Use default flag for shelving

Avoids an issue when running the script for the first time where Shelve would freak out and die because the shelf doesn't exist.
This commit is contained in:
Thomas Wade 2018-09-27 00:15:29 +09:30
parent 161d24e238
commit 86d7958489

View File

@ -267,7 +267,7 @@ def Get_Follows(url, limit = 100):
user_dict = {} user_dict = {}
track_dict = {} track_dict = {}
with shelve.open('shelf.db', 'r') as shelf: with shelve.open('shelf.db') as shelf:
if 'user_dict' in shelf.keys(): if 'user_dict' in shelf.keys():
user_dict = shelf['user_dict'] user_dict = shelf['user_dict']
if 'track_dict' in shelf.keys(): if 'track_dict' in shelf.keys():
@ -327,7 +327,7 @@ for i in range(MAX_DEGREE + 1):
user_dict[user.url_username] = user user_dict[user.url_username] = user
# Update the shelf with the new dictionaries # Update the shelf with the new dictionaries
with shelve.open('shelf.db', 'c') as shelf: with shelve.open('shelf.db') as shelf:
shelf['user_dict'] = user_dict shelf['user_dict'] = user_dict
shelf['track_dict'] = track_dict shelf['track_dict'] = track_dict