notion_tasks.py 1.3 KB

1234567891011121314151617181920212223242526272829
  1. from notion_client import Client
  2. # --- CONFIG ---
  3. NOTION_TOKEN = "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"
  4. TODO_PREFIX = "To do du projet @"
  5. notion = Client(auth=NOTION_TOKEN)
  6. # --- Extraction des tâches ---
  7. def extract_tasks(database_id):
  8. tasks = []
  9. cursor = None
  10. while True:
  11. res = notion.databases.query(database_id=database_id, start_cursor=cursor)
  12. for row in res["results"]:
  13. props = row["properties"]
  14. name_data = props.get("Tache", {}).get("title", [])
  15. name = name_data[0]["plain_text"] if name_data else ""
  16. status = props.get("Status", {}).get("status", {})
  17. status_name = status.get("name", "") if status else ""
  18. date_field = props.get("Dead line", {}).get("date")
  19. deadline = date_field.get("start") if date_field else ""
  20. person = [p.get("name") for p in props.get("person", {}).get("people", [])]
  21. url = f"https://www.notion.so/{row['id'].replace('-', '')}"
  22. tasks.append((name, status_name, deadline, ", ".join(person), url))
  23. if not res.get("has_more"):
  24. break
  25. cursor = res["next_cursor"]
  26. return tasks