Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import time
- from pprint import pprint as pp #for simplicity
- ## LOGIN to reddit ##
- url = r'http://www.reddit.com/api/login/'
- payload = {'user': 'USERNAME',
- 'passwd': 'PASSWORD',
- 'api_type': 'json'}
- r = requests.post(url, payload)
- #save the cookie
- redditCookie = r.cookies
- #print the response
- print 'Login Response:'
- j = json.loads(r.text)
- pp(j)
- #save the modhash
- mh = j['json']['data']['modhash']
- ##SUBMIT to reddit ##
- url = r'http://www.reddit.com/api/submit'
- payload = {'title' : 'API TEST!',
- 'text': '{}'.format(time.asctime()),
- 'sr': 'tankorsmash',
- 'kind': 'self',
- 'uh': mh,
- 'r': 'tankorsmash',
- }
- #post the story
- r = requests.post(url, payload, cookies=redditCookie)
- print 'posted story with hash:', mh
- print 'and cookies:', redditCookie
- #here's the response:
- j = json.loads(r.text)
- print 'response from API after submission'
- pp(j)
Add Comment
Please, Sign In to add comment