Browse Source

fixing age issue

master
Andreas Demmelbauer 6 years ago
parent
commit
913c672375
1 changed files with 14 additions and 6 deletions
  1. +14
    -6
      tootbot.py

+ 14
- 6
tootbot.py View File

@@ -91,15 +91,17 @@ for p in reversed(t.entries):
) )
last = db.fetchone() last = db.fetchone()


print('Processing: %s' % p.id)
shouldpost = True shouldpost = True
posttime = datetime(p.published_parsed.tm_year, p.published_parsed.tm_mon, p.published_parsed.tm_mday, p.published_parsed.tm_hour, p.published_parsed.tm_min, p.published_parsed.tm_sec) posttime = datetime(p.published_parsed.tm_year, p.published_parsed.tm_mon, p.published_parsed.tm_mday, p.published_parsed.tm_hour, p.published_parsed.tm_min, p.published_parsed.tm_sec)
if last is not None: if last is not None:
shouldpost = False shouldpost = False
print("skip: already posted") print("skip: already posted")
# process only unprocessed tweets less than n days old # process only unprocessed tweets less than n days old
if datetime.now() - posttime > timedelta(days=days):
age = datetime.now() - posttime
if age > timedelta(days=days):
shouldpost = False shouldpost = False
print("skip: Tweet older than %s days" % days)
print("skip: Posting older than %s days (%s)" % (days, age) )
# kill tweets with fb links with fire! # kill tweets with fb links with fire!
if "https://www.facebook.com" in p.title or "https://m.facebook.com" in p.title: if "https://www.facebook.com" in p.title or "https://m.facebook.com" in p.title:
shouldpost = False shouldpost = False
@@ -173,6 +175,7 @@ h.body_width = 0


s = feedparser.parse('http://'+soupuser+'/rss') s = feedparser.parse('http://'+soupuser+'/rss')



# start with oldest # start with oldest
for p in reversed(s.entries): for p in reversed(s.entries):
# check if this tweet has been processed # check if this tweet has been processed
@@ -182,14 +185,19 @@ for p in reversed(s.entries):
) )
last = db.fetchone() last = db.fetchone()


print('Processing: %s' % p.id)
if last is not None: if last is not None:
shouldpost = False shouldpost = False
print("skip: already posted") print("skip: already posted")
# process only unprocessed tweets less than n days old # process only unprocessed tweets less than n days old
if datetime.now() - posttime > timedelta(days=days):
shouldpost = True

posttime = datetime(p.published_parsed.tm_year, p.published_parsed.tm_mon, p.published_parsed.tm_mday, p.published_parsed.tm_hour, p.published_parsed.tm_min, p.published_parsed.tm_sec)
age = datetime.now() - posttime
if age > timedelta(days=days):
shouldpost = False shouldpost = False
print("skip: Posting older than %s days" % days)
print("skip: Posting older than %s days (%s)" % (days, age) )


if shouldpost: if shouldpost:
# Create application if it does not exist # Create application if it does not exist
@@ -216,7 +224,7 @@ for p in reversed(s.entries):
postedtweets.append(postedtweet[0].split('/')[-1]) postedtweets.append(postedtweet[0].split('/')[-1])
# check if already tweeted # check if already tweeted
if tweet_id in postedtweets: if tweet_id in postedtweets:
print('Already tweeted: ', j['source'])
print('Already posted the Tweet: ', j['source'])


else: else:
# collect information about images # collect information about images


Loading…
Cancel
Save