#!/usr/bin/python # import MySQL module import MySQLdb import sys import getopt import socket def main(argv): grandtotal=0 grandtotal_current=0 db = MySQLdb.connect(host="localhost", user="mythtv", passwd="mythtv", db="ncid") # create a cursor cursor = db.cursor() # execute SQL statement cursor.execute("select name,number,count(number) as '# calls' from cid group by number,name order by '# calls' DESC limit 20;") result = cursor.fetchall() #Top shows #print '

' print '

' print '' print "Top 20 callers" searchstring=''' ''' cursor.execute("select name,number,count(number) as '# calls' from cid group by number,name order by '# calls' DESC limit 20;") result = cursor.fetchall() for row in result: print " " #print " " print searchstring % (row[0], row [0]) print " " #print " " print searchstring % (row[1], row [1]) print " " #print "%40s %26s %10s" %(row[0],row[2],row[1]) print "
%s
",row[0],"",row[2],"",row[1],"
" print "
" #Top categorys print '
' print '
' #print '

' print '

' print '' print "Last 20 calls" print '
' cursor.execute("select date,time,name,number from cid order by date(ts) DESC ,time DESC limit 20 ;" ) result = cursor.fetchall() for row in result: print " " print " " %(row[0]) print " " #print " " print searchstring % (row[2], row [2]) #print " " print searchstring % (row[3], row [3]) print " " # print "%26s %26s %26s %26s " %(row[0],row[1],row[2],row[3]) print "
%s ",row[1],"",row[2],"",row[3],"
" print "
" if __name__ == "__main__": main(sys.argv[1:])