Created
August 23, 2016 20:45
-
-
Save manichabba/4564251b5ba18b2de0c6bec72c715238 to your computer and use it in GitHub Desktop.
Counting Organizations This application will read the mailbox data (mbox.txt) count up the number email messages per organization (i.e. domain name of the email address) using a database with the following schema to maintain the counts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sqlite3 | |
conn = sqlite3.connect('emaildb.sqlite') | |
cur = conn.cursor() | |
cur.execute(''' | |
DROP TABLE IF EXISTS Counts''') | |
cur.execute(''' | |
CREATE TABLE Counts (org TEXT, count INTEGER)''') | |
fname = raw_input('Enter file name: ') | |
if ( len(fname) < 1 ) : fname = 'mbox.txt' | |
fh = open(fname) | |
for line in fh: | |
if not line.startswith('From: ') : continue | |
pieces = line.split()[1] | |
org = pieces.split('@')[1] | |
print org | |
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() | |
sqlstr = 'SELECT org, count FROM Counts ORDER BY count DESC LIMIT 10' | |
print "Counts:" | |
for row in cur.execute(sqlstr) : | |
print str(row[0]), row[1] | |
cur.close() |
Non of the codes for me is actually counting orgs, maximum i get is 1? what am i doing wrong , i already tried all the codes here ans mine which were similar and trying to correct where i think mistake can be , and yes i do have mbox.txt saved in same directory and i do have created db.sqlite files but they either empty or counting 1, please help
me too and i can't pass this task did u pass it?
Send me more details so that I can help you out.
…On Mon, Jun 17, 2024 at 6:36 PM Bssmmn ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
me too and i can't pass this task did u pass it?
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/manichabba/4564251b5ba18b2de0c6bec72c715238#gistcomment-5091503>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQLNHCJGL5QWWWJJFDGMFQTZH3NODBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZTSMJRGA3DGNNHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Yes now i passed all of them
________________________________
From: Kartik Nanneboina ***@***.***>
Sent: 17 June 2024 14:27
To: kartik-nv ***@***.***>
Cc: Comment ***@***.***>
Subject: Re: manichabba/Sqlite.py
@kartik-nv commented on this gist.
________________________________
Send me more details so that I can help you out.
On Mon, Jun 17, 2024 at 6:36 PM Bssmmn ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
me too and i can't pass this task did u pass it?
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/manichabba/4564251b5ba18b2de0c6bec72c715238#gistcomment-5091503>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQLNHCJGL5QWWWJJFDGMFQTZH3NODBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZTSMJRGA3DGNNHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
—
Reply to this email directly, view it on GitHub<https://gist.github.com/manichabba/4564251b5ba18b2de0c6bec72c715238#gistcomment-5091514> or unsubscribe<https://github.com/notifications/unsubscribe-auth/BFE7DXNN6FAU7AAWIP2NLWTZH3P57BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZTSMJRGA3DGNNHORZGSZ3HMVZKMY3SMVQXIZI>.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
Can anyone help me getting the desired answer that is 536?
I am not getting sql query error database disk image malformed... Can any help me out please
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the solution that works for me :