Browse Source

awork Aufgabe erstellen mit Status "Läuft"

gc-server3 5 months ago
parent
commit
f4898a5b9a
2 changed files with 15 additions and 7 deletions
  1. 2 1
      .gitignore
  2. 13 6
      awork/awork_tasks.py

+ 2 - 1
.gitignore

@@ -18,4 +18,5 @@ fehlerbericht/config.py
 mailserver/temp/
 *.zip
 datev/export
-sandbox/sql
+sandbox/sql
+awork/projects.json

+ 13 - 6
awork/awork_tasks.py

@@ -1,13 +1,16 @@
-from credentials import Client
-import typer
-import requests
-import json
 import datetime
+import json
 from pathlib import Path
+
+import requests
+import typer
+from credentials import Client
 from model import AworkProjekt, Comment, User
 from sqlalchemy import create_engine, text
 from sqlalchemy.orm import Session
 
+app = typer.Typer()
+
 DSN = "mysql+pymysql://gaps:Gcbs12ma@192.168.2.41/tasks"
 
 awork_api_url = "https://api.awork.com/api/v1"
@@ -42,6 +45,7 @@ def get_users():
     return data
 
 
+@app.command()
 def import_projects():
     projects = get_projects()
     p = convert_projects(projects)
@@ -85,6 +89,7 @@ def convert_projects(projects):
     return res
 
 
+@app.command()
 def create_task(comment_id: int):
     with Session(create_engine(DSN)) as db_session:
         comment = db_session.get(Comment, comment_id)
@@ -97,7 +102,7 @@ def create_task(comment_id: int):
 
         res = requests.get(awork_api_url + "/projects/" + comment.awork_project_id + "/taskstatuses", headers=header)
         data = res.json()
-        task_status = [s["id"] for s in data if s["name"] == "To do"]
+        task_status = [s["id"] for s in data if s["type"] == "progress"]
         if len(task_status) == 0:
             return 0
         task_status_id = task_status[0]
@@ -242,4 +247,6 @@ def authorize():
 
 if __name__ == "__main__":
     main()
-    typer.run(create_task)
+    app()
+    # create_task(74715)
+    # import_projects()