-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsiteutils.py
727 lines (634 loc) · 23.2 KB
/
siteutils.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
import logging
import os
import hashlib
import psycopg2
import psycopg2.extras
from flask import g
import json
import random
import string
from email.message import Message
import email.utils
import smtplib
import statistics
import collections
import math
import model
import tempfile
import csv
import zipfile
cwd = os.path.dirname(os.path.realpath(__file__))
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler(cwd + '/logs/logs.log')
formatter = logging.Formatter(
'%(asctime)s - %(name)s, %(lineno)s - %(levelname)s - %(message)s',
datefmt='%m/%d %H:%M:%S'
)
fh.setFormatter(formatter)
logger.addHandler(fh)
def addnewuser(request):
"""Process form from create new user page.
Update table users with form data and md5 hash for password.
If sql fails due to key constraints return appropriate error msg.
"""
logger.debug(request)
username = request.get('UserName').strip()
firstname = request.get('FirstName', 'john').strip()
lastname = request.get('LastName', 'doe').strip()
affil = request.get('Affil', 'self').strip()
email = request.get('Email').strip()
passwd = request.get('Password').strip()
digest = hashlib.md5()
digest.update(passwd)
hash_passwd = digest.hexdigest()
query = """insert into users(firstname, lastname, affiliate, username,
email, password, dateadded) values (%s, %s, %s, %s, %s, %s,
CURRENT_DATE)"""
errormsg1 = """You have already registered with this email.
If you don't recall your username and password you can
request a reset on the login tab of the app."""
errormsg2 = """This username is already in use. Please try to register
again with a different username. """
errormsg3 = """Registration error. """
successmsg = """Registration completed. You can now login
with your username and password on the login tab of the app."""
if(len(passwd) < 6 or len(username) < 2 or len(email) < 5):
return errormsg3
try:
with g.db.cursor() as cur:
cur.execute(
query, (
firstname, lastname, affil, username, email, hash_passwd
)
)
g.db.commit()
except psycopg2.IntegrityError as e:
if "users_email_key" in str(e.args):
return errormsg1
elif "users_username_key" in str(e.args):
return errormsg2
return successmsg
def userauth(request):
logger.debug(request)
username = request.get('loginUsername').strip()
passwd = request.get('loginPassword').strip()
digest = hashlib.md5()
digest.update(passwd)
hash_passwd = digest.hexdigest()
query = """select * from users where username = %s
and password = %s"""
with g.db.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
try:
cur.execute(query, (username, hash_passwd))
except Exception, e:
logger.debug(e.pgerror)
rec = cur.fetchone()
try:
return json.dumps({
'success': True,
'username': rec['username'].strip(),
'firstname': rec['firstname'].strip()
})
except TypeError:
return json.dumps({'success': False})
def passwdreset(emailaddr):
query = """select * from users where email = %s """
with g.db.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute(query, (emailaddr,))
logger.debug(cur.rowcount)
if cur.rowcount == 0:
return json.dumps({
'success': True,
'msg': "This email has not registered."
})
rec = cur.fetchone()
pk = rec['pk']
chars = string.ascii_letters + string.digits
pwd = ''.join(random.choice(chars) for i in range(8))
digest = hashlib.md5()
digest.update(pwd)
hash_passwd = digest.hexdigest()
logger.debug(pwd)
query = """update users set password = %s where pk = %s"""
with g.db.cursor() as cur:
cur.execute(query, (hash_passwd, pk))
g.db.commit()
message = """
You have requested a password reset for \
login to the NC threats \
analysis web site.
Username: %s
Password: %s
""" % (rec['username'], pwd)
msg = Message()
msg['To'] = emailaddr
msg['From'] = '[email protected]'
msg['Subject'] = 'Requested password reset'
msg['Date'] = email.utils.formatdate(localtime=1)
msg['Message-ID'] = email.utils.make_msgid()
msg.set_payload(message)
s = smtplib.SMTP('127.0.0.1')
s.sendmail('[email protected]', emailaddr, msg.as_string())
return json.dumps({
'success': True,
'username': rec['username'],
'pass': pwd,
'msg': "Check your email."
})
def userpage(username):
query = """select * from usersaoi where username = %s """
results = []
with g.db.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute(query, (username,))
for rec in cur:
results.append({'aoiid': rec['aoiid'], 'aoidesc': rec['aoidesc']})
return {'username': username, 'results': results}
def passwdchng(username, passwd):
if len(passwd) < 6:
return json.dumps({'success': False})
digest = hashlib.md5()
digest.update(passwd)
hash_passwd = digest.hexdigest()
query = """update users set password = %s where username = %s"""
with g.db.cursor() as cur:
cur.execute(query, (hash_passwd, username))
if cur.rowcount == 1:
g.db.commit()
return json.dumps({'success': True})
else:
g.db.rollback()
return json.dumps({'success': False})
def qrypttojson(lon, lat, lyr):
"""select huc6 from huc6nc where ST_Contains(wkb_geometry,
ST_Transform(ST_SetSRID(ST_Point(-9108450, 4230555),900913),4326)); """
qry_col = lyr
if lyr not in [
'huc2', 'huc4', 'huc6', 'huc8', 'huc10', 'huc_12', 'co_num', 'bcr'
]:
logger.info('invalid layer name')
return
if lyr in ['huc2', 'huc4', 'huc6', 'huc8', 'huc10']:
qry_tbl = lyr + "nc"
elif lyr == 'huc_12':
qry_tbl = 'huc12nc'
elif lyr == 'co_num':
qry_tbl = 'counties'
elif lyr == 'bcr':
qry_tbl = 'nc_bcr'
query = "select ST_AsGeoJSON(wkb_geometry, 6), "
query += qry_col + " from " + qry_tbl
query += " where ST_Contains(wkb_geometry, "
query += "ST_Transform(ST_SetSRID(ST_Point(%s, %s),900913),4326)) "
logger.debug(query % (lon, lat))
with g.db.cursor() as cur:
cur.execute(query, (lon, lat))
res = cur.fetchone()
the_geom = json.loads(res[0])
the_huc = str(res[1])
logger.debug(the_geom['type'])
# logger.debug(the_geom)
geojson_obj = {
"type": "Feature",
"geometry": {
"type": the_geom['type'],
"coordinates": the_geom['coordinates']
},
"properties": {
"name": the_huc
}
}
ret_dict = {
"the_geom": geojson_obj,
"the_huc": the_huc
}
# logger.debug(ret_dict)
return json.dumps(ret_dict)
def qryptbufferjson(lon, lat, ptradius):
"""
select ST_AsGeoJSON(ST_Transform(ST_Buffer(ST_Transform(
ST_SetSRID(ST_Point(-78.867, 35.968),4326), 32119), 3000), 4326))
"""
query = "select ST_AsGeoJSON(ST_Transform(ST_Buffer(ST_Transform("
query += "ST_SetSRID(ST_Point(%s, %s),4326), 32119), %s)"
query += ", 4326))"
logger.debug(lon)
logger.debug(lat)
buffmeters = 1000 * float(ptradius)
# logger.debug(query % (lon, lat, buffmeters))
with g.db.cursor() as cur:
cur.execute(query, (lon, lat, buffmeters))
res = cur.fetchone()
the_geom = json.loads(res[0])
geojson_obj = {
"type": "Feature",
"geometry": {
"type": the_geom['type'],
"coordinates": the_geom['coordinates']
}
}
ret_dict = {
"the_geom": geojson_obj
}
logger.debug(ret_dict)
return json.dumps(ret_dict)
def make_composite_threat_count(hucs_dict, hucs_dict_ps, model_length):
"""
Function creates report for composite threat count. Also
adds Threat Count column to hucs_dict_ps.
"""
threat_count = []
for huc in hucs_dict:
threat = 0
# threat_rnk = 0
for idx in range(model_length):
# logger.debug(idx)
try:
threat += float(hucs_dict[huc][idx + 1])
# threat_rnk += float(hucs_dict_ps[huc][idx + 1])
except IndexError:
logger.debug(huc)
logger.debug(idx)
threat_raw = threat
# hucs_dict[huc].append(threat_raw)
hucs_dict_ps[huc].append(int(threat_raw))
# threat_rank.append(float(threat_rnk) / (idx + 1))
threat_count.append(threat)
# calculate composite thrts
thrt_counts_summary = []
thrt_counts_summary.append("Composite Threat Count")
mean = statistics.mean(threat_count)
thrt_counts_summary.append(int(mean * 100) / 100.0)
try:
stdev = statistics.stdev(threat_count)
thrt_counts_summary.append(int(stdev * 10000) / 10000.0)
except statistics.StatisticsError:
thrt_counts_summary.append('na')
thrt_counts_summary.append(min(threat_count))
thrt_counts_summary.append(max(threat_count))
# logger.debug(thrt_counts_summary)
return {
"thrt_counts_summary": thrt_counts_summary
}
def make_report_threats_summary(
model_cols, hucs_dict, rank_data, dt_data
):
"""
model_cols -list of column headers for AOI Threat Summary by HUC12
hucs_dict -dict of huc12 - list with first item huc and rest threats 0/1
rank_data -dict of threat name, eg firesup - list of threats ps percents
dt_data - same as rank_data but for dt as opposed to sv
returns:
report_rank - occurence and severity stats per threat
occurences - used to calculate Occurrence Rating
num_threats - total number present
thrts_included_msg - Distinct Threat Count text
"""
summary_params_list = collections.OrderedDict()
for idx, model_col in enumerate(model_cols):
if idx != 0:
summary_params_list[model_col] = [
hucs_dict[x][idx] for x in hucs_dict
]
# logger.debug(summary_params_list)
report = []
report_rank = []
# for row in summary_params_list:
# report_row = [str(row)]
# mean = statistics.mean(summary_params_list[row])
# report_row.append(int(mean * 100) / 100.0)
# try:
# stdev = statistics.stdev(summary_params_list[row])
# report_row.append(int(stdev * 10000) / 10000.0)
# except statistics.StatisticsError:
# report_row.append('na')
# row_min = min(summary_params_list[row])
# report_row.append(row_min)
# row_max = max(summary_params_list[row])
# report_row.append(row_max)
# logger.debug(report_row)
# report.append(report_row)
dt_labels = {
"frst": "% lost since 2000",
"ftwt": "% lost since 2000",
"hbwt": "% lost since 2000",
"open": "% lost since 2000",
"shrb": "% lost since 2000",
"urbangrth": "% area",
"firesup": "urban density",
"hiway": "meters/hectares",
"slr_up": "% lost since 2000",
"slr_lc": "% lost since 2000",
"triassic": "% area",
"wind": "wind power class",
"manure": "kg/ha/yr",
"nitrofrt": "kg/ha/yr",
"totnitro": "kg/ha/yr",
"totsulf": "kg/ha/yr",
"insectdisease": "% area impacted",
"ndams": "n",
"impairbiota": "km*stream density",
"impairmetal": "km*stream density"
}
# if formvals['mode'] != 'single':
thrts_present = 0
occurences = []
severity = []
for i, threat in enumerate(rank_data):
# logger.debug(threat)
# logger.debug(model_cols[i + 1])
report_row = [model_cols[i + 1]]
cnts = summary_params_list[model_cols[i + 1]]
mean = statistics.mean(cnts)
# logger.debug(mean)
if mean > 0:
thrts_present += 1
occurences.append(mean)
report_row.append(math.ceil(mean * 100) / 100.0)
mean = statistics.mean(rank_data[threat])
severity.append(mean)
report_row.append(int(mean * 100) / 100.0)
try:
stdev = statistics.stdev(rank_data[threat])
report_row.append(int(stdev * 10000) / 10000.0)
except statistics.StatisticsError:
report_row.append('na')
row_min = min(rank_data[threat])
report_row.append(row_min)
row_max = max(rank_data[threat])
# if row_max > 0:
# thrts_present += 1
report_row.append(row_max)
try:
dt_mean = statistics.mean(dt_data[threat])
dt_text = str(int(dt_mean * 100) / 100.0) + " " + dt_labels[threat]
report_row.append(dt_text)
except KeyError:
logger.debug(threat)
report_row.append('-')
# add row to report
report_rank.append(report_row)
num_threats = i + 1
thrts_included_msg = "%d of %d " % (thrts_present, num_threats)
# logger.debug(num_threats)
return {
"report_rank": report_rank,
"num_threats": num_threats,
"occurences": occurences,
"thrts_included_msg": thrts_included_msg
}
def aoi_spreadsheet(id, query):
pass
logger.debug("aoi_spreadsheet")
if id == 0:
report_results = model.get_threat_report2(id, query)
report_results['samplesize'] = len(report_results['res_arr'])
del(report_results["res_arr"])
a = report_results["thrts_included_msg"].split("of")
report_results["thrts_included_msg"] = a
results_complete = {
"state": report_results
}
# return json.dumps(report_results, indent=4)
else:
results_state = model.get_threat_report2(id, query)
results_aoi = model.get_threat_report2(id, query, 'aoi')
results_5k = model.get_threat_report2(id, query, '5k')
results_12k = model.get_threat_report2(id, query, '12k')
results_state['samplesize'] = len(results_state['res_arr'])
del(results_state["res_arr"])
a = results_state["thrts_included_msg"].split("of")
results_state["thrts_included_msg"] = a
results_aoi['samplesize'] = len(results_aoi['res_arr'])
del(results_aoi["res_arr"])
a = results_aoi["thrts_included_msg"].split("of")
results_aoi["thrts_included_msg"] = a
results_5k['samplesize'] = len(results_5k['res_arr'])
del(results_5k["res_arr"])
a = results_5k["thrts_included_msg"].split("of")
results_5k["thrts_included_msg"] = a
results_12k['samplesize'] = len(results_12k['res_arr'])
del(results_12k["res_arr"])
a = results_12k["thrts_included_msg"].split("of")
results_12k["thrts_included_msg"] = a
results_complete = collections.OrderedDict([
("aoi", results_aoi),
("5k", results_5k),
("12k", results_12k),
("state", results_state)
])
# {
# "state": results_state,
# "aoi": results_aoi,
# "5k": results_5k,
# "12k": results_12k
# }
fieldnames = [
"Report Year",
"Summary",
"# swds",
"DTC",
"MTC",
"Occr",
"CTC mean",
"CTC sd",
"CTC min",
"CTC max"
]
with tempfile.NamedTemporaryFile(
delete=False,
suffix=".csv",
dir='/tmp',
prefix='ncthreats'
) as temp:
csvwriter = csv.DictWriter(temp, fieldnames=fieldnames)
csvwriter.writeheader()
for summary in results_complete:
row = {}
row["Report Year"] = results_complete[summary]['year']
row["Summary"] = summary
row["# swds"] = results_complete[summary]["samplesize"]
row["DTC"] = results_complete[summary]["thrts_included_msg"][0].strip()
row["MTC"] = results_complete[summary]["thrts_included_msg"][1].strip()
row["Occr"] = results_complete[summary]["other_stats"]['comp_occ']
row["CTC mean"] = results_complete[summary]["threat_summary"][0][1]
row["CTC sd"] = results_complete[summary]["threat_summary"][0][2]
row["CTC min"] = results_complete[summary]["threat_summary"][0][3]
row["CTC max"] = results_complete[summary]["threat_summary"][0][4]
csvwriter.writerow(row)
temp_name1 = temp.name
##################################################################
# start ssheet2
##################################################################
fieldnames = [
"Report Year",
"Summary",
"Threat Name",
"Occurrence",
"Severity",
"Severity s.d.",
"Severity min.",
"Severity max.",
"Data Mean"
]
with tempfile.NamedTemporaryFile(
delete=False,
suffix=".csv",
dir='/tmp',
prefix='ncthreats'
) as temp:
csvwriter = csv.DictWriter(temp, fieldnames=fieldnames)
csvwriter.writeheader()
for summary in results_complete:
row = {}
for rept_rank in results_complete[summary]['report_rank']:
row["Report Year"] = results_complete[summary]['year']
row["Summary"] = summary
row["Threat Name"] = rept_rank[0]
row["Occurrence"] = rept_rank[1]
row["Severity"] = rept_rank[2]
row["Severity s.d."] = rept_rank[3]
row["Severity min."] = rept_rank[4]
row["Severity max."] = rept_rank[5]
row["Data Mean"] = rept_rank[6]
csvwriter.writerow(row)
temp_name2 = temp.name
with tempfile.NamedTemporaryFile(
delete=False,
suffix=".zip",
dir='/tmp',
prefix='ncthreats'
) as temp:
zf = zipfile.ZipFile(temp, mode='w')
zf.write(temp_name1, "Summary.csv")
zf.write(temp_name2, "ThreatData.csv")
zf.write("/var/www/wsgi/wps-server/templates/README.txt", "README.txt")
zf.close()
return temp.name
def batch_spreadsheet(id, query_str):
logger.debug("batch_spreadsheet")
query = "select * from batch where batch_id = %s order by name"
batch_results = collections.OrderedDict()
with g.db.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute(query, (id, ))
for row in cur:
name = row['name']
aoi_id = row['resource'].split("/")[-1]
logger.info(name)
logger.debug(aoi_id)
results_aoi = model.get_threat_report2(aoi_id, query_str, 'aoi')
results_5k = model.get_threat_report2(aoi_id, query_str, '5k')
results_12k = model.get_threat_report2(aoi_id, query_str, '12k')
results_aoi['samplesize'] = len(results_aoi['res_arr'])
del(results_aoi["res_arr"])
a = results_aoi["thrts_included_msg"].split("of")
results_aoi["thrts_included_msg"] = a
results_5k['samplesize'] = len(results_5k['res_arr'])
del(results_5k["res_arr"])
a = results_5k["thrts_included_msg"].split("of")
results_5k["thrts_included_msg"] = a
results_12k['samplesize'] = len(results_12k['res_arr'])
del(results_12k["res_arr"])
a = results_12k["thrts_included_msg"].split("of")
results_12k["thrts_included_msg"] = a
batch_results[name] = collections.OrderedDict()
batch_results[name]['aoi'] = results_aoi
batch_results[name]['5k'] = results_5k
batch_results[name]['12k'] = results_12k
# batch_results[name]['samplesize'] = samplesize
results = []
for polygon in batch_results:
for summary in batch_results[polygon]:
row = {}
row["Report Year"] = batch_results[polygon][summary]['year']
row['Polygon'] = polygon
row["Summary"] = summary
row["# swds"] = batch_results[polygon][summary]["samplesize"]
row["DTC"] = batch_results[polygon][summary]["thrts_included_msg"][0].strip()
row["MTC"] = batch_results[polygon][summary]["thrts_included_msg"][1].strip()
row["Occr"] = batch_results[polygon][summary]["other_stats"]['comp_occ']
row["CTC mean"] = batch_results[polygon][summary]["threat_summary"][0][1]
row["CTC sd"] = batch_results[polygon][summary]["threat_summary"][0][2]
row["CTC min"] = batch_results[polygon][summary]["threat_summary"][0][3]
row["CTC max"] = batch_results[polygon][summary]["threat_summary"][0][4]
results.append(row)
fieldnames = [
"Report Year",
"Polygon",
"Summary",
"# swds",
"DTC",
"MTC",
"Occr",
"CTC mean",
"CTC sd",
"CTC min",
"CTC max"
]
with tempfile.NamedTemporaryFile(
delete=False,
suffix=".csv",
dir='/tmp',
prefix='ncthreats'
) as temp:
csvwriter = csv.DictWriter(temp, fieldnames=fieldnames)
csvwriter.writeheader()
csvwriter.writerows(results)
temp_name1 = temp.name
############################################################
# start ss 2
#######################################################
fieldnames = [
"Report Year",
'Polygon',
"Summary",
"Threat Name",
"Occurrence",
"Severity",
"Severity s.d.",
"Severity min.",
"Severity max.",
"Data Mean"
]
results = []
for polygon in batch_results:
for summary in batch_results[polygon]:
rept_rank = batch_results[polygon][summary]['report_rank']
for threat in rept_rank:
row = {}
# logger.debug(threat)
row["Report Year"] = batch_results[polygon][summary]['year']
row['Polygon'] = polygon
row["Summary"] = summary
row["Threat Name"] = threat[0]
row["Occurrence"] = threat[1]
row["Severity"] = threat[2]
row["Severity s.d."] = threat[3]
row["Severity min."] = threat[4]
row["Severity max."] = threat[5]
row["Data Mean"] = threat[6]
results.append(row)
with tempfile.NamedTemporaryFile(
delete=False,
suffix=".csv",
dir='/tmp',
prefix='ncthreats'
) as temp:
csvwriter = csv.DictWriter(temp, fieldnames=fieldnames)
csvwriter.writeheader()
csvwriter.writerows(results)
temp_name2 = temp.name
logger.debug(temp_name1)
logger.debug(temp_name2)
with tempfile.NamedTemporaryFile(
delete=False,
suffix=".zip",
dir='/tmp',
prefix='ncthreats'
) as temp:
zf = zipfile.ZipFile(temp, mode='w')
zf.write(temp_name1, "Summary.csv")
zf.write(temp_name2, "ThreatData.csv")
zf.write("/var/www/wsgi/wps-server/templates/README.txt", "README.txt")
zf.close()
return temp.name