Skip to content

Instantly share code, notes, and snippets.

@abutcher
Created March 4, 2012 07:35
Show Gist options
  • Select an option

  • Save abutcher/1971139 to your computer and use it in GitHub Desktop.

Select an option

Save abutcher/1971139 to your computer and use it in GitHub Desktop.
AndrewsTimeRelativeFuckStoppedDown
def AndrewsTimeRelativeFuckStoppedDown(data):
what_i_care_about = []
# Gather what I care about...
for tweet in data[u'results']:
tweet_date = datetime.datetime(*time.strptime(tweet[u'created_at'],
"%a, %d %b %Y %H:%M:%S +0000")[0:6])
tweet_text = tweet[u'text']
what_i_care_about.append((tweet_date, tweet_text))
# Sort the tweets by date if not sorted already
what_i_care_about = sorted(what_i_care_about, key=lambda t: t[0])
# Get the current and last bad tweet.
for tweet in what_i_care_about:
if "down" in tweet[1] or "stopped" in tweet[1] or "fuck" in tweet[1]:
current = tweet
break
for tweet in what_i_care_about:
if "down" in tweet[1] or "stopped" in tweet[1] or "fuck" in tweet[1] and tweet != current:
last = tweet
break
delta = datetime.timedelta(minutes=30)
now = datetime.datetime(*time.localtime()[0:6])
relative_delta = now - delta
if not current or not last:
print "Not enough bad data to work with."
elif current[0] - last[0] < delta and last[0] > relative_delta:
print "The PRT is probably down."
else:
print "The PRT is probably up."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment