Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import requests.auth
- import json
- import re
- from ConfigParser import ConfigParser
- def parseDeal(source):
- deal = {}
- deal['store'] = source['data']['title']
- config = ConfigParser()
- config.read('config.cfg')
- client_id = config.get('Auth', 'client_id')
- client_secret = config.get('Auth', 'client_secret')
- username = config.get('Auth', 'username')
- password = config.get('Auth', 'password')
- client_auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
- post_data = {'grant_type': 'password', 'username': username, 'password': password}
- headers = {'User-Agent': 'DealsBot by ArqadeDeals'}
- response = requests.post('https://www.reddit.com/api/v1/access_token', auth=client_auth, data=post_data, headers=headers)
- access_token = response.json()['access_token']
- headers = {'Authorization': 'bearer ' + access_token, 'User-Agent': 'DealsBot by ArqadeDeals'}
- response = requests.get('https://oauth.reddit.com/r/gamedeals/hot/?limit=25', headers=headers)
- deals = []
- for post in response.json()['data']['children']:
- d = []
- d.append(post['data']['title'].encode('utf-8', 'replace'))
- d.append(post['data']['url'].encode('utf-8', 'replace'))
- deals.append(d)
- with open('deals.txt', 'w') as outfile:
- for deal in deals:
- outfile.write(deal[0] + ' ?\\|/? ' + deal[1] + '\n')
Add Comment
Please, Sign In to add comment