-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb2sheet_xls.py
executable file
·348 lines (322 loc) · 11.3 KB
/
web2sheet_xls.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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/env python
import sys
import urllib2
import json
import re
import HTMLParser
from natsort import natsorted
import xlsxwriter, xlrd
import argparse
name_spr = 'GeniusPlaza Learning Objects'
filter = {
'type': 'all',
'domain': 'all',
'standard': 'all',
'language': 'all',
'subject': 'all',
}
fields = [ 'Search Grade/Subjects', 'Search Domain',
'Grade',
'Standard index',
'Language',
'Resource type', 'Resource name', 'Resource URL' ]
search = { 'PreK Math':
[ '1',
{ 'All Domains': 'all'}
],
'PreK ELA':
[ '2',
{ 'L.PK - Language': '85' }
],
'PreK Social Studies':
[ '122',
{ 'All Domains': 'all' }
],
'PreK Spanish':
[ '39',
{ 'All Domains': 'all' }
],
'K Math':
[ '6',
{ 'All Domains': 'all' }
],
'K ELA':
[ '7',
{ 'L.K - Language': '33',
'RL.K - Reading Literature': '92',
'RI.K - Reading Informational Text': '93',
'RF.K - Reading Foundational Skills': '178' }
],
'1st Grade Math':
[ '12',
{ '1.OA - Operations and algebraic thinking': '10',
'1.NBT - Number and operations in base ten': '11',
'1.MD - Measurements and data': '12',
'1.G - Geometry': '13' }
],
'1st Grade ELA':
[ '13',
{ 'L.1 - Language': '41',
'RL.1 - Reading Literature': '91',
'RI.1 - Reading Informational Text': '90',
'RF.1 - Reading Foundational Skills': '179' }
],
'2nd Grade Math':
[ '18',
{ '2.OA - Operations and algebraic thinking': '14',
'2.NBT - Number and operations in base ten': '15',
'2.MD - Measurements and data': '16',
'2.G - Geometry': '17' }
],
'2nd Grade ELA':
[ '19',
{ 'L.2 - Language': '42',
'RL.2 - Reading Literature': '88',
'RI.2 - Reading Informational Text': '89',
'RF.2 - Reading Foundational Skills': '180' }
],
'3rd Grade Math':
[ '24',
{ '3.OA - Operations and algebraic thinking': '18',
'3.NBT - Number and operations in base ten': '19',
'3.NF - Number and operations - Fractions': '20',
'3.MD - Measurements and data': '21',
'3.G - Geometry': '22',
'P - Parenting': '125' }
],
'3rd Grade ELA':
[ '25',
{ 'L.3 - Language': '43',
'RL.3 - Reading Literature': '53',
'RI.3 - Reading Informational Text': '62' }
],
'4th Grade Math':
[ '30',
{ '4.OA - Operations and algebraic thinking': '23',
'4.NBT - Number and operations in base ten': '24',
'4.NF - Number and operations - Fractions': '25',
'4.MD - Measurements and data': '26',
'4.G - Geometry': '27' }
],
'4th Grade ELA':
[ '31',
{ 'L.4 - Language': '44',
'RL.4 - Reading Literature': '86',
'RI.4 - Reading Informational Text': '87' }
],
'4th Grade Science':
[ '73',
{ 'All Domains': 'all' }
],
'5th Grade Math':
[ '36',
{ '5.OA - Operations and algebraic thinking': '28',
'5.NBT - Number and operations in base ten': '29',
'5.NF - Number and operations - Fractions': '30',
'5.MD - Measurements and data': '31',
'5.G - Geometry': '32' }
],
'5th Grade ELA':
[ '37',
{ 'L.5 - Language': '45',
'RL.5 - Reading Literature': '61',
'RI.5 - Reading Informational Text': '63' }
],
'5th Grade Science':
[ '74',
{ 'All Domains': 'all' }
],
'Primary School Spanish':
[ '38',
{ 'All Domains': 'all' }
],
'6th Grade Math':
[ '44',
{ 'All Domains': 'all' }
],
'6th Grade ELA':
[ '43',
{ 'L.6 - Language': '95',
'RL.6 - Reading Literature': '118',
'RI.6 - Reading Informational Text': '119' }
],
'7th Grade Math':
[ '46',
{ 'All Domains': 'all' }
],
'7th Grade ELA':
[ '45',
{ 'L.7 - Language': '116',
'RL.7 - Reading Literature': '120',
'RI.7 - Reading Informational Text': '121' }
],
'8th Grade Math':
[ '48',
{ 'All Domains': 'all' }
],
'8th Grade ELA':
[ '47',
{ 'L.8 - Language': '114',
'RL.8 - Reading Literature': '122',
'RI.8 - Reading Informational Text': '123' }
],
'Middle School Spanish':
[ '40',
{ 'All Domains': 'all' }
],
'9th Grade Math':
[ '64',
{ 'All Domains': 'all' }
],
'9th Grade ELA':
[ '49',
{ 'L.9-10 - Language': '115',
'RL.9-10 - Reading Literature': '136',
'RI.9-10 - Reading Informational Text': '132' }
],
'10th Grade Math':
[ '65',
{ 'All Domains': 'all' }
],
'10th Grade ELA':
[ '51',
{ 'L.9-10 - Language': '129',
'RL.9-10 - Reading Literature': '137',
'RI.9-10 - Reading Informational Text': '133' }
],
'11th Grade ELA':
[ '53',
{ 'L.11-12 - Language': '130',
'RL.11-12 - Reading Literature': '138',
'RI.11-12 - Reading Informational Text': '134' }
],
'12th Grade ELA':
[ '55',
{ 'L.11-12 - Language': '131',
'RL.11-12 - Reading Literature': '139',
'RI.11-12 - Reading Informational Text': '135' }
],
'High School Algebra':
[ '59',
{ 'All Domains': 'all' }
],
'High School Geometry':
[ '62',
{ 'All Domains': 'all' }
],
'High School Functions':
[ '60',
{ 'All Domains': 'all' }
],
'High School Statistics and Probability':
[ '63',
{ 'All Domains': 'all' }
],
'High School Spanish':
[ '41',
{ 'All Domains': 'all' }
],
'High School Number and Quantity':
[ '58',
{ 'All Domains': 'all' }
],
'Parent - Computer Skills':
[ '119',
{ 'All Domains': 'all' }
],
'Parenting':
[ '116',
{ 'All Domains': 'all' }
],
'Parent - US Citizenship':
[ '118',
{ 'All Domains': 'all' }
],
'Administrator - Professional Development':
[ '125',
{ 'All Domains': 'all' }
],
'Teacher - Professional Development':
[ '126',
{ 'All Domains': 'all' }
],
'Teacher - Resources':
[ '127',
{ 'All Domains': 'all' }
]
}
# URLs of previously existing learning objects
previous = []
def geniusplaza_get (grade, domains):
results = []
filter['n'] = 1
filter['subject'] = search[grade][0]
for domain in natsorted(domains):
filter['domain'] = domains[domain]
str = urllib2.urlopen("https://www.geniusplaza.com/bank_educators/get_ajax?sEcho=2&iColumns=1&sColumns=&iDisplayStart=0&iDisplayLength={n}&mDataProp_0=0&a=get_page&keyword=undefined&type={type}&domain={domain}&standard={standard}&language={language}&subject={subject}&assign=all".format(**filter)).read()
data=json.JSONDecoder().decode(str)
filter['n'] = int(data['iTotalRecords'])
print "Grade %s, domain %s : %d objects" % (grade, domain, filter['n'])
str = urllib2.urlopen("https://www.geniusplaza.com/bank_educators/get_ajax?sEcho=2&iColumns=6&sColumns=&iDisplayStart=0&iDisplayLength={n}&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&mDataProp_5=5&a=get_page&keyword=undefined&type={type}&domain={domain}&standard={standard}&language={language}&subject={subject}&assign=all".format(**filter)).read()
data = json.JSONDecoder().decode(str)
objs = data['aaData']
html = HTMLParser.HTMLParser()
for e in objs:
for fld in fields:
e[fld] = ''
e['Search Grade/Subjects'] = grade
e['Search Domain'] = domain
e['Standard index'] = e['3'].split(' ', 1)[0]
e['Resource name'] = html.unescape(re.sub('<.*?>', '', e['1']))
e['Grade'] = html.unescape(re.sub('<.*?>', '', e['2']))
e['Language'] = html.unescape(e['4'])
e['Resource type'] = html.unescape(e['5'])
m = re.match('.*<a href="(.*)" target="_blank">.*', e['1'])
e['Resource URL'] = m.groups()[0]
results.extend(objs)
print ' ...processed'
return results
def gspread_update_grade (ws, row, objs):
# authorise gspread
ignored = 0
for j in range(len(objs)):
e = objs[j]
if e['Resource URL'] in previous:
ignored += 1
continue
for i in range(len(fields)):
ws.write(row, i, e[fields[i]])
row += 1
print " ...done, ignored %d previous objects" % (ignored)
def main(argv):
parser = argparse.ArgumentParser(description='Extract learning objects from GeniusPlaza.')
parser.add_argument('--diff', help="difference with previous excel file", action="append")
args = parser.parse_args()
for f in args.diff:
try:
nprev = 0
prev_wb = xlrd.open_workbook(f)
for s in prev_wb.sheets():
for row in range(1, s.nrows):
for col in range(s.ncols):
if s.cell(0, col).value == 'Resource URL':
url = s.cell(row, col).value.replace("www.prek12plaza.com","www.geniusplaza.com")
previous.append(url)
nprev += 1
print "Added %d previous learning objects from %s" % (nprev, f)
except:
pass
# Create an new Excel file and add a worksheet.
wb = xlsxwriter.Workbook(name_spr + '.xlsx')
for grade in natsorted(search):
# select worksheet
ws = wb.add_worksheet(grade[:30])
for i in range(len(fields)):
ws.write(0, i, fields[i])
domains = search[grade][1]
objs = geniusplaza_get (grade, domains)
gspread_update_grade (ws, 1, objs)
#row += len(objs)
wb.close()
if __name__ == '__main__':
main(sys.argv)