diff --git a/datecsv.sh b/datecsv.sh new file mode 100755 index 0000000..17af6e3 --- /dev/null +++ b/datecsv.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +DATAFILE=Database.db + +SQLITE="sqlite3 -csv -header" + +QUERY="SELECT SUBSTR(t.timestamp,0,11) AS 'Date', (SELECT COUNT(*) FROM tweets e WHERE SUBSTR(e.timestamp,0,11) = SUBSTR(t.timestamp,0,11)) AS 'Tweets'" + +for i in $@; + do QUERY="$QUERY, (SELECT COUNT(*) FROM tweets e WHERE SUBSTR(e.timestamp,0,11) = SUBSTR(t.timestamp,0,11) AND LOWER(e.text) LIKE '%${i,,}%') AS '$i'" +done + +QUERY="$QUERY FROM tweets t GROUP BY SUBSTR(t.timestamp,0,11);" + +$SQLITE $DATAFILE "$QUERY" diff --git a/gethandles.py b/gethandles.py new file mode 100755 index 0000000..f246c10 --- /dev/null +++ b/gethandles.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +# -*- 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(list(getTweets().items()), key=operator.itemgetter(1), reverse=True) + for handle, tweets in data: + print(handle + "," + str(tweets))