Handle Reddit PRAW exceptions
This commit is contained in:
parent
2ede5ed6ff
commit
0a1ebaa8b8
|
@ -8,7 +8,9 @@ if __name__ == '__main__':
|
||||||
sys.path.insert(0,'.')
|
sys.path.insert(0,'.')
|
||||||
|
|
||||||
import praw
|
import praw
|
||||||
|
from praw.exceptions import PRAWException
|
||||||
from praw.models import MoreComments
|
from praw.models import MoreComments
|
||||||
|
from prawcore.exceptions import PrawcoreException
|
||||||
|
|
||||||
from utils import render_md
|
from utils import render_md
|
||||||
|
|
||||||
|
@ -20,7 +22,14 @@ SITE_AUTHOR_LINK = lambda x : 'https://old.reddit.com/u/{}'.format(x)
|
||||||
reddit = praw.Reddit('bot')
|
reddit = praw.Reddit('bot')
|
||||||
|
|
||||||
def feed():
|
def feed():
|
||||||
|
try:
|
||||||
return [x.id for x in reddit.subreddit(SUBREDDITS).hot()]
|
return [x.id for x in reddit.subreddit(SUBREDDITS).hot()]
|
||||||
|
except PRAWException as e:
|
||||||
|
logging.error('Problem hitting reddit API: {}'.format(str(e)))
|
||||||
|
return []
|
||||||
|
except PrawcoreException as e:
|
||||||
|
logging.error('Problem hitting reddit API: {}'.format(str(e)))
|
||||||
|
return []
|
||||||
|
|
||||||
def comment(i):
|
def comment(i):
|
||||||
if isinstance(i, MoreComments):
|
if isinstance(i, MoreComments):
|
||||||
|
@ -40,6 +49,7 @@ def comment(i):
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def story(ref):
|
def story(ref):
|
||||||
|
try:
|
||||||
r = reddit.submission(ref)
|
r = reddit.submission(ref)
|
||||||
if not r: return False
|
if not r: return False
|
||||||
|
|
||||||
|
@ -60,6 +70,13 @@ def story(ref):
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
except PRAWException as e:
|
||||||
|
logging.error('Problem hitting reddit API: {}'.format(str(e)))
|
||||||
|
return False
|
||||||
|
except PrawcoreException as e:
|
||||||
|
logging.error('Problem hitting reddit API: {}'.format(str(e)))
|
||||||
|
return False
|
||||||
|
|
||||||
# scratchpad so I can quickly develop the parser
|
# scratchpad so I can quickly develop the parser
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(feed())
|
print(feed())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user