From 644539a23601a2bfb16ca1984b5f6b6e40c0b01c Mon Sep 17 00:00:00 2001 From: Swapnil Date: Wed, 17 Jan 2024 15:44:23 +0530 Subject: [PATCH] Added code skeleton --- main.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 61 insertions(+) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/main.py b/main.py new file mode 100644 index 0000000..56a3f73 --- /dev/null +++ b/main.py @@ -0,0 +1,60 @@ +import os +import time +import json +import requests + +# Define the path to the persistent data store +DATA_STORE_PATH = "/data/last_update_time.txt" + +def get_last_update_time(): + with open(DATA_STORE_PATH, 'r') as file: + return file.read().strip() + +def update_last_update_time(new_time): + with open(DATA_STORE_PATH, 'w') as file: + file.write(new_time) + +def get_annotations(last_update_time, inoreader_username, inoreader_password): + # Replace with actual API call + # This is a placeholder implementation + response = requests.get( + "https://www.inoreader.com/reader/api/0", + params={"since": last_update_time}, + auth=(inoreader_username, inoreader_password), + ) + return response.json() + +def push_to_readwise(annotations, readwise_username, readwise_password): + # Replace with actual API call + # This is a placeholder implementation + response = requests.post( + "https://readwise.io/api/annotations", + data=json.dumps(annotations), + auth=(readwise_username, readwise_password), + ) + return response.status_code + +def main(): + # Get credentials from environment variables + inoreader_username = os.getenv("INOREADER_USERNAME") + inoreader_password = os.getenv("INOREADER_PASSWORD") + readwise_username = os.getenv("READWISE_USERNAME") + readwise_password = os.getenv("READWISE_PASSWORD") + + while True: + last_update_time = get_last_update_time() + + # Get annotations after the last update time + annotations = get_annotations(last_update_time, inoreader_username, inoreader_password) + + # Push annotations to Readwise + push_to_readwise(annotations, readwise_username, readwise_password) + + # Update the last update time + update_last_update_time(time.ctime()) + + # Wait for an hour + time.sleep(3600) + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..077c95d --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests==2.31.0 \ No newline at end of file