Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kaining back #15

Merged
merged 3 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 []
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";
}
}
}
}ƒ
zwinniez marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion src/open_source_python_template/token.json

This file was deleted.

Loading