1
0

taiga_wiki_bookmarks.py 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. import requests, urllib3
  2. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  3. base_url = 'https://192.168.130.161/taiga/api/v1'
  4. auth_url = f'{base_url}/auth'
  5. auth = requests.post(auth_url, json={'type': 'normal', 'username': 'FrancoisLange', 'password': 'BTSai123'}, verify=False).json()
  6. headers = {'Authorization': f'Bearer {auth["auth_token"]}', 'Content-Type': 'application/json'}
  7. proj_id = 21
  8. bookmarks = [
  9. {"title": "26.04.30 PLAN (Sprint Planning)", "href": "26-04-30-plan"},
  10. {"title": "26.04.30 DAILY (Daily Scrum)", "href": "26-04-30-daily"},
  11. {"title": "26.04.30 REVIEW (Sprint Review)", "href": "26-04-30-review"},
  12. {"title": "26.04.30 RETROSPECTIVE (Sprint Retrospective)", "href": "26-04-30-retrospective"},
  13. {"title": "26.04.30 ARTIFACT (Artifacts Used)", "href": "26-04-30-artifact"}
  14. ]
  15. # Get current links to calculate order
  16. existing = requests.get(f'{base_url}/wiki-links?project={proj_id}', headers=headers, verify=False).json()
  17. max_order = max([e['order'] for e in existing]) if existing else 0
  18. for i, b in enumerate(bookmarks):
  19. payload = {
  20. "project": proj_id,
  21. "title": b["title"],
  22. "href": b["href"],
  23. "order": max_order + i + 1
  24. }
  25. r = requests.post(f'{base_url}/wiki-links', json=payload, headers=headers, verify=False)
  26. print(f'Created Bookmark {b["title"]}: {r.status_code}')
  27. if r.status_code != 201:
  28. print(r.text)