export_taiga.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import requests
  2. import urllib3
  3. import os
  4. import json
  5. import time
  6. urllib3.disable_warnings()
  7. TAIGA_USER = os.environ.get('TAIGA_USER', 'FrancoisLange')
  8. TAIGA_PASS = os.environ.get('TAIGA_PASS', 'your_db_password_here')
  9. base_url = 'https://192.168.130.161/taiga/api/v1'
  10. def main():
  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. }
  20. project_id = 21
  21. # In Taiga, request a dump
  22. print("Requesting Taiga project export...")
  23. resp = requests.post(f'{base_url}/exporter/{project_id}/dump', headers=headers, verify=False)
  24. if resp.status_code == 202:
  25. print("Export is being processed...")
  26. # Poll for the export dump file
  27. for _ in range(30):
  28. time.sleep(2)
  29. export_status = requests.get(f'{base_url}/exporter/{project_id}', headers=headers, verify=False).json()
  30. if 'export_file' in export_status and export_status['export_file']:
  31. file_url = export_status['export_file']
  32. print(f"Export file is ready: {file_url}")
  33. # Download it
  34. file_resp = requests.get(file_url, headers=headers, verify=False)
  35. with open(r'c:\Users\lanfr144\Documents\DOPRO1\Antigravity\taiga_export.json', 'wb') as f:
  36. f.write(file_resp.content)
  37. print("Export successfully saved to Antigravity/taiga_export.json")
  38. return
  39. else:
  40. print(f"Direct export request failed: {resp.status_code} - {resp.text}")
  41. # Let's try to query the export configuration to see if there is already an existing dump
  42. export_status = requests.get(f'{base_url}/exporter/{project_id}', headers=headers, verify=False).json()
  43. print("Existing export details:", export_status)
  44. if 'export_file' in export_status and export_status['export_file']:
  45. file_url = export_status['export_file']
  46. print(f"Downloading existing export: {file_url}")
  47. file_resp = requests.get(file_url, headers=headers, verify=False)
  48. with open(r'c:\Users\lanfr144\Documents\DOPRO1\Antigravity\taiga_export.json', 'wb') as f:
  49. f.write(file_resp.content)
  50. print("Export successfully saved to Antigravity/taiga_export.json")
  51. return
  52. if __name__ == '__main__':
  53. main()