Guest User

Untitled

a guest
Jun 1st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. # Global variables for superfeedr
  2. USERNAME = "grao_genylabs"
  3. PASSWORD = "L0ngtai!2"
  4. API_URL = 'https://push.superfeedr.com/'
  5. MODE_SUBSCRIBE   = 'subscribe'
  6. MODE_RETRIEVE    = 'retrieve'
  7.  
  8. def post_to_hub(data, method='POST'):
  9.     body = None
  10.     url  = API_URL
  11.     base64string = base64.encodestring('%s:%s' % (USERNAME, PASSWORD))[:-1]
  12.     headers = {'Authorization': 'Basic '+ base64string, 'Content-Type':'application/x-www-form-urlencoded', 'User-Agent':'Super Agent/0.0.1'}
  13.     if method == 'GET':
  14.         url = url + '?' + urllib.urlencode(data)
  15.     else:      
  16.         body = urllib.urlencode(data)
  17.    
  18.     response, content = Http(timeout=30).request(url, method=method, body=body, headers=headers)
  19.     return response, content
  20.  
  21. def notify_hub(mode, feed, callback=None):
  22.     post_data = {
  23.         'hub.mode': mode,
  24.         'hub.topic': feed,
  25.         'hub.callback': callback,
  26.         'format': "json"
  27.     }
  28.     response, content = post_to_hub(post_data)
  29.     if response.status != 204:
  30.         # didn't added in superfeedr
  31.         logger.info("the following rss feed was unable to add into superfeedr",feed)
  32.     return response, content
  33.  
  34. def retrieve(feed):
  35.     post_data = {
  36.         'hub.mode': MODE_RETRIEVE,
  37.         'hub.topic': feed
  38.     }
  39.     return post_to_hub(post_data, method='GET')
  40.  
  41. # function which subscribes the given feed in superfeedr        
  42. def subscribe(feed, callback):
  43.     return notify_hub(MODE_SUBSCRIBE, feed, callback)
  44.    
  45. response, content = subscribe(post['status']['feed'], URL)
Add Comment
Please, Sign In to add comment