-
Notifications
You must be signed in to change notification settings - Fork 0
/
DUEunzip.py
65 lines (48 loc) · 1.5 KB
/
DUEunzip.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 26 19:19:07 2020
@author: cappiello
"""
import json
import requests
from zipfile import ZipFile
import csv
#BLUEPRINT_PATH = 'blueprint.json'
#CONCRETE_ID = '_id'
#CONCRETE_ABSTRACT_PROPERTIES = 'DATA_MANAGEMENT'
#INT_STRUCT = 'INTERNAL_STRUCTURE'
#OUT_DATA = 'Testing_Output_Data'
#METHOD_ID = 'method_id'
#ZIP_Data = 'zip_data'
def DUEunzip(methodURL):
#with open(BLUEPRINT_PATH) as bp_file:
# bp = json.load(bp_file)
#methodnames = []
#zipdata=[]
#for method in bp[INT_STRUCT][OUT_DATA]:
# methodnames.append(method[METHOD_ID])
# zipdata.append(method[ZIP_Data])
c='getNutritionalData'
#methodURL="https://github.com/DITAS-Project/data-utility-evaluator/blob/master/dataset/getNutritionalData.zip?raw=true"
url = methodURL
r= requests.get(url)
open('dataset/'+c+'.zip','wb').write(r.content)
# DQDUE.openzipfile('dataset/'+c+'.zip')
with ZipFile('dataset/'+c+'.zip', 'r') as ZipObj:
ZipObj.extractall('dataset')
data = json.load(open('dataset/'+c+'.json'))
sample_data = open('dataset/'+c+'.csv', 'w')
csvwriter = csv.writer(sample_data)
count=0
for item in data:
if count == 0:
header=item.keys()
csvwriter.writerow(header)
count += 1
csvwriter.writerow(item.values())
sample_data.close()
c='dataset/'+c+'.csv'
return c
#return data
# datacsv = convertJSON(data)