Created
June 12, 2018 10:07
-
-
Save chadyred/ecf187517112278c653c55f97eece24e to your computer and use it in GitHub Desktop.
Create report with virus total
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import abc | |
import sys | |
from typing import Callable, IO, cast | |
import requests | |
import attr | |
class MessageTemplating(metaclass=abc.ABCMeta): | |
@abc.abstractmethod | |
def format_message(self, message: 'Messagerable') -> str: | |
"""Message factoring""" | |
class Messagerable(metaclass=abc.ABCMeta): | |
@abc.abstractmethod | |
def print_with_on(self, message: str, messagerTemplate : 'MessageTemplating', stream: IO[str]) -> 'Messagerable': | |
"""Message factoring""" | |
class Messager(Messagerable): | |
def print_with_on(self, message: str, messagerTemplate : 'MessageTemplating', stream: IO[str]) -> 'Messagerable': | |
messagerTemplate.format_message( | |
message, | |
lambda message_formatted: stream.write(message_formatted) | |
) | |
return self | |
class MessagerTemplate(MessageTemplating): | |
def format_message(self, message: str, action: Callable[[str], None]) -> str: | |
"""Show notice""" | |
action("Notice : " + message + '\n') | |
return self | |
class HostCaller(metaclass=abc.ABCMeta): | |
@abc.abstractmethod | |
def make_me_a_call(self, host: str, params: dict, action: Callable[['Messagerable'], None]) -> str: | |
"""Call host with credential""" | |
@attr.s | |
class ParamsData(): | |
params = attr.ib(default={}) | |
headers = attr.ib(default={}) | |
class ApiCallerVirusTotal(HostCaller): | |
def make_me_a_call(self, host: str, paramsData: 'ParamsData', action: Callable[['Messagerable'], None]) -> str: | |
"""Call host with credential""" | |
response = requests.post(host, paramsData.params, headers=paramsData.headers) | |
json = response.json() | |
action(str(json)) | |
return self | |
if __name__ == '__main__': | |
ApiCallerVirusTotal().make_me_a_call( | |
'https://www.virustotal.com/vtapi/v2/file/scan', | |
ParamsData( | |
params={'apikey':'API_KEY', 'file' : 'PATH_TO_FILE'}, | |
headers={'Accept-Encoding':'gzip, deflate', "User-Agent" : 'gzip, My python script example'} | |
), | |
lambda result: Messager().print_with_on( | |
result, | |
MessagerTemplate(), | |
sys.stdout | |
) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment