61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
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()
|