-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoller.py
More file actions
28 lines (22 loc) · 753 Bytes
/
poller.py
File metadata and controls
28 lines (22 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
import json,sys
base = "http://localhost:8080"
secret = None
if len(sys.argv) == 2:
secret = sys.argv[1]
else:
secret = requests.post(base+"/api/login",data={"username":"daphee","pw":"felix2006"}).content
print "Got secret:",secret
_id = "0"
while True:
print "Polling from ID '%s'" % _id
response = requests.post(base+"/api/get",data={"secret":secret,"operation":"newer_than","_id":_id})
last = None
for msg in json.loads(response.content):
print msg["time"],"-",msg["author"]+":",msg["content"]
last = msg
if not last == None:
_id = last["_id"]
"""response = requests.post(base+"/api/get",data={"secret":secret,"operation":"newer_than","_id":_id},stream=True)
for line in response.iter_content():
print line,"""