From af4b6d6076edb208742680c3a732c19de94d2445 Mon Sep 17 00:00:00 2001 From: Fan Yang <993169208@qq.com> Date: Sat, 11 May 2024 21:20:51 -0400 Subject: [PATCH 1/4] update the readme in database folder --- src/open_source_python_template/db/db.readme | 8 -------- src/open_source_python_template/db/readme.md | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) delete mode 100644 src/open_source_python_template/db/db.readme create mode 100644 src/open_source_python_template/db/readme.md diff --git a/src/open_source_python_template/db/db.readme b/src/open_source_python_template/db/db.readme deleted file mode 100644 index 15e27fb..0000000 --- a/src/open_source_python_template/db/db.readme +++ /dev/null @@ -1,8 +0,0 @@ -# Connect to AWS RDS through SSH - -```bash -psql -h opensource-db.chwy4eqkclzc.us-east-1.rds.amazonaws.com -p 5432 -U postgres -d task-db -``` - -Please connect Fan(fy2187@nyu.edu) for database password - diff --git a/src/open_source_python_template/db/readme.md b/src/open_source_python_template/db/readme.md new file mode 100644 index 0000000..214a549 --- /dev/null +++ b/src/open_source_python_template/db/readme.md @@ -0,0 +1,15 @@ +# Connect to AWS RDS through SSH + +run the command with postgresql database installed + +```bash +psql -h opensource-db.chwy4eqkclzc.us-east-1.rds.amazonaws.com -p 5432 -U postgres -d task-db +``` + +## set up db + +run create_databse.sql to create the table in the database + + +Please connect Fan(fy2187@nyu.edu) for database password + From 4af9514125e1932f02089dd6802368c818fe95e6 Mon Sep 17 00:00:00 2001 From: zwinniez Date: Sat, 11 May 2024 22:17:27 -0400 Subject: [PATCH 2/4] fix: javascript functions import bug --- .../{ => static}/javascripts/script.js | 0 src/open_source_python_template/templates/index.html | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/open_source_python_template/{ => static}/javascripts/script.js (100%) diff --git a/src/open_source_python_template/javascripts/script.js b/src/open_source_python_template/static/javascripts/script.js similarity index 100% rename from src/open_source_python_template/javascripts/script.js rename to src/open_source_python_template/static/javascripts/script.js diff --git a/src/open_source_python_template/templates/index.html b/src/open_source_python_template/templates/index.html index 7ca41fe..1ab9272 100644 --- a/src/open_source_python_template/templates/index.html +++ b/src/open_source_python_template/templates/index.html @@ -62,6 +62,6 @@

Starred

- + \ No newline at end of file From 1b7f1f43ca50407913f7002f5afa43dcd7bffb59 Mon Sep 17 00:00:00 2001 From: Kaining Mao Date: Sat, 11 May 2024 22:48:58 -0400 Subject: [PATCH 3/4] Update crawlTasks.py The task information is returned --- src/open_source_python_template/__init__.py | 6 ++- src/open_source_python_template/crawlTasks.py | 45 ++++++++----------- .../javascripts/script.js | 2 +- src/open_source_python_template/token.json | 1 - 4 files changed, 24 insertions(+), 30 deletions(-) delete mode 100644 src/open_source_python_template/token.json diff --git a/src/open_source_python_template/__init__.py b/src/open_source_python_template/__init__.py index f2c2628..c5fc53b 100644 --- a/src/open_source_python_template/__init__.py +++ b/src/open_source_python_template/__init__.py @@ -1,12 +1,14 @@ from flask import Flask, render_template +import crawlTasks app = Flask(__name__) +tasks = crawlTasks.get_tasks() +print(tasks) @app.route("/") def index(): return render_template("index.html") - - + if __name__ == "__main__": app.run(debug=True) diff --git a/src/open_source_python_template/crawlTasks.py b/src/open_source_python_template/crawlTasks.py index 47570c0..c2487de 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,11 @@ 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 +30,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/javascripts/script.js b/src/open_source_python_template/javascripts/script.js index fc44ee3..75154ba 100644 --- a/src/open_source_python_template/javascripts/script.js +++ b/src/open_source_python_template/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 From 7a4daf5ded3d62e322e7098df5a27867340b76db Mon Sep 17 00:00:00 2001 From: Kaining Mao Date: Sat, 11 May 2024 22:49:57 -0400 Subject: [PATCH 4/4] balck the code balck the code --- src/open_source_python_template/__init__.py | 4 +++- src/open_source_python_template/crawlTasks.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/open_source_python_template/__init__.py b/src/open_source_python_template/__init__.py index c5fc53b..5fc59b3 100644 --- a/src/open_source_python_template/__init__.py +++ b/src/open_source_python_template/__init__.py @@ -6,9 +6,11 @@ tasks = crawlTasks.get_tasks() print(tasks) + @app.route("/") def index(): return render_template("index.html") - + + if __name__ == "__main__": app.run(debug=True) diff --git a/src/open_source_python_template/crawlTasks.py b/src/open_source_python_template/crawlTasks.py index c2487de..30bbb6a 100644 --- a/src/open_source_python_template/crawlTasks.py +++ b/src/open_source_python_template/crawlTasks.py @@ -8,6 +8,7 @@ # If modifying these scopes, delete the file token.json. SCOPES = ["https://www.googleapis.com/auth/tasks.readonly"] + def get_tasks(): """Function to get tasks from Google Tasks API and return them as JSON.""" creds = None