Skip to content

Commit

Permalink
Return tuple containing last tweet in window
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestaylr committed Jan 10, 2017
1 parent 98f493d commit 8b60276
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def is_duplicate(product, name):
print 'Duplicate product', product['loc']
continue

if twitter.has_been_tweeted(product['image:image']['image:title']):
title = product['image:image']['image:title']
has_tweeted, last_tweet = twitter.has_been_tweeted(title)
if has_tweeted:
print 'Not posting duplicated tweet for', product['loc']
continue

Expand Down
9 changes: 6 additions & 3 deletions lib/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ def has_been_tweeted(match):
)

try:
for tweet in json.loads(content):
tweets = json.loads(content)
last = tweets[len(tweets) - 1]

for tweet in tweets:
if match in tweet['text']:
return True
return False
return True, last
return False, last
except ValueError:
return False

3 changes: 2 additions & 1 deletion monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def get_products(url, limit):
if product['id'] == int(previous[0]):
break

if twitter.has_been_tweeted(product['title']):
has_tweeted, last_tweet = twitter.has_been_tweeted(product['title'])
if has_tweeted:
print 'Not posting duplicated tweet for', product['handle']
continue

Expand Down

0 comments on commit 8b60276

Please sign in to comment.