Created
November 5, 2012 19:21
-
-
Save rdhyee/4019742 to your computer and use it in GitHub Desktop.
Extracting Stripe event types from the documents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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