api_export_taiga.py 2.1 KB

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