Guest User

Untitled

a guest
Apr 7th, 2017
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import requests
  2. import requests.auth
  3. import json
  4. import re
  5. from ConfigParser import ConfigParser
  6.  
  7. def parseDeal(source):
  8. deal = {}
  9. deal['store'] = source['data']['title']
  10.  
  11. config = ConfigParser()
  12. config.read('config.cfg')
  13. client_id = config.get('Auth', 'client_id')
  14. client_secret = config.get('Auth', 'client_secret')
  15. username = config.get('Auth', 'username')
  16. password = config.get('Auth', 'password')
  17.  
  18. client_auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
  19. post_data = {'grant_type': 'password', 'username': username, 'password': password}
  20. headers = {'User-Agent': 'DealsBot by ArqadeDeals'}
  21. response = requests.post('https://www.reddit.com/api/v1/access_token', auth=client_auth, data=post_data, headers=headers)
  22. access_token = response.json()['access_token']
  23. headers = {'Authorization': 'bearer ' + access_token, 'User-Agent': 'DealsBot by ArqadeDeals'}
  24. response = requests.get('https://oauth.reddit.com/r/gamedeals/hot/?limit=25', headers=headers)
  25. deals = []
  26. for post in response.json()['data']['children']:
  27. d = []
  28. d.append(post['data']['title'].encode('utf-8', 'replace'))
  29. d.append(post['data']['url'].encode('utf-8', 'replace'))
  30. deals.append(d)
  31. with open('deals.txt', 'w') as outfile:
  32. for deal in deals:
  33. outfile.write(deal[0] + ' ?\\|/? ' + deal[1] + '\n')
Add Comment
Please, Sign In to add comment