-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathedit_modify_code.py
More file actions
27 lines (21 loc) · 924 Bytes
/
Copy pathedit_modify_code.py
File metadata and controls
27 lines (21 loc) · 924 Bytes
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
#!/usr/bin/env python3
"""Set a modify code, then edit with it.
A modify code ('m:...') lets other people edit a page without being able to
steal it: it cannot change the edit code, url, modify code or SECRET options,
and cannot delete the page.
"""
import os
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='modify code example')
assert page['status'] == '200', page['content']
print(page)
# Set a modify code using the edit code. (Pass new_modify_code='m:' to unset one.)
result = client.edit(page['url_short'], page['edit_code'], new_modify_code='m:example-code')
print(result)
# Edit using the modify code in place of the edit code.
result = client.edit(page['url_short'], 'm:example-code', text='edited via modify code')
print(result)