Skip to content

Commit

Permalink
add error handler when user is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
umihico committed Mar 10, 2019
1 parent e35958c commit ceca751
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions attach-geotag/attach_geotag.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,41 @@
from microdb import MicroDB
from calc_geotag import calc_geotag

class DeletedUserException(Exception):
pass

def username_to_location(username="umihico"):
url = f'https://api.github.com/users/{username}'
response = retryable_authorized_http_requests(url)
return response.json()['location']
json=response.json()
if 'location' in json:
return response.json()['location']
elif 'message' in json and json['message']=="Not Found":
raise DeletedUserException()
else:
raise Exception(f'unknown response:{str(json)}')



def test_username_to_location():
print(username_to_location())


def update(username, mdb_geotag):
location = username_to_location(username)
geotag_json = {
"username": username,
'last_modified': time.time(),
'raw': location,
'geotags': calc_geotag(location)
}
print(username, location, calc_geotag(location))
mdb_geotag.upsert(geotag_json)
mdb_geotag.save()
try:
location = username_to_location(username)
except DeletedUserException as e:
return
else:
geotag_json = {
"username": username,
'last_modified': time.time(),
'raw': location,
'geotags': calc_geotag(location)
}
print(username, location, calc_geotag(location))
mdb_geotag.upsert(geotag_json)
mdb_geotag.save()


def sort_by_priotity(mdb_repos, mdb_geotag):
Expand Down

0 comments on commit ceca751

Please sign in to comment.