1
0

create_bookmarks_page.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. """
  15. check_req = requests.get(f'{base_url}/wiki?project={proj_id}&slug={slug}', headers=headers, verify=False)
  16. if check_req.status_code == 200:
  17. wiki_pages = check_req.json()
  18. if len(wiki_pages) > 0:
  19. page_id = wiki_pages[0]['id']
  20. version = wiki_pages[0]['version']
  21. payload = {
  22. "project": proj_id,
  23. "slug": slug,
  24. "content": content,
  25. "version": version
  26. }
  27. res = requests.put(f'{base_url}/wiki/{page_id}', json=payload, headers=headers, verify=False)
  28. print("Updated bookmarks page!")
  29. exit()
  30. payload = {
  31. "project": proj_id,
  32. "slug": slug,
  33. "content": content
  34. }
  35. res = requests.post(f'{base_url}/wiki', json=payload, headers=headers, verify=False)
  36. if res.status_code == 201:
  37. print("Created bookmarks page!")
  38. else:
  39. print(f"Failed to create bookmarks: {res.text}")