Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Global variables for superfeedr
- USERNAME = "grao_genylabs"
- PASSWORD = "L0ngtai!2"
- API_URL = 'https://push.superfeedr.com/'
- MODE_SUBSCRIBE = 'subscribe'
- MODE_RETRIEVE = 'retrieve'
- def post_to_hub(data, method='POST'):
- body = None
- url = API_URL
- base64string = base64.encodestring('%s:%s' % (USERNAME, PASSWORD))[:-1]
- headers = {'Authorization': 'Basic '+ base64string, 'Content-Type':'application/x-www-form-urlencoded', 'User-Agent':'Super Agent/0.0.1'}
- if method == 'GET':
- url = url + '?' + urllib.urlencode(data)
- else:
- body = urllib.urlencode(data)
- response, content = Http(timeout=30).request(url, method=method, body=body, headers=headers)
- return response, content
- def notify_hub(mode, feed, callback=None):
- post_data = {
- 'hub.mode': mode,
- 'hub.topic': feed,
- 'hub.callback': callback,
- 'format': "json"
- }
- response, content = post_to_hub(post_data)
- if response.status != 204:
- # didn't added in superfeedr
- logger.info("the following rss feed was unable to add into superfeedr",feed)
- return response, content
- def retrieve(feed):
- post_data = {
- 'hub.mode': MODE_RETRIEVE,
- 'hub.topic': feed
- }
- return post_to_hub(post_data, method='GET')
- # function which subscribes the given feed in superfeedr
- def subscribe(feed, callback):
- return notify_hub(MODE_SUBSCRIBE, feed, callback)
- response, content = subscribe(post['status']['feed'], URL)
Add Comment
Please, Sign In to add comment