2015-04-13 20:11:42 +00:00
|
|
|
#!/usr/bin/env python3
|
2015-04-12 22:08:33 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import operator, re, sqlite3
|
|
|
|
|
|
|
|
def getTweets(database_filename = "Database.db"):
|
|
|
|
sql_conn = sqlite3.connect(database_filename)
|
|
|
|
cur = sql_conn.cursor()
|
|
|
|
|
|
|
|
handles = dict()
|
|
|
|
tweets = cur.execute("SELECT text FROM tweets")
|
|
|
|
|
|
|
|
for tweet in tweets:
|
|
|
|
for word in tweet[0].split():
|
|
|
|
if word[0] == "@":
|
|
|
|
handle = "@" + re.split('[\\W]',word[1:])[0].lower()
|
|
|
|
if handle != "@":
|
|
|
|
try:
|
|
|
|
handles[handle] += 1
|
|
|
|
except KeyError:
|
|
|
|
handles[handle] = 1
|
|
|
|
|
|
|
|
return handles
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2015-04-13 20:11:42 +00:00
|
|
|
data = sorted(list(getTweets().items()), key=operator.itemgetter(1), reverse=True)
|
2015-04-12 22:08:33 +00:00
|
|
|
for handle, tweets in data:
|
2015-04-13 20:11:42 +00:00
|
|
|
print(handle + "," + str(tweets))
|