-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombineData.py
executable file
·49 lines (41 loc) · 1.31 KB
/
combineData.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
#!/usr/local/bin/python
import sys
import json
def combineURLDicts(dict1, dict2):
newDict = {}
for key in dict1.keys():
if key not in dict2:
newDict[key] = dict1[key]
else:
newDict[key] = dict1[key] + dict2[key]
for key in dict2.keys():
if key not in dict1:
newDict[key] = dict2[key]
return newDict
def addDataDict(dataDict, articleDict):
for company in articleDict.keys():
for date in articleDict[company]:
article = articleDict[company][date]
if article in dataDict:
dataDict[article]["company"] += [company]
else:
dataDict[article] = {"date": date[:10], "company": [company]}
return dataDict
def getJSON(fileName):
f = open(fileName)
jsonData = json.load(f)
f.close()
return jsonData
def writeJSON(jsonData, fileName):
f = open(fileName, 'w')
json.dump(jsonData, f)
f.close()
json1 = getJSON(sys.argv[2])
json2 = getJSON(sys.argv[3])
json3 = getJSON(sys.argv[4])
finalJsonFile = sys.argv[5]
if (sys.argv[1] == "data"):
combinedJSON = addDataDict(addDataDict(addDataDict({}, json1), json2), json3)
elif (sys.argv[1] == "url"):
combinedJSON = combineURLDicts(combineURLDicts(json1, json2), json3)
writeJSON(combinedJSON, finalJsonFile)