# -*- coding: utf-8 -*-
# @Time     : 2022/01/30 12:07:37
# @Author   : ddvv
# @Site     : https://ddvvmmzz.github.io
# @File     : malwarebazaar.py
# @Software : Visual Studio Code
# @WeChat   : NextB


import json
import requests
from hihunter.common.common import *

class MalwareBazaar(object):
    def __init__(self, api_key):
        self.api_key = api_key

    def upload(self, file_name):
        try:
            data = {
                'anonymous': 0,
                'delivery_method': 'other',
                'tags': [
                ],
                'references': {
                },
                'context': {
                }
            }
            files = {
                'json_data': (None, json.dumps(data), 'application/json'),
                'file': (open(file_name,'rb'))
                }
            headers = {'API-KEY': self.api_key}
            response = requests.post('https://mb-api.abuse.ch/api/v1/', files=files, headers=headers)
            return return_data(2000, 'upload success', response.json())
        except Exception as e:
            return return_data(20001, str(e), {})