create_taiga_wiki.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import requests
  2. import urllib3
  3. urllib3.disable_warnings()
  4. base_url = 'https://192.168.130.161/taiga/api/v1'
  5. auth = requests.post(f'{base_url}/auth', json={'type': 'normal', 'username': 'FrancoisLange', 'password': 'your_db_password_here'}, verify=False).json()
  6. if 'auth_token' not in auth:
  7. print("Authentication failed:", auth)
  8. exit(1)
  9. h = {'Authorization': f'Bearer {auth["auth_token"]}', 'Content-Type': 'application/json'}
  10. project_id = 21
  11. pages = [
  12. {"slug": "26-05-15-retrospective", "content": "# 26.05.15 RETROSPECTIVE\n\nReview for the two last weeks."},
  13. {"slug": "26-05-15-plan", "content": "# 26.05.15 PLAN\n\nCreate a plan for this week."},
  14. {"slug": "26-05-15-review", "content": "# 26.05.15 REVIEW\n\nCreate a review the two last weeks."},
  15. {"slug": "26-05-15-daily", "content": "# 26.05.15 DAILY\n\nDaily for today."}
  16. ]
  17. for page in pages:
  18. payload = {
  19. "project": project_id,
  20. "slug": page["slug"],
  21. "content": page["content"]
  22. }
  23. r = requests.post(f'{base_url}/wiki', json=payload, headers=h, verify=False)
  24. if r.status_code == 201:
  25. print(f"Created: {page['slug']}")
  26. elif r.status_code == 400 and "already exists" in r.text.lower():
  27. print(f"Already exists: {page['slug']}")
  28. else:
  29. print(f"Failed to create {page['slug']}: {r.status_code} {r.text}")
  30. # We also need to add them to the wiki links (bookmarks in Taiga)
  31. # The user said: "create the bookmarks in wiki for today with the following entries"
  32. # Bookmarks are usually created via POST /api/v1/wiki-links
  33. links = [
  34. {"title": "26.05.15 RETROSPECTIVE", "href": "26-05-15-retrospective"},
  35. {"title": "26.05.15 PLAN", "href": "26-05-15-plan"},
  36. {"title": "26.05.15 REVIEW", "href": "26-05-15-review"},
  37. {"title": "26.05.15 DAILY", "href": "26-05-15-daily"}
  38. ]
  39. for link in links:
  40. payload = {
  41. "project": project_id,
  42. "title": link["title"],
  43. "href": link["href"]
  44. }
  45. r = requests.post(f'{base_url}/wiki-links', json=payload, headers=h, verify=False)
  46. if r.status_code == 201:
  47. print(f"Created link: {link['title']}")
  48. else:
  49. print(f"Failed to create link {link['title']}: {r.status_code} {r.text}")