29 lines
697 B
Python
29 lines
697 B
Python
|
#!/usr/bin/env python
|
||
|
# -*- 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__":
|
||
|
data = sorted(getTweets().items(), key=operator.itemgetter(1), reverse=True)
|
||
|
for handle, tweets in data:
|
||
|
print handle + "," + str(tweets)
|