api_export_taiga.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import requests
  2. import urllib3
  3. import os
  4. import json
  5. from dotenv import load_dotenv
  6. repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  7. load_dotenv(dotenv_path=os.path.join(repo_root, ".env"))
  8. urllib3.disable_warnings()
  9. TAIGA_USER = os.environ.get('TAIGA_USER', 'FrancoisLange')
  10. TAIGA_PASS = os.environ.get('TAIGA_PASS', 'your_db_password_here')
  11. base_url = os.environ.get('TAIGA_URL', 'https://192.168.130.161/taiga').rstrip('/') + '/api/v1'
  12. def main():
  13. print("Logging into Taiga...")
  14. auth_resp = requests.post(f'{base_url}/auth', json={'type': 'normal', 'username': TAIGA_USER, 'password': TAIGA_PASS}, verify=False)
  15. if auth_resp.status_code != 200:
  16. print("Auth failed!")
  17. return
  18. auth = auth_resp.json()
  19. headers = {
  20. 'Authorization': f'Bearer {auth["auth_token"]}',
  21. 'Content-Type': 'application/json',
  22. 'x-disable-pagination': 'true'
  23. }
  24. project_id = 21
  25. print("Fetching project details...")
  26. project = requests.get(f'{base_url}/projects/{project_id}', headers=headers, verify=False).json()
  27. print("Fetching sprints (milestones)...")
  28. sprints = requests.get(f'{base_url}/milestones?project={project_id}', headers=headers, verify=False).json()
  29. print("Fetching user stories...")
  30. user_stories = requests.get(f'{base_url}/userstories?project={project_id}', headers=headers, verify=False).json()
  31. print("Fetching tasks...")
  32. tasks = requests.get(f'{base_url}/tasks?project={project_id}', headers=headers, verify=False).json()
  33. print("Fetching wiki pages...")
  34. wikis = requests.get(f'{base_url}/wiki?project={project_id}', headers=headers, verify=False).json()
  35. print("Fetching issues...")
  36. issues = requests.get(f'{base_url}/issues?project={project_id}', headers=headers, verify=False).json()
  37. export_data = {
  38. "project": project,
  39. "sprints": sprints,
  40. "user_stories": user_stories,
  41. "tasks": tasks,
  42. "wiki_pages": wikis,
  43. "issues": issues
  44. }
  45. out_path = r'c:\Users\lanfr144\Documents\DOPRO1\Antigravity\taiga_export.json'
  46. with open(out_path, 'w', encoding='utf-8') as f:
  47. json.dump(export_data, f, indent=2, ensure_ascii=False)
  48. print(f"API Taiga Export saved successfully to {out_path}!")
  49. if __name__ == '__main__':
  50. main()