Skip to content

Commit

Permalink
Bug fix for forgeting to save existing hash value and note guid when …
Browse files Browse the repository at this point in the history
…update/save gist into database
  • Loading branch information
leemengtw committed Feb 15, 2018
1 parent b83f8d3 commit f7158e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
12 changes: 6 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ def sync_gist(gist, driver):

# check existing gist hash before fetch if available
prev_hash = db.get_hash_by_id(gist['id'])
if prev_hash:
note_guid = db.get_note_guid_by_id(gist['id'])
if prev_hash and note_guid:
note_exist = True
cur_hash = get_gist_hash(github_user, gist['name'])
if prev_hash == cur_hash:
print('Gist {} remain the same, ignore.'.format(gist_url))
db.update_gist(gist)
db.update_gist(gist, note_guid, cur_hash)
return None


Expand All @@ -137,18 +138,17 @@ def sync_gist(gist, driver):
note_body = format_note_body(gist)

# get hash of raw gist content and save gist info to database
gist['hash'] = get_gist_hash(github_user, gist['name'])
gist_hash = get_gist_hash(github_user, gist['name'])

# create new note / update existing note
if not note_exist:
note = create_note(note_title, note_body, [resource], parent_notebook=notebook)
gist['note_guid'] = note.guid
db.save_gist(gist)
db.save_gist(gist, note_guid, gist_hash)
else:
note_guid = db.get_note_guid_by_id(gist['id'])
note = get_note(note_guid)
update_note(note, note_title, note_body, note_guid, [resource])
db.update_gist(gist)
db.update_gist(gist, note_guid, gist_hash)

os.remove(image_path)
print("Finish creating note for gist {}".format(gist_url))
Expand Down
20 changes: 14 additions & 6 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_note_guid_by_id(self, gist_id):
return self.info.get(gist_id, {}).get('note_guid', '')


def save_gist(self, gist):
def save_gist(self, gist, note_guid, hash):
"""Save information of a given gist into database.
Parameters
Expand All @@ -107,16 +107,19 @@ def save_gist(self, gist):
'name': 'gist_name',
'description': 'description',
'pushAt': '2018-01-15T00:48:23Z',
'hash': 'hash value'
}
note_guid : str
hash : str
"""
gist['note_guid'] = note_guid
gist['hash'] = hash

self.info[gist['id']] = gist
self.info['num_gists'] = self.info.get('num_gists', 0) + 1
self.sync_info('save')
self.update_sync_time()

def update_gist(self, gist):
def update_gist(self, gist, note_guid, hash):
"""Update information of a given gist into database.
Parameters
Expand All @@ -127,11 +130,16 @@ def update_gist(self, gist):
'id': 'gist_id',
'name': 'gist_name',
'description': 'description',
'pushAt': '2018-01-15T00:48:23Z',
'hash': 'hash value'
'pushAt': '2018-01-15T00:48:23Z'
}
note_guid : str
hash : str
"""

gist['note_guid'] = note_guid
gist['hash'] = hash

self.info[gist['id']] = gist
self.sync_info('save')
self.update_sync_time()
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ pyperclip==1.6.0
pyportmidi==0.0.7
PySocks==1.6.7
python-dateutil==2.6.0
pytz==2018.3
requests==2.18.4
selenium==3.8.1
six==1.11.0
subprocess32==3.2.7
TBB==0.1
tzlocal==1.5.1
urllib3==1.22

0 comments on commit f7158e2

Please sign in to comment.