Skip to content

Commit eda99c1

Browse files
author
Michael Skelton
committed
Multiple sheets and split fields
1 parent eaf7c0b commit eda99c1

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

UpdateJsonDataset/GenerateJsonDataset.pyproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<Compile Include="excel_to_json.py">
3232
<SubType>Code</SubType>
3333
</Compile>
34+
<Compile Include="split_json.py">
35+
<SubType>Code</SubType>
36+
</Compile>
3437
</ItemGroup>
3538
<Import Project="$(PtvsTargetsFile)" Condition="Exists($(PtvsTargetsFile))" />
3639
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" Condition="!Exists($(PtvsTargetsFile))" />

UpdateJsonDataset/split_json.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import xlrd
2+
from collections import OrderedDict
3+
import simplejson as json
4+
import urllib.request
5+
6+
SOURCESHEET = 'https://docs.google.com/spreadsheets/d/1TWS238xacAto-fLKh1n5uTsdijWdCEsGIM0Y0Hvmc5g/pub?output=xlsx'
7+
OUTPUTSHEET = 'RansomwareOverview.xlsx'
8+
JSONFILE = 'RansomwareOverview.json'
9+
10+
# download and save ransomware overview file locally
11+
try:
12+
urllib.request.urlretrieve(SOURCESHEET, OUTPUTSHEET)
13+
except IOError:
14+
print('An error occured trying to write an updated spreadsheet. Do you already have it open?')
15+
except urllib.error.URLError:
16+
print('An error occured trying to download the file. Please check the source and try again.')
17+
18+
wb = xlrd.open_workbook(OUTPUTSHEET)
19+
sh = wb.sheet_by_index(0)
20+
mw = wb.sheet_by_index(2)
21+
# List to hold dictionaries
22+
c_list = []
23+
24+
# Iterate through each row in worksheet and fetch values into dict
25+
for rownum in range(1, sh.nrows):
26+
cars = OrderedDict()
27+
row_values = sh.row_values(rownum)
28+
29+
30+
if row_values[6]=="":
31+
name = row_values[0]
32+
gre=[name]
33+
elif "," in row_values[6]:
34+
e=row_values[6].split(",")
35+
ge = [row_values[0]]
36+
gre=e+ge
37+
else:
38+
gre=[row_values[0],row_values[6]]
39+
print (gre)
40+
cars['Name'] = gre
41+
cars['Extensions'] = row_values[1]
42+
cars['Extension Pattern'] = row_values[2]
43+
cars['Ransom Note Filename(s)'] = row_values[3]
44+
cars['Comment'] = row_values[4]
45+
cars['Encryption Algorithm'] = row_values[5]
46+
cars['Decryptor'] = row_values[7]
47+
if row_values[8]=="":
48+
cars['Resources'] = [row_values[9]]
49+
elif row_values[9]=="":
50+
cars['Resources']=[row_values[8]]
51+
else:
52+
cars['Resources'] = [row_values[8], row_values[9]]
53+
cars['Screenshots'] = row_values[10]
54+
55+
for r in range(1, mw.nrows):
56+
rowe = mw.row_values(r)
57+
58+
if row_values[0] == rowe[0]:
59+
cars['Microsoft Detection Name']=rowe[1]
60+
cars['Microsoft Info'] = rowe[2]
61+
cars['Sandbox'] = rowe[3]
62+
cars['IOCs'] = rowe[4]
63+
cars['Snort'] = rowe[5]
64+
65+
c_list.append(cars)
66+
67+
# Serialize the list of dicts to JSON
68+
j = json.dumps(c_list)
69+
70+
# Write to file
71+
with open(JSONFILE, 'w') as f:
72+
f.write(j)
73+
74+
f.close()

0 commit comments

Comments
 (0)