-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdumpforums.py
More file actions
54 lines (50 loc) · 1.91 KB
/
dumpforums.py
File metadata and controls
54 lines (50 loc) · 1.91 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
import jsonrpc
import socket
import random
import json
import sys
print "dumping subscribed forums... please wait!"
#rpc = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportSocket(addr="/tmp/testservice", sock_type=socket.AF_UNIX))
rpc = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportSocket(addr=("127.0.0.1",11111)))
print "loading forums..."
forums = rpc.bridge.getForums()
print "loading keyring..."
gpgIdList = rpc.bridge.getGPGAllList()
print "gen name hash..."
gpgIds = {}
for i in gpgIdList:
n = rpc.bridge.getPeerName(i)
#print n
gpgIds[i]=n
print "writing forums list..."
with open('../jout/forums.json', 'w') as ffile:
ffile.write(json.dumps(forums))
def dumpMsg(forumID,msgID):
#print msgID
msg = rpc.bridge.getForumMessage(forumID,msgID)
#sys.stdout.write(' '+msg['srcId']+': ')
if msg['srcId'] != '':
if msg['srcId'] in gpgIds:
msg['srcId'] = gpgIds[msg['srcId']]
else:
msg['srcId'] = "KeyHidden"
#sys.stdout.write(msg['srcId']+' ')
with open("../jout/msg"+msgID+".json", 'w') as ffile:
ffile.write(json.dumps(msg))
msgheaders = rpc.bridge.getForumThreadMsgList(forumID,msgID)
with open("../jout/thread"+msgID+".json", 'w') as ffile:
ffile.write(json.dumps(msgheaders))
for msgh in msgheaders:
dumpMsg(forumID, msgh['msgId'])
print "writing forums..."
for f in forums:
if f['forumRelationship'] == "SUBSCRIBED":
print "dumping " + f['forumId']
threadlist = rpc.bridge.getForumThreadList(f['forumId'])
with open("../jout/forum"+f['forumId']+".json", 'w') as ffile:
ffile.write(json.dumps(threadlist))
for tm in threadlist:
#print tm
dumpMsg(f['forumId'], tm['msgId'])
print "done dumping forum messages"