diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..5d1a81a --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.8-slim-buster + +WORKDIR /app + +ADD . /app + +RUN pip install --no-cache-dir -r requirements.txt + +EXPOSE 5000 + +CMD ["python", "main.py"] \ No newline at end of file diff --git a/app/dummy.env b/app/dummy.env new file mode 100644 index 0000000..333096c --- /dev/null +++ b/app/dummy.env @@ -0,0 +1,8 @@ +CLIENT_ID= +CLIENT_SECRET= +REDIRECT_URI= +OPTIONAL_SCOPES= +DATABASE_URL= + +# generated by `openssl rand -hex 24` - used to encrypt session +APP_SECRET_KEY= \ No newline at end of file diff --git a/templates/home.html b/app/templates/home.html similarity index 100% rename from templates/home.html rename to app/templates/home.html diff --git a/templates/login.html b/app/templates/login.html similarity index 100% rename from templates/login.html rename to app/templates/login.html diff --git a/database/Dockerfile b/database/Dockerfile new file mode 100644 index 0000000..5d1a81a --- /dev/null +++ b/database/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.8-slim-buster + +WORKDIR /app + +ADD . /app + +RUN pip install --no-cache-dir -r requirements.txt + +EXPOSE 5000 + +CMD ["python", "main.py"] \ No newline at end of file diff --git a/Dockerfile b/job/Dockerfile similarity index 92% rename from Dockerfile rename to job/Dockerfile index 2d677f5..efa4ad0 100644 --- a/Dockerfile +++ b/job/Dockerfile @@ -6,6 +6,4 @@ ADD . /app RUN pip install --no-cache-dir -r requirements.txt -EXPOSE 80 - CMD ["python", "main.py"] diff --git a/job/dummy.env b/job/dummy.env new file mode 100644 index 0000000..717a83c --- /dev/null +++ b/job/dummy.env @@ -0,0 +1,3 @@ +DATABASE_URL= +INOREADER_CLIENT_ID= +INOREADER_CLIENT_SECRET= \ No newline at end of file diff --git a/main.py b/main.py deleted file mode 100644 index 656f0cd..0000000 --- a/main.py +++ /dev/null @@ -1,123 +0,0 @@ -import os -import time -import json -import requests -import logging - -DATA_STORE_PATH = "/data/last_update_time.txt" - -logging.basicConfig(level=logging.INFO) - -class APIHandler: - def __init__(self, base_url, headers={}): - self.base_url = base_url - self.headers = headers - - def get(self, endpoint, params=None): - response = requests.get(self.base_url + endpoint, params=params, headers=self.headers) - response.raise_for_status() - return response.json() - - def post(self, endpoint, data=None): - response = requests.post(self.base_url + endpoint, data=json.dumps(data), headers=self.headers) - 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 update_last_update_time(new_time): - with open(DATA_STORE_PATH, 'w') as file: - file.write(str(new_time)) - -def get_new_annotations(last_annotation_time): - inoreader = APIHandler( - "https://www.inoreader.com/reader/api/0/stream/contents", - headers = { - 'Authorization': 'Bearer ' + os.getenv("INOREADER_ACCESS_TOKEN") - } - ) - - all_annotations = [] - continuation = None - - while True: - params = { - "annotations": 1, - "n": 100, - } - if continuation: - params["c"] = continuation - - inoreader_response = inoreader.get( - "/user/-/state/com.google/annotated", - params=params - ) - data = json.loads(inoreader_response) - - for item in data["items"]: - annotations = item.get("annotations", []) - for annotation in annotations: - annotation['title'] = item['title'] - annotation['author'] = item['author'] - annotation['sources'] = item['canonical'] - all_annotations.append(annotation) - - if 'continuation' in data: - continuation = data['continuation'] - time.sleep(900) # Sleep for 15 minutes between pages - else: - break - - return [annotation for annotation in all_annotations if annotation['added_on'] > last_annotation_time] - -def push_annotations_to_readwise(annotations): - readwise = APIHandler( - "https://readwise.io", - headers = { - 'Authorization': 'Token ' + os.getenv("READWISE_ACCESS_TOKEN"), - 'Content-Type': 'application/json' - } - ) - - readwise.post( - "/api/v2/highlights/", - data={ - 'highlights': [ - { - 'text': annotation['text'], - 'title': annotation['title'], - 'author': annotation['author'], - 'note': annotation['note'], - 'highlighted_at': annotation['added_on'], - 'category': 'articles', - 'source_url': annotation['sources'][0]['href'] if annotation['sources'] else None, - } - for annotation in annotations - ] - } - ) - -def main(): - - while True: - try: - last_annotation_time = get_last_update_time() - new_annotations = get_new_annotations(last_annotation_time) - - if new_annotations: - latest_added_on = max(annotation['added_on'] for annotation in new_annotations) - push_annotations_to_readwise(new_annotations) - update_last_update_time(latest_added_on) - else: - logging.info("No new annotations found") - - time.sleep(86400) # Sleep for 24 hours - - except Exception as e: - logging.error(f"An error occurred: {e}") - time.sleep(3600) # Sleep for 1 hour in case of error - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 077c95d..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -requests==2.31.0 \ No newline at end of file diff --git a/templates/login.jinja2 b/templates/login.jinja2 deleted file mode 100644 index 1c2a363..0000000 --- a/templates/login.jinja2 +++ /dev/null @@ -1,9 +0,0 @@ - -
-