update_bookmarks.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import requests
  2. import urllib3
  3. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  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': 'BTSai123'}, verify=False).json()
  6. headers = {'Authorization': f'Bearer {auth["auth_token"]}', 'Content-Type': 'application/json'}
  7. proj_id = 21
  8. slug = 'home'
  9. check_req = requests.get(f'{base_url}/wiki?project={proj_id}&slug={slug}', headers=headers, verify=False)
  10. if check_req.status_code == 200:
  11. wiki_pages = check_req.json()
  12. if len(wiki_pages) > 0:
  13. page_id = wiki_pages[0]['id']
  14. version = wiki_pages[0]['version']
  15. content = wiki_pages[0]['content']
  16. # Append the new links if they aren't there
  17. new_links = """
  18. - [26.05.07 DAILY](260507-daily)
  19. - [26.05.07 REVIEW](260507-review)
  20. - [26.05.07 RETROSPECTIVE](260507-retrospective)
  21. - [26.05.07 PLAN](260507-plan)
  22. """
  23. if "260507-daily" not in content:
  24. content += new_links
  25. payload = {
  26. "project": proj_id,
  27. "slug": slug,
  28. "content": content,
  29. "version": version
  30. }
  31. res = requests.put(f'{base_url}/wiki/{page_id}', json=payload, headers=headers, verify=False)
  32. if res.status_code == 200:
  33. print("Bookmarks updated successfully!")
  34. else:
  35. print(f"Failed to update bookmarks: {res.text}")
  36. else:
  37. print("Bookmarks already up to date.")