Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
107 lines (87 loc) · 3.42 KB

File metadata and controls

107 lines (87 loc) · 3.42 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
"""
If you've installed the Python Draftable API then execute like:
DR_ACCOUNT=<your-account> DR_TOKEN=<your-token> python example/simple.py
If you're running from the git repo, then execute as below (setting PYTHONPATH):
PYTHONPATH=. DR_ACCOUNT=<your-account> DR_TOKEN=<your-token> python example/simple.py
Replace "<your-account>" and "<your-token>" with values from your Draftable
account at https://api.draftable.com/account/credentials
"""
import os
import sys
import time
import draftable
from draftable.endpoints.comparisons.changes import Change
# From https://api.draftable.com/account/credentials under "Account ID"
account_id = os.environ.get("DR_ACCOUNT")
auth_token = os.environ.get("DR_TOKEN")
base_url = os.environ.get("DR_BASE_URL") # Enterprise only
if not account_id or not auth_token:
sys.stderr.write(
"Provide both DR_ACCOUNT and DR_TOKEN environment variables\n"
)
sys.stderr.write(
'See https://api.draftable.com/account/credentials under "Account ID"\n'
)
sys.exit(1)
if base_url and not base_url.endswith("/v1"):
sys.stderr.write(
f'Value for DR_BASE_URL is "{base_url}" but must end with "/v1"\n'
)
sys.exit(1)
draftable_client = draftable.Client(account_id, auth_token, base_url)
comparisons = draftable_client.comparisons
# Create a new comparison with existing sample files
comparison = comparisons.create(
left="test-files/hello-left.txt",
right="test-files/hello-right.txt",
# Alternatively, be explicit about "type" (RTF, PDF, etc) and display name:
#
# left=comparisons.side_from_url('https://api.draftable.com/static/test-documents/code-of-conduct/left.rtf', 'rtf'),
# right=comparisons.side_from_url('https://api.draftable.com/static/test-documents/code-of-conduct/right.pdf', 'pdf'),
)
print(f"Created comparison:\n {comparison}")
print(
f" - Public URL: {comparisons.public_viewer_url(comparison.identifier)}"
)
print(
f" - Signed URL: {comparisons.signed_viewer_url(comparison.identifier)}"
)
for _ in range(10):
if comparisons.get(comparison.identifier).ready:
break
time.sleep(1)
print(f"\nListing changes:\n {comparison}")
change_details = comparisons.change_details(comparison.identifier)
change: Change
for change in change_details.changes:
if change.kind != "match":
print(f"change.kind: {change.kind}, leftText: {change.leftText}, rightText: {change.rightText}")
# Alternatively, be explicit about "type" (RTF, PDF, etc) and display name:
comparison = comparisons.create(
left=draftable.make_side(
"https://api.draftable.com/static/test-documents/code-of-conduct/left.rtf",
"rtf",
),
right=draftable.make_side(
"https://api.draftable.com/static/test-documents/code-of-conduct/right.pdf",
"pdf",
),
)
print(f"\nCreated with make_side:\n {comparison}")
print(
f" - Public URL: {comparisons.public_viewer_url(comparison.identifier)}"
)
print(
f" - Signed URL: {comparisons.signed_viewer_url(comparison.identifier)}"
)
for _ in range(10):
if comparisons.get(comparison.identifier).ready:
break
time.sleep(1)
print(f"\nListing changes:\n {comparison}")
change_details = comparisons.change_details(comparison.identifier)
change: Change
for change in change_details.changes:
if change.kind != "match":
print(f"change.kind: {change.kind}, leftText: {change.leftText}, rightText: {change.rightText}")
Morty Proxy This is a proxified and sanitized view of the page, visit original site.