Initial commit
This commit is contained in:
commit
a950eae69f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
data
|
||||||
25
recover-notes.py
Normal file
25
recover-notes.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
# open connection to database
|
||||||
|
conn = sqlite3.connect('notes-backup.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# execute query to fetch note data
|
||||||
|
cursor.execute('SELECT title, body FROM notes')
|
||||||
|
|
||||||
|
# save each note as a file
|
||||||
|
for title, body in cursor:
|
||||||
|
# Remove any special characters that could cause problems in a Unix filename
|
||||||
|
safe_title = re.sub(r'[^\w_.)( -]', '', title)
|
||||||
|
filename = 'data/{}.txt'.format(safe_title)
|
||||||
|
with open(filename, 'w') as f:
|
||||||
|
Text = BeautifulSoup(body, 'html.parser').get_text()
|
||||||
|
PlainText = Text.encode('mac-roman').decode("utf-8")
|
||||||
|
f.write(PlainText)
|
||||||
|
|
||||||
|
# close the database connection
|
||||||
|
conn.close()
|
||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
bs4
|
||||||
|
sqlite3
|
||||||
Loading…
x
Reference in New Issue
Block a user