malware-encyclopedias/bin/fetcher.py

50 lines
1.3 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
# coding=utf-8
#
# malware-encyclopedias is a set of tools to gather malware names and descriptions
#
# Software is free software released under the "Modified BSD license"
#
# Copyright (c) 2015-2016 Alexandre Dulaunoy - a@foo.be
import requests
import feedparser
import string
import json
import datetime
import os
vendors = ['symantec']
symantec_url = "http://www.symantec.com/xml/rss/azlistings.jsp?azid="
symantec_listings = ['_1234567890']
rawdir = '../raw'
date_handler = lambda obj: (
obj.isoformat()
if isinstance(obj, datetime.datetime)
or isinstance(obj, datetime.date)
else None
)
def symantec_parsing(doc = False):
if not doc:
return False
return feedparser.parse(doc)
def json_save(vendor = False, dump=False, part=None):
if not vendor or not dump:
return False
fd = open(os.path.join(rawdir, vendor+"/"+part+".json"), 'w')
fd.write(json.dumps(dump, default=date_handler))
fd.close()
for e in list(string.ascii_uppercase):
symantec_listings.append(e)
for vendor in vendors:
for d in symantec_listings:
r = requests.get(symantec_url+d)
if r.status_code == 200:
json_save(vendor = vendor, dump=symantec_parsing(doc=r.text), part=d)