-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathraw.py
More file actions
33 lines (27 loc) · 1.22 KB
/
Copy pathraw.py
File metadata and controls
33 lines (27 loc) · 1.22 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
#!/usr/bin/env python3
"""Get a page's raw markdown text via the /api/raw endpoint.
Raw access is never open by default. Access codes are issued by rentry admins
(request one from support@rentry.co); a page's SECRET_RAW_ACCESS_CODE metadata
can only be set to an already-issued code. Access is granted when either:
- the request bears an issued access code (passed as auth_code below)
or
- the page itself has an issued SECRET_RAW_ACCESS_CODE set.
This example creates a page and then reads it back over raw using an issued
access code from the RAW_ACCESS_CODE environment variable.
"""
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')
auth_code = os.getenv('RAW_ACCESS_CODE', '')
client = RentryClient(base_url)
# Create a page to read back over raw.
page = client.new(text='raw access example')
assert page['status'] == '200', page['content']
print(page)
# An issued access code grants raw access to any page, including the one we
# just created. Without a valid auth_code the API returns an error explaining
# how to obtain one.
result = client.raw(page['url_short'], auth_code=auth_code)
print(result)