Created
December 16, 2013 21:00
-
-
Save maluta/7994360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding:utf-8 -*- | |
import re | |
import csv | |
import sys | |
from datetime import datetime | |
tweets = csv.reader(open("tweets.csv"), delimiter=',', quotechar='"') | |
tweets_per_year = { 2008:0, 2009:0, 2010:0, 2011:0, 2012:0, 2013:0 } | |
tweets_per_hour = { 0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, | |
7:0, 8:0, 9:0, 10:0, 11:0, 12:0, | |
13:0, 14:0, 15:0, 16:0, 17:0, 18:0, | |
19:0, 20:0, 21:0, 22:0, 23:0 } | |
format = '%Y-%m-%d %H:%M:%S' #2013-12-13 06:33:25 +0000 | |
for tweet in tweets: | |
date = tweet[3] | |
if date != "timestamp": | |
date_object = datetime.strptime(date[:-6],format) | |
year = date_object.year | |
for y in tweets_per_year: | |
if y == year: | |
tweets_per_year[year] += 1 | |
hour = date_object.hour | |
minute = date_object.minute | |
second = date_object.second | |
if hour == 0 and minute == 0 and second == 0: | |
pass | |
else: | |
for t in tweets_per_hour: | |
if t == hour: | |
tweets_per_hour[t] += 1 | |
print tweets_per_year | |
print tweets_per_hour | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment