-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnntp2mbox.py
executable file
·59 lines (38 loc) · 993 Bytes
/
nntp2mbox.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
import nntplib
import sys
import email
outfile = file(sys.argv[-1], 'a')
nntpconn = nntplib.NNTP('news.gmane.org')
resp, count, first, last, name = nntpconn.group(sys.argv[-1])
print 'Group', name, 'has', count, 'articles, range', first, 'to', last
last = int(last)
startnr = last - 500
if startnr < 1:
startnr = 1
try:
nofile = file(sys.argv[-1] + ".cfg", 'r')
startnr = int(nofile.readline())
nofile.close()
except IOError:
print 'No number file found, starting at ' + str(startnr)
if startnr < 1:
startnr = 1
if startnr < last:
last = last +1
for msgno in range( startnr, last ):
try:
resp, number, id, list = nntpconn.article(str(msgno))
text = str()
for line in list:
text += line + "\n"
msg = email.message_from_string(text)
outfile.write(str(msg))
outfile.write('\n')
print '%s(%s): %s' % (number, msgno, id)
except:
pass
outfile.close()
nofile = file(sys.argv[-1] + ".cfg", 'w')
nofile.write(str(last))
nofile.close()