Separate services - app, db, and job #1

Open
swapnil wants to merge 36 commits from swapnil/inoreader2readwise:main into main
Showing only changes of commit 889469dcff - Show all commits

View File

@ -25,13 +25,27 @@ class APIHandler:
response.raise_for_status()
return response.status_code
def get_last_update_time():
with open(DATA_STORE_PATH, 'r') as file:
return int(file.read().strip())
def get_last_update_time(email):
response = requests.get(f'{DATABASE_URL}/annotation_last_update/{email}')
response.raise_for_status()
def update_last_update_time(new_time):
with open(DATA_STORE_PATH, 'w') as file:
file.write(str(new_time))
if response.status_code == 204:
return 0
elif response.status_code == 200:
return response.json()['last_update_time']
def update_last_update_time(email, new_time):
response = requests.post(
f'{DATABASE_URL}/annotation_last_update',
headers={
'Content-Type': 'application/json'
},
json={
'email': email,
'last_update_time': new_time
}
)
response.raise_for_status()
def get_new_annotations(last_annotation_time, inoreader_token):
inoreader = APIHandler(
@ -207,13 +221,13 @@ def main():
inoreader_token, readwise_api_key = check_and_refresh_access_token(token)
last_annotation_time = get_last_update_time()
last_annotation_time = get_last_update_time(token['email'])
new_annotations = get_new_annotations(last_annotation_time, inoreader_token)
if new_annotations:
latest_added_on = max(annotation['added_on'] for annotation in new_annotations)
push_annotations_to_readwise(new_annotations, readwise_api_key)
update_last_update_time(latest_added_on)
update_last_update_time(token['email'], latest_added_on)
logging.info("Successfully pushed {} new annotations to Readwise for user with email: {}".format(len(new_annotations), token['email']))
else:
logging.info("No new annotations found for user with email: {}".format(token['email']))