forked from d101tm/tmstats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistclubsbycity.py
More file actions
executable file
·242 lines (200 loc) · 7.81 KB
/
listclubsbycity.py
File metadata and controls
executable file
·242 lines (200 loc) · 7.81 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/env python3
""" Create the "Club Listing By City" as an includable HTML file.
Also create the CSS/JS and actual HTML as separate pieces for Joomla.
And create narrow versions to be phone-friendly. """
import sys, re, os
from simpleclub import Club
import tmparms, tmglobals
from tmutil import cleandate, overrideClubs, removeSuspendedClubs
from overridepositions import overrideClubPositions
import imp
myglobals = tmglobals.tmglobals()
# Create the templates
headinfo= {}
headinfo['style'] = """
table.clubtable {width: 100%; display: none; border-collapse: collapse;
border-left-style: hidden !important;
border-right-style: hidden !important;
}
.fullcity td {border: 0px solid white;}
.fullcity tr {border: 0px solid white;}
div.fullcity {padding-bottom: 3px;}
h3.cityname {font-weight: bold; font-size: 150%;}
h3.cityname:hover {background-color: #772432; color: white;}
col.c1 {width: 22%;}
col.c2 {width: 32%;}
col.c3 {width: 46%;}
td.clubname {padding-top: 6px; font-weight: bold; font-size: 125%;
color: #772432; border-top: 1px solid #ddd;}
td.tminfo {vertical-align: top; padding-right: 3px;
border-right: 1px solid #ddd;}
td.meeting {vertical-align: top; padding-right: 3px;
padding-left: 3px;
border-right: 1px solid #ddd;}
td.location {vertical-align: top; padding-left: 3px;}
div.locfirst {text-indent: -1em; padding-left: 1em;}
"""
header = """
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
jQ = jQuery.noConflict();
</script>
<style type="text/css">
%(style)s
</style>
</head>
</body>
""" % headinfo
footer = """
</body>
</html>
"""
citytemplate = """
<div class="fullcity" id="%(cityid)s">
<h3 class="cityname title pane-toggler" onclick='jQ ( "#%(cityid)sclubs, #%(cityid)sopen, #%(cityid)sclosed" ).toggle();'><span id="%(cityid)sopen" style="display:none;">▾</span><span id="%(cityid)sclosed">▸</span> %(cityname)s</h3>
<table class="clubtable" id="%(cityid)sclubs">
<colgroup>
<col class="c1"><col class="c2"><col class="c3">
</colgroup>
%(clubs)s
</table>
</div>"""
clubtemplate = """
<tr>
<td class="clubname" colspan="3">%(clubname)s</td>
</tr>
<tr>
<td colspan="3">%(restrict)s</td>
</tr>
<tr>
<td class="tminfo">%(tminfo)s</td>
<td class="meeting">%(meetingday)s %(meetingtime)s<br />%(lcontact)s</td>
<td class="location">%(location)s<br />%(city)s, %(state)s %(zip)s</td>
</tr>
"""
narrowcitytemplate = """
<div class="fullcity" id="n%(cityid)s">
<h3 class="cityname title pane-toggler" onclick='jQ ( "#n%(cityid)sclubs, #n%(cityid)sopen, #n%(cityid)sclosed" ).toggle();'><span id="n%(cityid)sopen" style="display:none;">▾</span><span id="n%(cityid)sclosed">▸</span>%(cityname)s</h3>
<table class="clubtable" id="n%(cityid)sclubs">
%(narrowclubs)s
</table>
</div>"""
narrowtemplate = """
<tr>
<td class="clubname">%(clubname)s</td>
</tr>
<tr><td>%(restrict)s<td></tr>
<tr><td>%(meetingday)s %(meetingtime)s</td></tr>
<tr><td class="location">%(location)s<br />%(city)s, %(state)s %(zip)s</td></tr>
<tr><td>%(stminfo)s</td></tr>
<tr><td>%(scontact)s</td></tr>
"""
# Helper functions
def normalize(s):
if s:
return re.sub('\W\W*', '', s).strip().lower()
else:
return ''
# Main program
# Handle parameters
parms = tmparms.tmparms()
parms.parser.add_argument("--date", dest='date', default='today')
parms.add_argument('--outdir', dest='outdir', default='${workdir}', help='Where to put the files created by this program.')
parms.add_argument('--newalignment', dest='newalignment', default=None, help='Overrides area/division data from the CLUBS table.')
parms.add_argument('--mapoverride', dest='mapoverride', default=None, help='Google spreadsheet with overriding address and coordinate information')
# Do global setup
myglobals.setup(parms)
conn = myglobals.conn
curs = myglobals.curs
parms.date = cleandate(parms.date)
# Promote information from parms.makemap if not already specified
parms.mapoverride = parms.mapoverride if parms.mapoverride else parms.makemap.get('mapoverride',None)
# Get the club information for the specified date
clubs = Club.getClubsOn(curs, parms.date)
# And remove suspended clubs.
clubs = removeSuspendedClubs(clubs, curs)
# And override it if needed.
if parms.newalignment:
overrideClubs(clubs, parms.newalignment, exclusive=False)
# If there are overrides to club positioning, handle them now
if parms.mapoverride:
overrideClubPositions(clubs, parms.mapoverride, parms.googlemapsapikey)
cities = {}
for c in clubs:
club = clubs[c]
club.city = club.city.title()
if club.city not in cities:
cities[club.city] = []
cities[club.city].append(club)
outfile = open(os.path.join(parms.outdir, 'clublist.html'),'w')
headfile = open(os.path.join(parms.outdir, 'clublist.css'),'w')
bodyfile = open(os.path.join(parms.outdir, 'clublist.body'),'w')
narrowfile = open(os.path.join(parms.outdir, 'narrowclublist.html'),'w')
narrowbodyfile = open(os.path.join(parms.outdir, 'narrowclublist.body'),'w')
headfile.write(headinfo['style'])
outfile.write(header)
narrowfile.write(header)
for city in sorted(cities.keys()):
info = {}
info['cityid']= normalize(city)
info['cityname'] = city
info['clubs'] = ''
allclubinfo = []
allnarrowinfo = []
cities[city].sort(key=lambda x:x.clubname.lower())
for club in cities[city]:
data = {}
data['clubname'] = club.clubname
data['tminfo'] = 'Club %s<br />Area %s%s<br />Charter: %s' % \
(club.clubnumber, club.division, club.area, club.charterdate)
data['stminfo'] = 'Club %s | Area %s%s | Charter: %s' % \
(club.clubnumber, club.division, club.area, club.charterdate)
if club.clubstatus.startswith('Open') or club.clubstatus.startswith('None'):
data['restrict'] = 'Club is open to all'
else:
data['restrict'] = 'Contact club about membership requirements'
if club.advanced == '1':
data['restrict'] += '; Club is an Advanced Club'
data['meetingday'] = club.meetingday.replace(' ',' ')
data['meetingtime'] = club.meetingtime.replace(' ',' ')
data['contact'] = []
if club.clubwebsite:
data['contact'].append('<a href="%s" target="_blank">Website</a>' % (club.clubwebsite))
if club.facebook:
data['contact'].append('<a href="%s" target="_blank">Facebook</a>' % (club.facebook))
if club.clubemail:
data['contact'].append('<a href="%s" target="_blank">Email</a>' % (club.clubemail))
if club.phone:
data['contact'].append('Phone: %s' % (club.phone))
data['lcontact'] = '<br />'.join(data['contact'])
data['scontact'] = ' | '.join(data['contact'])
address = club.place.split('\n')
address.append(club.address)
data['location'] = '<div class="locfirst">' + \
address[0] + \
'</div>' + \
('<br />'.join(address[1:]))
data['city'] = club.city
data['state'] = club.state
data['zip'] = club.zip
allclubinfo.append(clubtemplate % data)
allnarrowinfo.append(narrowtemplate % data)
info['clubs'] = '\n'.join(allclubinfo)
outfile.write(citytemplate % info)
outfile.write('\n')
bodyfile.write(citytemplate % info)
bodyfile.write('\n')
info['narrowclubs'] = '\n'.join(allnarrowinfo)
narrowfile.write(narrowcitytemplate % info)
narrowfile.write('\n')
narrowbodyfile.write(narrowcitytemplate % info)
narrowbodyfile.write('\n')
outfile.write(footer);
narrowfile.write(footer);
outfile.close()
bodyfile.close()
narrowfile.close()
narrowbodyfile.close()
headfile.close( )