From a950eae69f4a9ddca3bee30b05ea3ed1c3d4a8ea Mon Sep 17 00:00:00 2001 From: Christopher Aedo Date: Wed, 29 Mar 2023 14:18:29 -0700 Subject: [PATCH] Initial commit --- .gitignore | 1 + recover-notes.py | 25 +++++++++++++++++++++++++ requirements.txt | 2 ++ 3 files changed, 28 insertions(+) create mode 100644 .gitignore create mode 100644 recover-notes.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1269488 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data diff --git a/recover-notes.py b/recover-notes.py new file mode 100644 index 0000000..2a1178a --- /dev/null +++ b/recover-notes.py @@ -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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fe67cbc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +bs4 +sqlite3