-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_json.py
More file actions
59 lines (38 loc) · 1.08 KB
/
csv_json.py
File metadata and controls
59 lines (38 loc) · 1.08 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
from flask import Flask, render_template, request
import requests
import csv
import json
app = Flask(__name__)
@app.route('/convert', methods=['POST'])
def convert():
fname1 = request.form['path1']
fname2 = request.form['path2']
name = request.form['name']
j = []
f1 = open (fname1,'rU')
f2 = open (fname2,'w')
c = 0
d = 0
reader = csv.DictReader(f1, delimiter=",", lineterminator='\n')
for row in reader :
del(row[" timestamp"])
del(row["Pressure"])
del(row["Humidity"])
del(row["Temperature"])
del(row[""])
row["Station"]=name
j.append(row)
c=c+1
for row in j :
json.dump(row,f2)
if(d!=c-1):
f2.write(',')
f2.write('\n')
d=d+1
tempf="JSON Parsed! Path of Parsed JSON File --> " + fname2
return render_template('json.html', temp=tempf)
@app.route('/')
def index1():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)