1
0

export_taiga.py 2.8 KB

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