1
0

taiga_wiki_push.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import requests
  2. import urllib3
  3. import os
  4. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  5. base_url = 'https://192.168.130.161/taiga/api/v1'
  6. auth_url = f'{base_url}/auth'
  7. auth = requests.post(auth_url, json={'type': 'normal', 'username': 'FrancoisLange', 'password': 'BTSai123'}, verify=False).json()
  8. headers = {'Authorization': f'Bearer {auth["auth_token"]}', 'Content-Type': 'application/json'}
  9. proj_id = 21
  10. def push_wiki(slug, md_path):
  11. with open(md_path, 'r') as f:
  12. content = f.read()
  13. res = requests.get(f'{base_url}/wiki?project={proj_id}&slug={slug}', headers=headers, verify=False).json()
  14. if len(res) > 0:
  15. wiki_id = res[0]['id']
  16. version = res[0]['version']
  17. payload = {'content': content, 'version': version}
  18. r = requests.put(f'{base_url}/wiki/{wiki_id}', json=payload, headers=headers, verify=False)
  19. print(f'Updated {slug}: {r.status_code}')
  20. else:
  21. payload = {'project': proj_id, 'slug': slug, 'content': content}
  22. r = requests.post(f'{base_url}/wiki', json=payload, headers=headers, verify=False)
  23. print(f'Created {slug}: {r.status_code}')
  24. if r.status_code != 201:
  25. print(r.text)
  26. # In Taiga, the home page of the wiki is usually 'home'
  27. push_wiki('26-04-30-plan', 'docs/Scrum_Plan.md')
  28. push_wiki('26-04-30-daily', 'docs/Scrum_Daily.md')
  29. push_wiki('26-04-30-review', 'docs/Scrum_Review.md')
  30. push_wiki('26-04-30-retrospective', 'docs/Scrum_Retro.md')
  31. push_wiki('26-04-30-artifact', 'docs/Scrum_Artifacts.md')