Permalink
Browse files

Updated to use json response for /api/submit

  • Loading branch information...
1 parent f548e6c commit 3eae227c1ad990e01d93e158a16a1ecff7b15aa0 @aperson committed May 7, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 SuggestionBot.py
View
4 SuggestionBot.py
@@ -32,7 +32,7 @@ def _login(self, username, password):
def submit(self, subreddit, title, url=None, text=None):
'''Makes a submission on reddit and returns the url.'''
- body = {'title' : title, 'sr' : subreddit, 'uh' : self.modhash}
+ body = {'title' : title, 'sr' : subreddit, 'uh' : self.modhash, 'api_type' : 'json'}
if url:
body['kind'] = 'link'
body['url'] = url
@@ -45,7 +45,7 @@ def submit(self, subreddit, title, url=None, text=None):
try:
with self.opener.open('http://www.reddit.com/api/submit', body) as w:
- link = json.loads(w.read().decode('utf-8'))['jquery'][12][3][0]
+ link = json.loads(w.read().decode('utf-8'))['json']['data']['url']
return(link)
except urllib.error.HTTPError:
print('Failed to submit!')

0 comments on commit 3eae227

Please sign in to comment.