-
Notifications
You must be signed in to change notification settings - Fork 2
/
sampledates.py
39 lines (35 loc) · 981 Bytes
/
sampledates.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
import ast
import os
import io
import json
import sys
if os.path.isfile('sampledates.json'):
with io.open('sampledates.json', 'rb') as cache:
dates = json.load(cache)
else:
dates = dict()
with io.open('samples.json', 'rb') as infile:
ransomware = json.load(infile)
index = 0
for hash, data in ransomware.items():
if hash not in dates:
metafile ='MetaInfo/' + hash + '.json'
if os.path.isfile(metafile):
with open(metafile, 'r') as meta:
try:
data = ast.literal_eval(meta.readline())
except Exception:
print 'crash parsing', hash
raise
attrs = data['data']['attributes']
if 'first_submission_date' in attrs:
dates[hash] = int(attrs['first_submission_date'])
else:
dates[hash] = None
index += 1
if index % 1000 == 0:
sys.stderr.write('\r%dk ' % (index / 1000))
sys.stderr.flush()
sys.stderr.write('\r%d / %d \n' % (len(dates), index))
with io.open('sampledates.json', 'wb') as outfile:
json.dump(dates, outfile)