Commit c3467fdc authored by Sacha's avatar Sacha
Browse files

prevent some 500s for querying

parent 1d29b9a6
......@@ -106,6 +106,7 @@ class Article(object):
"""
def __init__(self, j, training=False):
try:
self.lead = j['snippet']
self.title = j['headline']['main']
self.source = j['source']
......@@ -113,17 +114,22 @@ class Article(object):
self.url = j['web_url']
self.xlarge = 'https://www.nytimes.com/%s' % j['multimedia'][0]['url'] if len(j['multimedia']) > 1 else None
self.published = j['pub_date'][:10]
self.full = self._full_text(training)
self.training = training
if training:
sw = set(stopwords.words('english'))
mod_tit = ' '.join(filter(lambda x: x not in sw,
self.title.split()))
self.queried_title = mod_tit
self.title_tweets = twitter_search(mod_tit, training=training)
self.comments = article_comments(self.url, training=training)
# notice that this count doesn't include tweets
self.n_comments = len(self.comments)
except KeyError:
self.full = None
return None
self.full = self._full_text(training)
self.training = training
if training:
sw = set(stopwords.words('english'))
mod_tit = ' '.join(filter(lambda x: x not in sw,
self.title.split()))
self.queried_title = mod_tit
self.title_tweets = twitter_search(mod_tit, training=training)
self.comments = article_comments(self.url, training=training)
# notice that this count doesn't include tweets
self.n_comments = len(self.comments)
def to_dict(self):
if self.full is not None and len(self.full) != 0:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment