-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.cgi
executable file
·151 lines (124 loc) · 4.72 KB
/
index.cgi
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/python -S
# Main index page for the Kingman internal website.
# By Ka-Ping Yee <[email protected]>, a Kingmanite from 2000 to 2008.
from utils import *
from fastcgi import os, client, request, form
import random
past_events = 12
future_events = 18
max_events = 24
max_notes = 36
prologue('Castro Internal', 'style.css')
borkify = not random.randrange(100)
borkify = 0
if borkify and not form.preview:
# Replace the existing "write" routine with one that sends all text
# through a Swedish Chef filter.
chef = os.popen2("./chef")
def write(*stuff):
chef[0].write(flatten(stuff))
import utils
utils.write = write
# Status bar.
last_toner_record = (get_toner_records(1).values() or [{}])[0]
write_template('status.html',
dns=read_file('/tmp/status.dns'),
printer=read_file('/tmp/status.printer'),
toner=last_toner_record.get('black_cartridge', '') or '?',
half_fish=read_file('/tmp/status.half-fish'),
jukebox=read_file('/tmp/status.jukebox'),
dsl=read_file('/tmp/status.dsl'))
# Links section.
voc_members = {}
for line in read_lines('voc-members.txt'):
voc_members[line.strip()] = 1
if 'comment-only' in voc_members:
del voc_members['comment-only']
voc_done = len(voc_members)
voc_needed = int((50 + 9) * 0.9 + 0.999)
quotients, counts = get_hotness('do', {'m': 35, 'f': 32})
hq = percentage(quotients[('any', 'any')])
fhq = percentage(quotients[('any', 'f')])
mhq = percentage(quotients[('any', 'm')])
import utils
utils.wiki = Wiki('kwiki-data')
utils.wikiurl = request.rsplit('/', 1)[0] + '/kwiki.cgi'
date, meta, body = utils.wiki.get_page('front_page_links')
write_template('links.html',
front_page_links=format_text(body),
voc_count=voc_done,
voc_percent='%.1f' % (voc_done/59.0),
hotness_quotient=hq)
# Announcement.
announcement = read_file('announcement.txt')
if announcement.strip():
write(div(announcement, c='announcement'))
# Event listing and message board.
events = get_events()
events.sort()
today = get_date()
first, last = 0, len(events)
for i in range(len(events)):
date, title, details = events[i]
if date < today:
first = i
if date > today:
last = i
break
nearby = events[max(first - past_events, 0):
min(last + future_events, len(events))][-max_events:]
event_rows = map(format_event, reversed(nearby))
see_all = link('events.cgi', '(see all %d events)' % len(events))
event_rows.append(tr(td(see_all, colspan=2)))
upcoming_rows = map(format_event, [e for e in nearby if e[0] >= today])
recent_rows = map(format_event, reversed([e for e in nearby if e[0] < today]))
recent_rows.append(tr(td(see_all, colspan=2)))
today = [(date, t, d) for (date, t, d) in events if date == today]
today_rows = map(format_event, today)
today_section = [div(h2('Today'), c='heading'),
div(table(today_rows), c='today content')]
if not today_rows:
today_section = []
notes = get_notes()
notes.reverse()
note_rows = map(format_note, notes[:max_notes])
see_all = link('notes.cgi', '(see all %d notes)' % len(notes))
note_rows.append(tr(td(see_all, colspan=2)))
def sel_option(text, value, current):
sel = [None, 'selected'][str(value) == str(current)]
return option(text, value=value, selected=sel)
# Show only the next six months as options.
month_options = [sel_option('month', '', form.month)]
y, l = time.localtime()[:2]
suffix = ''
for i in range(6):
text = monthnames[l][:3] + suffix
month_options.append(sel_option(text, '%04d-%02d' % (y, l), form.month))
l += 1
if l > 12:
y, l = y + 1, 1
suffix = ' %d' % y # indicate year rollover
day_options = [sel_option('day', '', form.day)
] + [sel_option(i, i, form.day) for i in range(1, 32)]
event_preview = ''
if form.preview and form.title:
date = parse_date(form.month + '-' + form.day)
event_preview = table(format_event((date, form.title, form.details)))
note_preview = ''
if form.preview and form.name:
y, l, d, h, m, s = time.localtime()[:6]
note_preview = table(format_note(
(Date(y, l, d), '%02d:%02d' % (h, m), form.name, form.note)))
write_template('events-notes.html', today=today_section,
upcoming=table(upcoming_rows), recent=table(recent_rows),
events=table(event_rows), notes=table(note_rows),
month_options=month_options, day_options=day_options,
title=esc(form.title), details=esc(form.details),
name=esc(form.name), note=esc(form.note),
event_preview=event_preview, note_preview=note_preview)
try:
epilogue()
except SystemExit:
if borkify:
chef[0].close()
print chef[1].read()