diff --git a/src/open_source_python_template/__init__.py b/src/open_source_python_template/__init__.py index f2c2628..5fc59b3 100644 --- a/src/open_source_python_template/__init__.py +++ b/src/open_source_python_template/__init__.py @@ -1,7 +1,11 @@ from flask import Flask, render_template +import crawlTasks app = Flask(__name__) +tasks = crawlTasks.get_tasks() +print(tasks) + @app.route("/") def index(): diff --git a/src/open_source_python_template/crawlTasks.py b/src/open_source_python_template/crawlTasks.py index 47570c0..30bbb6a 100644 --- a/src/open_source_python_template/crawlTasks.py +++ b/src/open_source_python_template/crawlTasks.py @@ -1,4 +1,3 @@ -from flask import Flask, jsonify import os.path from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials @@ -6,15 +5,12 @@ from googleapiclient.discovery import build from googleapiclient.errors import HttpError -app = Flask(__name__) - # If modifying these scopes, delete the file token.json. SCOPES = ["https://www.googleapis.com/auth/tasks.readonly"] -@app.route("/get-tasks", methods=["GET"]) def get_tasks(): - """Endpoint to get tasks from Google Tasks API and return them as JSON.""" + """Function to get tasks from Google Tasks API and return them as JSON.""" creds = None if os.path.exists("token.json"): creds = Credentials.from_authorized_user_file("token.json", SCOPES) @@ -35,24 +31,22 @@ def get_tasks(): tasklists = results.get("items", []) tasks_response = [] - if tasklists: - for tasklist in tasklists: - tasks = service.tasks().list(tasklist=tasklist["id"]).execute() - tasks_items = tasks.get("items", []) - for task in tasks_items: - tasks_response.append( - { - "title": task["title"], - "id": task["id"], - "tasklist_id": tasklist["id"], - "tasklist_title": tasklist["title"], - } - ) - - return jsonify(tasks_response) + if not tasklists: + print("No task lists found.") + return [] + for tasklist in tasklists: + tasks = service.tasks().list(tasklist=tasklist["id"]).execute() + tasks_items = tasks.get("items", []) + for task in tasks_items: + tasks_response.append( + { + "title": task["title"], + "id": task["id"], + "tasklist_id": tasklist["id"], + "tasklist_title": tasklist["title"], + } + ) + return tasks_response except HttpError as err: - return jsonify({"error": str(err)}), 500 - - -if __name__ == "__main__": - app.run(debug=True) + print({"error": str(err)}) + return [] diff --git a/src/open_source_python_template/static/javascripts/script.js b/src/open_source_python_template/static/javascripts/script.js index fc44ee3..75154ba 100644 --- a/src/open_source_python_template/static/javascripts/script.js +++ b/src/open_source_python_template/static/javascripts/script.js @@ -19,4 +19,4 @@ function search_task(id) { tasklists[i].style.display = "none"; } } -} +}ƒ diff --git a/src/open_source_python_template/token.json b/src/open_source_python_template/token.json deleted file mode 100644 index 9c721c5..0000000 --- a/src/open_source_python_template/token.json +++ /dev/null @@ -1 +0,0 @@ -{"token": "ya29.a0Ad52N3-ilDDNGtqK-PO6048p7T3KRiIH0Wc0a2gQyxjsp71wz6D27322tztDCMKLFi7eHl0MqrGyFHp7M06ugT46IZa7H9A_sR7KnVXYMrExx2_y5iUoptPZAS9rnK6N-vHKWrNupAF5MXkxCzcFMV2vU4Zg5FHZmboZaCgYKAQkSARASFQHGX2Mi91xNBjOvaqe3alyyctt2Eg0171", "refresh_token": "1//05TV7z8fFf5_aCgYIARAAGAUSNwF-L9IrEjgglPop6tZgyYAL-8Ph7gnb0Xgc-colt0kOA4Iaf_DSmUQmZ8YB0-nnBErSD9a5Qxw", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "1040401338975-of64s6p0qrs9d7mjokogl1u20g31e703.apps.googleusercontent.com", "client_secret": "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", "scopes": ["https://www.googleapis.com/auth/tasks.readonly"], "universe_domain": "googleapis.com", "account": "", "expiry": "2024-04-29T21:51:24.306748Z"} \ No newline at end of file