Permalink
Browse files

docs, etc

  • Loading branch information...
1 parent f1814bd commit f18c4aef3f464760de030178343f7616a9d76fbf @n8han n8han committed Apr 13, 2011
Showing with 12 additions and 8 deletions.
  1. +3 −1 steal.py
  2. +6 −7 storage.py
  3. +3 −0 stream.py
View
@@ -2,4 +2,6 @@
import stream, storage
-stream.jsonizer(storage.event_callback)
+if __name__ == "__main__":
+ # start piping the stream to our storage
+ stream.jsonizer(storage.event_callback)
View
@@ -2,15 +2,14 @@
conn = sqlite3.connect("meetups.sqlite")
-def setup():
- with conn:
- conn.execute("""create table if not exists event
- (id text, name text, description text, url text, time integer)""")
- conn.execute("create unique index if not exists event_id on event (id)")
-
-setup()
+# create tables if not already there
+with conn:
+ conn.execute("""create table if not exists event
+ (id text, name text, description text, url text, time integer)""")
+ conn.execute("create unique index if not exists event_id on event (id)")
def event_callback(event):
+ """Passed event dictionaries as they are streamed in"""
with conn:
values = [event.get(k, None) for k in ['id', 'name', 'description', 'event_url', 'time']]
conn.execute("""insert or replace into event values
View
@@ -3,7 +3,9 @@
last = ""
def jsonizer(event_callback):
+ """Passes json dicts to the given callback"""
def consume(data):
+ """Buffers data and invokes event_callback on completed lines"""
global last
lines = (last + data).split("\n")
for l in lines[:-1]:
@@ -13,4 +15,5 @@ def consume(data):
conn = pycurl.Curl()
conn.setopt(pycurl.URL, "http://stream.meetup.com/2/open_events")
conn.setopt(pycurl.WRITEFUNCTION, consume)
+ # perform() blocks until interrupted or connection is lost
conn.perform()

0 comments on commit f18c4ae

Please sign in to comment.