Skip to content

Instantly share code, notes, and snippets.

@judell
Created October 19, 2016 17:49
Show Gist options
  • Save judell/f918b327932774433888f1ca8bb281f7 to your computer and use it in GitHub Desktop.
Save judell/f918b327932774433888f1ca8bb281f7 to your computer and use it in GitHub Desktop.
def url_transfer_row(id=None, url_dest=None, username=None, token=None):
h = Hypothesis(username=username, token=token)
row = h.get_annotation(id)
try:
row['user'] = 'acct:' + h.username + '@hypothes.is'
permissions = row['permissions']
permission_fields = ['admin','update','delete']
for field in permission_fields:
permissions[field][0] = 'acct:' + h.username + '@hypothes.is'
row['permissions'] = permissions
del row['created']
del row['updated']
del row['id']
del row['links']
row['target'][0]['source'] = url_dest
row['uri'] = url_dest
selectors = row['target'][0]['selector']
_selectors = []
for selector in selectors:
if selector['type'] == 'TextQuoteSelector':
_selectors.append(selector)
row['target'][0]['selector'] = _selectors
r = h.post_annotation(row)
print (r.status_code)
except:
print (traceback.print_exc())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment