-
Notifications
You must be signed in to change notification settings - Fork 0
/
Email.py
42 lines (34 loc) · 1.17 KB
/
Email.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sqlite3
import re
conn = sqlite3.connect('orgdb.sqlite')
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS Counts')
cur.execute('''
CREATE TABLE Counts (org TEXT, count INTEGER)''')
fname = input('Enter file name: ')
if (len(fname) < 1): fname = 'mbox.txt'
fh = open(fname)
for line in fh:
if not (line.startswith('From: ')): continue
#if not (line.startswith('X-Authentication-Warning:')): continue
#pieces = re.findall('@\S*[a-zA-Z]',line)[0]
if line.startswith('Author:'):
pieces = line.split()
org = (pieces[6].split("@"))[1]
else:
pieces = line.split()
org = (pieces[1].split("@"))[1]
cur.execute('SELECT count FROM Counts WHERE org = ? ', (org,))
row = cur.fetchone()
if row is None:
cur.execute('''INSERT INTO Counts (org, count)
VALUES (?, 1)''', (org,))
else:
cur.execute('UPDATE Counts SET count = count + 1 WHERE org = ?',
(org,))
conn.commit()
# https://www.sqlite.org/lang_select.html
sqlstr = 'SELECT org, count FROM Counts ORDER BY count DESC LIMIT 1'
for row in cur.execute(sqlstr):
print(str(row[0]), row[1])
cur.close()