Advertisement
Atheuz

Untitled

Mar 22nd, 2012 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. # Filename      main.py
  4. # First edited  22-03-2012 19:45
  5. # Last edited   22-03-2012 20:01
  6.  
  7. import sqlite3
  8. import os, sys
  9. import collections
  10.  
  11. def export_messages():
  12.     conn = sqlite3.connect("main.db")
  13.     c = conn.cursor()
  14.     logins = [x[4] for x in c.execute("SELECT * FROM messages ORDER BY id DESC").fetchall()]
  15.     s = float(sum([x[1] for x in collections.Counter(logins).iteritems()]))
  16.     for i in sorted(collections.Counter(logins).iteritems(), key=lambda x: x[1], reverse=True):
  17.         print "Login: %s - Beskeder: %s - Procentvis: %.2f" % (i[0].ljust(25), str(i[1]).ljust(10), (i[1]/s)*100)
  18.     #for i in c.execute("SELECT * FROM messages ORDER BY id DESC").fetchall():
  19.         #try:
  20.             #i[-19].encode('utf-8')#print i[4], i[-19].encode('utf8')
  21.             #print "\n"
  22.         #except AttributeError:
  23.         #    print i
  24.  
  25. def main():
  26.     export_messages()
  27.  
  28. if __name__ == '__main__':
  29.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement