Skip to content

Commit

Permalink
Merge branch 'main' into yanglin
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanglin-Tao committed May 12, 2024
2 parents 2947fa4 + 8cae1bd commit 8467b5c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 36 deletions.
4 changes: 4 additions & 0 deletions src/open_source_python_template/__init__.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
44 changes: 19 additions & 25 deletions src/open_source_python_template/crawlTasks.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
from flask import Flask, jsonify
import os.path
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
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)
Expand All @@ -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 []
8 changes: 0 additions & 8 deletions src/open_source_python_template/db/db.readme

This file was deleted.

15 changes: 15 additions & 0 deletions src/open_source_python_template/db/readme.md
Original file line number Diff line number Diff line change
@@ -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([email protected]) for database password

Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ function search_task(id) {
tasklists[i].style.display = "none";
}
}
}
}ƒ
2 changes: 1 addition & 1 deletion src/open_source_python_template/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ <h2>Starred</h2>
</div>
</div>

<script src="../javascripts/script.js" defer></script>
<script src="../static/javascripts/script.js" defer></script>
</body>
</html>
1 change: 0 additions & 1 deletion src/open_source_python_template/token.json

This file was deleted.

0 comments on commit 8467b5c

Please sign in to comment.