1
0

create_bookmarks_page.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 = 'bookmarks'
  9. content = """# BOOKMARKS
  10. - [26.05.07 DAILY](260507-daily)
  11. - [26.05.07 REVIEW](260507-review)
  12. - [26.05.07 RETROSPECTIVE](260507-retrospective)
  13. - [26.05.07 PLAN](260507-plan)
  14. - [26.05.08 DAILY](260508-daily)
  15. - [26.05.08 REVIEW](260508-review)
  16. - [26.05.08 RETROSPECTIVE](260508-retrospective)
  17. - [26.05.08 PLAN](260508-plan)
  18. """
  19. check_req = requests.get(f'{base_url}/wiki?project={proj_id}&slug={slug}', headers=headers, verify=False)
  20. if check_req.status_code == 200:
  21. wiki_pages = check_req.json()
  22. if len(wiki_pages) > 0:
  23. page_id = wiki_pages[0]['id']
  24. version = wiki_pages[0]['version']
  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. print("Updated bookmarks page!")
  33. exit()
  34. payload = {
  35. "project": proj_id,
  36. "slug": slug,
  37. "content": content
  38. }
  39. res = requests.post(f'{base_url}/wiki', json=payload, headers=headers, verify=False)
  40. if res.status_code == 201:
  41. print("Created bookmarks page!")
  42. else:
  43. print(f"Failed to create bookmarks: {res.text}")