-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathedit_change_url.py
More file actions
34 lines (28 loc) · 1.02 KB
/
Copy pathedit_change_url.py
File metadata and controls
34 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
"""Move a page to a new url and rotate its edit code."""
import os
import secrets
from dotenv import load_dotenv
from rentry_client import RentryClient
load_dotenv()
base_url = os.getenv('BASE_PROTOCOL', 'https://') + os.getenv('BASE_URL', 'rentry.co')
client = RentryClient(base_url)
page = client.new(text='change url example')
assert page['status'] == '200', page['content']
print(page)
# Random suffixes so reruns don't collide with an existing url.
new_url = page['url_short'] + '-moved-' + secrets.token_hex(4)
new_edit_code = 'rotated-' + secrets.token_hex(4)
# upsert leaves the page's text and metadata untouched. Without it this would
# be a replace-mode edit, and omitting text in replace mode blanks the page.
result = client.edit(
page['url_short'],
page['edit_code'],
update_mode='upsert',
new_url=new_url,
new_edit_code=new_edit_code,
)
print(result)
# The page now answers at the new url, with the new edit code only.
result = client.fetch(new_url, new_edit_code)
print(result)