[30388f42] Keine neuen Commits in dieser Session.
Keine neuen Commits in dieser Session.
This commit is contained in:
29
check_notion_task.py
Normal file
29
check_notion_task.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
import requests
|
||||
import json
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
token = os.environ.get('NOTION_API_KEY')
|
||||
db_name = "Tasks [UT]"
|
||||
|
||||
def find_database_id(token, title):
|
||||
url = "https://api.notion.com/v1/search"
|
||||
headers = {"Authorization": f"Bearer {token}", "Notion-Version": "2022-06-28"}
|
||||
payload = {"query": title, "filter": {"value": "database", "property": "object"}}
|
||||
res = requests.post(url, headers=headers, json=payload)
|
||||
for db in res.json().get("results", []):
|
||||
if db["title"][0]["plain_text"] == title:
|
||||
return db["id"]
|
||||
return None
|
||||
|
||||
db_id = find_database_id(token, db_name)
|
||||
if db_id:
|
||||
url = f"https://api.notion.com/v1/databases/{db_id}/query"
|
||||
headers = {"Authorization": f"Bearer {token}", "Notion-Version": "2022-06-28"}
|
||||
res = requests.post(url, headers=headers)
|
||||
tasks = res.json().get("results", [])
|
||||
for task in tasks:
|
||||
tid = task["id"]
|
||||
title = task["properties"]["Name"]["title"][0]["plain_text"]
|
||||
print(f"Task: {title} | ID: {tid}")
|
||||
Reference in New Issue
Block a user