Skip to content

Commit 9e1f6fe

Browse files
Merge pull request #4 from mpentler/master
Fixed #2 - error handling on the database file
2 parents 6ca48f4 + df0380e commit 9e1f6fe

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

pastebin-mirror/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def archive_scrape_pastes(last_archive_time, scraper, storage, rate):
4949
if not storage.has_paste_content('paste_content', x['key'])]
5050
print('[*] Fetching {} new pastes'.format(len(recent_pastes)), file=sys.stderr)
5151
for paste in recent_pastes:
52-
5352
key = paste['key']
5453
storage.save_paste_reference('paste', key, paste['date'], paste['size'],
5554
paste['expire'], paste['title'], paste['syntax'],
@@ -91,7 +90,7 @@ def main():
9190
storage.initialize_tables(args.trending)
9291
else:
9392
storage = FlatFileStorage(location=args.output)
94-
93+
9594
last_scrape = -args.rate
9695
last_trending = -60 * 60
9796

pastebin-mirror/storage.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,25 @@ def __init__(self, location='pastebin.db'):
5555
self.connection = sqlite3.connect(location)
5656

5757
def initialize_tables(self, trending=False):
58-
self.connection.execute(
59-
'''
60-
CREATE TABLE IF NOT EXISTS paste (
61-
paste_key CHAR(8) PRIMARY KEY,
62-
timestamp TIMESTAMP,
63-
size INT,
64-
expires TIMESTAMP,
65-
title TEXT,
66-
syntax TEXT,
67-
user TEXT NULL
68-
);
69-
'''
70-
)
58+
59+
try:
60+
self.connection.execute(
61+
'''
62+
CREATE TABLE IF NOT EXISTS paste (
63+
paste_key CHAR(8) PRIMARY KEY,
64+
timestamp TIMESTAMP,
65+
size INT,
66+
expires TIMESTAMP,
67+
title TEXT,
68+
syntax TEXT,
69+
user TEXT NULL
70+
);
71+
'''
72+
)
73+
except sqlite3.OperationalError as err:
74+
print("[!] Error accessing database file: {}".format(err))
75+
print("[!] Fatal Error: Exiting...")
76+
exit(1)
7177

7278
self.connection.execute(
7379
'''

0 commit comments

Comments
 (0)