Added a little test script
[pymailstats.git] / test.py
blobec0a312694afb1d5767d448f181aa2221d07ad87
1 #!/usr/bin/env python
3 from mailbasedata import *
4 import email
5 import mhlib
7 # Global variable
8 mh = mhlib.MH("")
9 dir = mhlib.Folder(mh, "")
10 mails = []
12 # basic functions
13 def parseMails():
14 for i in dir.listmessages():
15 mails.append(basedata(mhlib.Message(dir, i)))
18 """Returns a dictionary with all acitve senders (mail address) as key
19 and the number of mails as value. If there is no mail, the dictonary
20 will be empty."""
21 def getActivePoster():
22 poster = {}
23 for i in mails:
24 if i.getFromMailAddr() == None:
25 print i
26 if i.getFromMailAddr() in poster:
27 poster[i.getFromMailAddr()] = poster[i.getFromMailAddr()] + 1
28 else:
29 poster[i.getFromMailAddr()] = 1
30 return poster
33 def getUserMailClient():
34 poster = {}
35 foo = []
36 for i in mails:
37 if i.getPureMailer() == None:
38 print i
39 if i.getPureMailer() in poster:
40 poster[i.getPureMailer()] = poster[i.getPureMailer()] + 1
41 else:
42 poster[i.getPureMailer()] = 1
43 for i,j in poster.iteritems():
44 foo.append([i, j])
45 foo.sort(key=lambda t:-t[1])
46 for i in foo:
47 print i
49 """Returns a dictionary with a tupel mail address, and mail client as
50 key and the number of reconized mails as value. If there is no mail
51 recognized, it will return an empty dictionary. Combninations from
52 mail clinet and email address that did not occur, will have no entry
53 inside the dict."""
54 def getMailClientPerAddress():
55 pairs = {}
56 foo = []
57 for i in mails:
58 if ((i.getFromMailAddr(), i.getMailer()) in pairs):
59 pairs[i.getFromMailAddr(), i.getMailer()] = pairs[i.getFromMailAddr(), i.getMailer()] +1
60 else:
61 pairs[i.getFromMailAddr(), i.getMailer()] = 1
63 return pairs
65 """Returns a dictionary with procentage of usage of each recognized
66 mail client for an email address. The key is builded from trupel of
67 email address and mailclient and will be empty if no mail is
68 recognized."""
69 def getUserFavoriteMailer():
70 # getting data we need here
71 client_per_address = getMailClientPerAddress()
72 mails_per_poster = getActivePoster()
74 usage = {}
75 tmp = client_per_address.keys()
76 for i,j in tmp:
77 usage[i,j] = client_per_address[i,j] * 100 // mails_per_poster[i]
78 print i, j, usage[i,j]
81 def getMailPerDayOfWeek():
82 return None
85 def getJustEveryMailBasisDate():
86 for i in mails:
87 print i.getMailer(), "\t",
88 print i.getDate()
89 print i.getFromMailAddr()
92 parseMails()
93 foo = getActivePoster()
94 for i in foo:
95 print i, foo[i]
96 print getUserFavoriteMailer()
97 print getUserMailClient()
98 foo = getMailClientPerAddress()
99 baa = foo.keys()
100 for i in baa:
101 print i,foo[i]
102 for i in mails:
103 print i.getFromMailAddr(),
104 print i.getMailer()