Skip to content

Instantly share code, notes, and snippets.

@simonw
Forked from bruntonspall/get-pms.py
Created January 5, 2010 12:15
Show Gist options
  • Save simonw/269339 to your computer and use it in GitHub Desktop.
Save simonw/269339 to your computer and use it in GitHub Desktop.
import MySQLdb;
from datetime import datetime
import re
import mailbox
import sys
name = "enation"
threading=False
if len(sys.argv) > 1:
name = sys.argv[1]
if len(sys.argv) > 2:
threading = True
cn = MySQLdb.connect("localhost", "wikileaks", "", name)
results = cn.query(""" SELECT * FROM pm join pmtext on pm.pmtextid = pmtext.pmtextid join user on pmtext.fromuserid = user.userid join user touser on pm.userid = touser.userid;""")
results = cn.use_result()
mbox = mailbox.mbox(name+'-pms.txt')
while True:
msgs = results.fetch_row(maxrows=50, how=1)
if len(msgs) == 0:
break
for msg in msgs:
msg['joindate'] = datetime.fromtimestamp(msg['joindate'])
msg['lastvisit'] = datetime.fromtimestamp(msg['lastvisit'])
msg['lastactivity'] = datetime.fromtimestamp(msg['lastactivity'])
msg['lastpost'] = datetime.fromtimestamp(msg['lastpost'])
msg['dateline'] = datetime.fromtimestamp(msg['dateline'])
msg['mboxdate'] = msg['dateline'].strftime("%a %b %d %H:%M:%S %Y")
msg['message'] = msg['message']
if threading and msg['parentpmid'] != '0':
email = """From %(email)s %(mboxdate)s
To: %(touser.email)s
Date: %(dateline)s
Message-ID: %(pmid)s
In-Reply-To: %(parentpmid)s
Subject: %(title)s
%(message)s
""" % msg
else:
email = """From %(email)s %(mboxdate)s
To: %(touser.email)s
Date: %(dateline)s
Message-ID: %(pmid)s
Subject: %(title)s
%(message)s
""" % msg
mbox.add(mailbox.Message(email))
import MySQLdb;
from datetime import datetime
import sys
name = "enation"
if len(sys.argv) > 1:
name = sys.argv[1]
cn = MySQLdb.connect("localhost", "wikileaks", "", name)
results = cn.query(""" SELECT * FROM user;""")
results = cn.use_result()
userlist = file(name+'-users.txt', 'w')
userlist.write("Username <email> \"homepage\" \"usertitle\" joindate lastvisit lastactivity lastpost")
userdetails = file(name+'-userdetails.txt', 'w')
while True:
users = results.fetch_row(maxrows=0, how=1)
if len(users) == 0:
break
for user in users:
user['joindate'] = datetime.fromtimestamp(user['joindate'])
user['lastvisit'] = datetime.fromtimestamp(user['lastvisit'])
user['lastactivity'] = datetime.fromtimestamp(user['lastactivity'])
user['lastpost'] = datetime.fromtimestamp(user['lastpost'])
userlist.write( "%(username)s <%(email)s> \"%(homepage)s\" \"%(usertitle)s\" %(joindate)s %(lastvisit)s %(lastactivity)s %(lastpost)s\n" % user)
userdetails.write("""
************************************* %(userid)s *******************************
Username: %(username)s
email: %(email)s
birthday: %(birthday)s
Homepage: %(homepage)s
ICQ: %(icq)s
MSN: %(msn)s
AIM: %(aim)s
YAHOO: %(yahoo)s
usertitle: %(usertitle)s
customtitle: %(customtitle)s
Joined: %(joindate)s
Last Visit: %(lastvisit)s
Last Post: %(lastpost)s
Last Activity: %(lastpost)s
Number Posts: %(posts)s
""" % user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment