Skip to content

Instantly share code, notes, and snippets.

@hancush
Forked from anonymous/datetime_filter.py
Last active September 11, 2015 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hancush/6d934adf79a685db6d94 to your computer and use it in GitHub Desktop.
Save hancush/6d934adf79a685db6d94 to your computer and use it in GitHub Desktop.
from datetime import datetime, timedelta
import tweepy
from config import *
import requests
requests.packages.urllib3.disable_warnings()
OAUTH_KEYS = (ckey, csecret, atoken, asecret)
auth = tweepy.OAuthHandler(ckey, csecret)
twitter = tweepy.API(auth)
timeline = tweepy.Cursor(twitter.list_timeline, list_id=211679718).items(999)
count = 0
now = datetime.now().strftime('%H:%M:%S')
cutoff = (datetime.now() - timedelta(hours=1)).strftime('%H:%M:%S')
for tweet in timeline:
count += 1
data = tweet._json
# format created_at string to datetime #
raw_time = datetime.strptime(data['created_at'], '%a %b %d %H:%M:%S +0000 %Y')
# convert created_at from UTC to CDT (my local time) #
adjust_time = raw_time - timedelta(hours=5)
# reformat adjusted time to hour:minute:second as string #
time = adjust_time.strftime('%H:%M:%S')
if time > cutoff:
print count, time, tweet.text
else:
print count, time, tweet.text, time > cutoff
break
print "Now: ", now
print "Cutoff ", cutoff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment