From a7a7ee3ee3e35db68cc714b3618d6d38fe6e863c Mon Sep 17 00:00:00 2001 From: Shailaja kumari Date: Mon, 12 Feb 2024 23:26:23 +0530 Subject: [PATCH] added login.html,home.html ,removed outer dockerfile,requirement.txt,main.txt --- app/Dockerfile | 11 +++ app/dummy.env | 8 ++ {templates => app/templates}/home.html | 0 {templates => app/templates}/login.html | 0 database/Dockerfile | 11 +++ Dockerfile => job/Dockerfile | 2 - job/dummy.env | 3 + main.py | 123 ------------------------ requirements.txt | 1 - templates/login.jinja2 | 9 -- templates/logout.jinja2 | 9 -- templates/mainscreen.jinja2 | 21 ---- templates/processoauth2.jinja2 | 15 --- templates/setapikey.jinja2 | 9 -- 14 files changed, 33 insertions(+), 189 deletions(-) create mode 100644 app/Dockerfile create mode 100644 app/dummy.env rename {templates => app/templates}/home.html (100%) rename {templates => app/templates}/login.html (100%) create mode 100644 database/Dockerfile rename Dockerfile => job/Dockerfile (92%) create mode 100644 job/dummy.env delete mode 100644 main.py delete mode 100644 requirements.txt delete mode 100644 templates/login.jinja2 delete mode 100644 templates/logout.jinja2 delete mode 100644 templates/mainscreen.jinja2 delete mode 100644 templates/processoauth2.jinja2 delete mode 100644 templates/setapikey.jinja2 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 @@ - - -Logging in - - - -Redirecting ... - - diff --git a/templates/logout.jinja2 b/templates/logout.jinja2 deleted file mode 100644 index 247bbd3..0000000 --- a/templates/logout.jinja2 +++ /dev/null @@ -1,9 +0,0 @@ - - -Logout - - - -Redirecting ... - - diff --git a/templates/mainscreen.jinja2 b/templates/mainscreen.jinja2 deleted file mode 100644 index fc0e9a8..0000000 --- a/templates/mainscreen.jinja2 +++ /dev/null @@ -1,21 +0,0 @@ - - -Inoreader 2 Readwise main screen -</head> -<body> -Hello {% inoreader_username %} -<p/> -<form action="setapikey"> -API key: -<input type="text" id="apikey">{% readwise_apikey %}</input> -<submit>Change</submit> -</form> -<br/> -Last time sync: {%lastsync%} {%syncstatus%}} -<br/> -Next time sync: {%nextsync%} -<form action="logout"> -<submit>Logout</submit> -</form> -</body> -</html> diff --git a/templates/processoauth2.jinja2 b/templates/processoauth2.jinja2 deleted file mode 100644 index e5e36ee..0000000 --- a/templates/processoauth2.jinja2 +++ /dev/null @@ -1,15 +0,0 @@ -<html> -<head> -<title>Processing oauth2 -{%if login_success%} - -{%endif%} - - -{%if login_success%} -Redirecting ... -{%else%} -Login failed. -{%endif%} - - diff --git a/templates/setapikey.jinja2 b/templates/setapikey.jinja2 deleted file mode 100644 index 18d21f1..0000000 --- a/templates/setapikey.jinja2 +++ /dev/null @@ -1,9 +0,0 @@ - - -Changing API key - - - -Redirecting ... - -