Skip to content

Instantly share code, notes, and snippets.

@rdhyee
Created November 5, 2012 19:21
Show Gist options
  • Save rdhyee/4019742 to your computer and use it in GitHub Desktop.
Save rdhyee/4019742 to your computer and use it in GitHub Desktop.
Extracting Stripe event types from the documents
import requests
from StringIO import StringIO
from lxml.html import parse
from collections import defaultdict
import re
# the list of Stripe events in the documentation and is not currently available from the API itself
url = "https://stripe.com/docs/api#event_types"
r = requests.get(url)
doc = parse(StringIO(r.content)).getroot()
ev_dts = doc.cssselect('#event_types + div')[0].findall('.//dt')
event_types = [ev_dt.text_content() for ev_dt in ev_dts]
print event_types
resource_actions = [(event_type, None) if re.match("^(.+)\.([^\.]*)$", event_type) is None else re.match("^(.+)\.([^\.]*)$", event_type).groups() for event_type in event_types]
print resource_actions
ra = defaultdict(set)
for (r,a) in resource_actions:
ra[r].add(a)
print ra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment