In [ ]:
%matplotlib inline

In [ ]:
try:
    from urllib.parse import urlparse
except ImportError:
    from urlparse import urlparse

In [ ]:
import json

def jpprint(j):
    return json.dumps(j, indent=4, sort_keys=True)

In [ ]:
from hypothesis_settings import (USERNAME, TOKEN)

import requests
API_URL = "https://hypothes.is/api"


# search rdhyee 
headers = {'Authorization': 'Bearer ' + TOKEN, 'Content-Type': 'application/json;charset=utf-8' }
params = {'user': 'rdhyee@hypothes.is'}


r = requests.get(API_URL + "/search", headers=headers, params=params)

print(jpprint(r.json()))

# GET /api
# Host: hypothes.is
# Accept: application/json

OLD STUFF


In [ ]:
# package up logic in a package
from hypothesisapi import API

# include your hypothes.is USERNAME, PASSWORD as parameters in a hypothesis_settings.py file in your sys.path
# get token from https://hypothes.is/profile/developer
from hypothesis_settings import (USERNAME, TOKEN)

h_api = API(USERNAME, TOKEN)

In [ ]:
# https://hypothes.is/a/8qXlSF8gTQmeh29v1XoErg
# https://via.hypothes.is/http://www.meetup.com/SFOpenAnnotation/events/221577503/
# http://www.meetup.com/SFOpenAnnotation/events/221577503/
# http://www.webcitation.org/6Y2WtcAUJ

annotation_id = "8qXlSF8gTQmeh29v1XoErg"
rows = h_api.search_id(annotation_id)
rows

In [ ]:
# Looking for the type of data fields in the annotations. (here: For rdhyee as rdhyee)

from itertools import islice
from collections import Counter

key_count = Counter()

for (i,row) in enumerate(islice(h_api.search(user='rdhyee', offset=0),None)):
    key_count.update(row.keys())

key_count

In [ ]:
h_api.get_annotation(annotation_id)

Annotations

Keys that seem to be present in all annotations:

  • id
  • created
  • updated
  • uri
  • permissions
  • user
  • consumer

In [ ]:
a0 = rows['rows'][0]
(a0['id'], a0['created'], a0['updated'], a0['uri'], a0['permissions'], a0['user'], a0['consumer'])

In [ ]:
# for the annotation for the meetup

a0.keys()

In [ ]:
a0['document']

In [ ]:
a0['target']

Analyzing rdhyee's annotations


In [ ]:
import numpy as np
import pandas as pd
from pandas import (DataFrame, Series)
import matplotlib.pyplot as plt

In [ ]:
# package up logic in a package
from hypothesisapi import API

# include your hypothes.is USERNAME, PASSWORD as parameters in a hypothesis_settings.py file in your sys.path
from hypothesis_settings import (USERNAME, TOKEN)

h_api = API(USERNAME, TOKEN)
h_api.login()

rdhyee_annotations = list(h_api.search(user='rdhyee', offset=0, ))
len(rdhyee_annotations)

In [ ]:
df = DataFrame(rdhyee_annotations)
df.head()

In [ ]:
import datetime
import dateutil

s = df.created.apply(dateutil.parser.parse).apply(lambda d: (d.year, d.month)).value_counts()
s

In [ ]:
(s.sort_index(ascending=True).plot(kind='bar', color='green', # x='year/month', y='# of annotations'
                                  ))

In [ ]:
# get domain of uri

df.uri.apply(lambda url: urlparse(url)[1]).value_counts()

In [ ]:
df.sort_index(by='created', ascending=True)

using Jon's library


In [ ]:
from hypothesis_settings import (USERNAME, TOKEN)
from Hypothes_is import Hypothesis, HypothesisAnnotation

In [ ]:
h = Hypothesis(USERNAME, TOKEN, max_results)

In [ ]:
list(h.search_all({'sort':'updated', 'order':'desc', 'user':'rdhyee@hypothes.is', 'limit':1}))

In [ ]:
def test_create():
    return (h.create_annotation_with_target_using_only_text_quote(
       url="https://www.nytimes.com/2017/05/06/world/europe/france-election-emmanuel-macron-marine-le-pen.html",
       exact=u"""Then, barely an hour before the official close of campaigning at midnight Friday, the staff of the presumed front-runner, Emmanuel Macron, a 39-year-old former investment banker, announced that his campaign had been the target of a “massive and coordinated” hacking operation.""",
       prefix="for its raw anger and insolence.",
       suffix="Internal emails and other docume",
       text="hello",
       tags=()
    ))

In [ ]:
r = test_create()

In [ ]:
r

In [ ]:
r.text