This repository was archived by the owner on Oct 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchcurators.py
More file actions
45 lines (40 loc) · 1.62 KB
/
fetchcurators.py
File metadata and controls
45 lines (40 loc) · 1.62 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# coding=utf-8
"""
Lädt die Liste mit den Curatoren des Accounts
@author Markus Tacker <m@coderbyheart.de>
"""
import vertx
import mutex
import time
from com.xhaus.jyson import JysonCodec as json
from oauth import Consumer
from core.event_bus import EventBus
config = vertx.config()
curators = None
fetching = mutex.mutex()
def response_handler(resp):
# TODO: Error handling
# print "got response %s" % resp.status_code
# print resp.headers
@resp.body_handler
def body_handler(body):
global curators
if resp.status_code == 200:
data = json.loads(body.to_string())
curators = []
for user in data['users']:
curators.append({'screen_name': user['screen_name'], 'id': user['id']})
fetching.unlock()
EventBus.send('log.event', "curators.list.result")
EventBus.send('curators.list.result', json.dumps(curators))
def list_curators(message):
global fetching
if curators is None:
if not fetching.testandset():
return
consumer = Consumer(api_endpoint="https://api.twitter.com/", consumer_key=config['consumer_key'], consumer_secret=config['consumer_secret'], oauth_token=config['oauth_token'], oauth_token_secret=config['oauth_token_secret'])
consumer.get("/1.1/lists/members.json", {'slug': config['curatorslist'], 'owner_screen_name': config['account']}, response_handler)
else:
EventBus.send('log.event', "curators.list.result (Cached)")
EventBus.send('curators.list.result', json.dumps(curators))
EventBus.register_handler('curators.list', False, list_curators)