1
0

taiga_wiki_rename.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. # Fetch all existing links
  9. existing = requests.get(f'{base_url}/wiki-links?project={proj_id}', headers=headers, verify=False).json()
  10. # Delete the ones I made previously that had parentheses
  11. for link in existing:
  12. if "26.04.30" in link['title']:
  13. requests.delete(f'{base_url}/wiki-links/{link["id"]}', headers=headers, verify=False)
  14. print(f"Deleted old link: {link['title']}")
  15. bookmarks = [
  16. {"title": "26.04.30 PLAN", "href": "26-04-30-plan"},
  17. {"title": "26.04.30 DAILY", "href": "26-04-30-daily"},
  18. {"title": "26.04.30 REVIEW", "href": "26-04-30-review"},
  19. {"title": "26.04.30 RETROSPECTIVE", "href": "26-04-30-retrospective"},
  20. {"title": "26.04.30 ARTIFACT", "href": "26-04-30-artifact"}
  21. ]
  22. # Calculate fresh order
  23. existing = requests.get(f'{base_url}/wiki-links?project={proj_id}', headers=headers, verify=False).json()
  24. max_order = max([e['order'] for e in existing]) if existing else 0
  25. for i, b in enumerate(bookmarks):
  26. payload = {
  27. "project": proj_id,
  28. "title": b["title"],
  29. "href": b["href"],
  30. "order": max_order + i + 1
  31. }
  32. r = requests.post(f'{base_url}/wiki-links', json=payload, headers=headers, verify=False)
  33. print(f'Created Bookmark {b["title"]}: {r.status_code}')