Skip to content

Commit 2568a89

Browse files
committed
copy of webnews archive from Starship Python
0 parents  commit 2568a89

7 files changed

+598
-0
lines changed

.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# compiled python
2+
*.py[co]
3+
build
4+
build-stamp
5+
# editor debris
6+
*~
7+
.#*
8+
._*
9+
.*.sw?
10+
# OS debris
11+
.DS_Store
12+
# ignore temp/state files
13+
.netrwhist
14+
#
15+
node_modules
16+
# don't include the sag couch library
17+
sag*
18+
# don't include the configuration file
19+
options.json
20+
tools/docopt
21+

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 1995-1997 Jim Tittsler http://tittsler.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# webnews - a web-based newsreader
2+
3+
Some of the members of the
4+
[Tokyo PC Users Group](http://tokyopc.org/) complained
5+
that they couldn't access our local
6+
[newsgroups](http://tokyopc.org/tpc/newsgroups.html)
7+
through their firewall, so I put together a
8+
[PCGI](http://starship.python.net/crew/jbauer/persistcgi/index.html)
9+
program that queries the NNTP server and builds
10+
[simple HTML pages](<http://www.tokyopc.org/cgi-bin/webnews/newsgroup?G=tpc.list)
11+
on the fly.
12+
13+
## License: MIT

backupfile.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
3+
def backupfile(filename, extension=".bak"):
4+
""" create a backupfile, returning (fin, fout) renaming original """
5+
6+
backname = filename+extension
7+
8+
try:
9+
os.remove(backname)
10+
except:
11+
pass # maybe nothing to delete
12+
13+
os.rename(filename, backname)
14+
15+
try:
16+
fin = open(backname, "r")
17+
except:
18+
print "Unable to open input file: %s" % backname
19+
20+
try:
21+
fout = open(filename, "w")
22+
except:
23+
print "Unable to create output file: %s" % filename
24+
25+
return (fin, fout)

ngupdate

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#! /usr/bin/python
2+
# -*- python -*-
3+
# $Id: ngupdate,v 1.3 1998/04/10 08:06:55 tpc Exp tpc $
4+
#
5+
# 1997.11.21 [email protected] add Expires header to newsgroups.html
6+
# 1997.11.20 [email protected] update newsgroups.html to show activity
7+
# 1998.04.02 [email protected] fix row matching regex so that it finds rows
8+
# with <FONT></FONT> in them
9+
10+
import sys, os, string, time, cgi, regex
11+
from nntplib import NNTP
12+
from time import ctime, time, localtime, strftime, asctime, gmtime
13+
from backupfile import backupfile
14+
15+
# number of seconds until the HTML page 'expires'
16+
valid_secs = 60*60*12 # 12 hours
17+
18+
# news server authentication
19+
user = 'account'
20+
password = 'password'
21+
22+
NEWS_SERVER = 'news.tpc.ml.org'
23+
#NEWS_SERVER = 'pengu.mww.dyn.ml.org'
24+
filenames = ('/home/tpc/www/tpc/newsgroups.html',
25+
'/home/tpc/www/member/newsgroups.html',
26+
'/home/tpc/www/exec/newsgroups.html')
27+
#filename = '/home/jwt/newsgroups.html'
28+
29+
def do_update(filename):
30+
try:
31+
news = NNTP(NEWS_SERVER)
32+
except:
33+
print "Can not open news server:", NEWS_SERVER
34+
raise SystemExit
35+
36+
try:
37+
resp = news.shortcmd('MODE READER')
38+
except:
39+
print "Can not communicate with server:", NEWS_SERVER
40+
raise SystemExit
41+
42+
resp = news.shortcmd('authinfo user '+user)
43+
if resp[:3] != '381':
44+
raise SystemExit
45+
resp = news.shortcmd('authinfo pass '+password)
46+
if resp[:3] != '281':
47+
raise SystemExit
48+
49+
(fin, fout) = backupfile(filename)
50+
51+
nowsecs = time()
52+
newstime = strftime("%H%M%S", localtime(nowsecs))
53+
datem1 = strftime("%y%m%d", localtime(nowsecs - (60*60*24)))
54+
datem7 = strftime("%y%m%d", localtime(nowsecs - (60*60*24*7)))
55+
datem21 = strftime("%y%m%d", localtime(nowsecs - (60*60*24*21)))
56+
57+
# copy the page up to the table comment
58+
while 1:
59+
line = fin.readline()
60+
if line == '': break
61+
if string.find(line, 'HTTP-EQUIV="Expires"') >= 0:
62+
fout.write('<META HTTP-EQUIV="Expires" CONTENT="%s"\n' % asctime(gmtime(nowsecs + valid_secs)))
63+
else:
64+
fout.write(line)
65+
if string.find(line, "##newsgroups table") >= 0: break
66+
67+
row = regex.symcomp('<TR><TD>.*</TD>\(<lead><TD>[^:]*://news.tpc.ml.org/\)\(<newsgroup>[^"]+\)\(<rest>.*\)')
68+
69+
while 1:
70+
line = fin.readline()
71+
if line == '': break
72+
if string.find(line, "</TABLE>") >= 0:
73+
break
74+
75+
if row.search(line) >= 0:
76+
newsgroup = row.group('newsgroup')
77+
idsm1 = 0
78+
idsm7 = 0
79+
idsm21 = 0
80+
try:
81+
resp, idsm1 = news.newnews(newsgroup, datem1, newstime)
82+
resp, idsm7 = news.newnews(newsgroup, datem7, newstime)
83+
resp, idsm21 = news.newnews(newsgroup, datem21, newstime)
84+
except:
85+
print "no such newsgroup:", newsgroup
86+
87+
fontm1 = ""
88+
fontm1e = ""
89+
fontm7 = ""
90+
fontm7e = ""
91+
if len(idsm1)>3:
92+
fontm1 = '<FONT COLOR="#FF0000">'
93+
fontm1e = '</FONT>'
94+
if len(idsm7)>10:
95+
fontm7 = '<FONT COLOR="#800000">'
96+
fontm7e = '</FONT>'
97+
line = "<TR><TD>%s%d%s/%s%d%s/%d</TD>%s%s%s\n" % (fontm1, len(idsm1), fontm1e, fontm7, len(idsm7), fontm7e, len(idsm21), row.group('lead'), newsgroup, row.group('rest'))
98+
fout.write(line)
99+
100+
# close the table and indicate update time
101+
fout.write("</TABLE><P>Last updated: %s</P>\n" % ctime(time()))
102+
103+
while 1:
104+
line = fin.readline()
105+
if line == '': break
106+
fout.write(line)
107+
108+
fin.close()
109+
fout.close()
110+
111+
for filename in filenames:
112+
do_update(filename)
113+

0 commit comments

Comments
 (0)