def get_fiat_value(self, start_date=datetime.date(datetime.now() - timedelta(days=1)), stop_date=datetime.date(datetime.now()),
                       base_currency="EUR", target_currency="USD"):
        """
        FIAT currency converter from European Central Bank, through https://exchangeratesapi.io API
        Parameters
        ----------
        start_date : datetime
            starting date for currency retrieval (default value: yesterday)
        stop_date : datetime
            stop date for currency retrieval (default value = today)
        base_currency : string
            base currency to convert from (EUR, USD, ...)
        target_currency : string
            target currency to convert to (USD, JPY, GBP, ...)

        Returns
        -------
        current_rate : float
            Exchange rate for stop date
        currecy_rates : dictionary(date: string<YYYY-MM-DD>, float)
            Exchange rates for whole configured date span (bank holidays not included, no rate for those dates)

        Raises
        ------
        ValueError
            If base currency and target currency are the same
            If stop date is previous to start date
            If any of the dates is in the future (beyond today)
        ConnectionError
            If response from server is not 200
        """
        currency_rates = dict()
        if base_currency == target_currency:
            raise ValueError("Base currency and target currency can not be equal")
        elif start_date >= datetime.now():
            raise ValueError("Start date must not be in the future or current date")
        elif stop_date > datetime.now():
            raise ValueError("Start date must not be in the future or current date")
        elif start_date > stop_date:
            raise ValueError("Start date can not be greater than stop date")
        else:
            # EUR / fiat_currency exchange rate from BCE
            date_start = start_date.strftime('%Y-%m-%d')
            date_stop = stop_date.strftime('%Y-%m-%d')
            headers = {
                'Accepts': 'application/json',
                'Accept-Encoding': 'deflate, gzip',
            }
            request_address = f'https://api.exchangeratesapi.io/history?base={base_currency.value}&start_at={date_start}&end_at={date_stop}&symbols={target_currency.value}'
            manager_fiat = RequestManager(headers)
            data = manager_fiat.send_request(parameters={}, url=request_address)

            # Check that everything was OK
            if manager_fiat.status_code == 200:
                rates = data["rates"]
                for rate in rates:
                    currency_rates[rate] = round(rates[rate][target_currency.value],4)
                return currency_rates[stop_date.strftime('%Y-%m-%d')], currency_rates
            else:
                raise ConnectionError("Connection did not finish as expected. HTTP error code {}\nRequest was: {}".format(manager_fiat.status_code, request_address))
def main():
    if '-r' in sys.argv:
        RequestManager.read_tiindicators()
        sys.exit()
    config.verbose_log = ('-v' in sys.argv)
    print('fetching & parsing data from misp...')
    events = _get_events()
    parsed_events = list()
    for event in events:
        parsed_event = defaultdict(list)

        for key, mapping in EVENT_MAPPING.items():
            parsed_event[mapping] = event.get(key, "")
        parsed_event['tags'] = [
            tag['name'].strip() for tag in event.get("Tag", [])
        ]
        _handle_diamond_model(parsed_event)
        _handle_tlp_level(parsed_event)
        _handle_timestamp(parsed_event)

        for attr in event['Attribute']:
            if attr['type'] == 'threat-actor':
                parsed_event['activityGroupNames'].append(attr['value'])
            if attr['type'] == 'comment':
                parsed_event['description'] += attr['value']
            if attr['type'] in MISP_ACTIONABLE_TYPES:
                parsed_event['request_objects'].append(RequestObject(attr))

        parsed_events.append(parsed_event)
    del events

    total_indicators = sum([len(v['request_objects']) for v in parsed_events])
    with RequestManager(total_indicators) as request_manager:
        for request_body in _graph_post_request_body_generator(parsed_events):
            request_manager.handle_indicator(request_body)
def send_message(comments, footer, footer_icon):
    star = ":star:"
    data = {
        'score': comments['score'],
        'title': comments['title'],
        'date': comments['date'],
        'comment': comments['comment'],
        'pretext': '`TEST` UtaPass Android has a new review!',
        'text': ''.join(star * int(comments['score']) + ' Score : %s' % str(comments['score'])),
        'content': u'{}\n\n [Translation]\n*{}*\n\n{}\n\n_{}  ver.{}_'.format(comments['comment'],
                                                                              comments['translated_title'],
                                                                              comments['translated_comment'],
                                                                              (comments['date']).strftime('%Y-%m-%d'),
                                                                              comments['version']),
        'thumb_url': 'https://img.au-market.com/mapi/pc_icon/39767/3976700000002/100211_116788.png',
        'footer': footer,
        'footer_icon': footer_icon
    }
    # if review has no version info or from au Market, wouldn't show comments['version']
    if comments['version'] is None or footer == FOOTER[0]:
        data['content'] = u'{}\n\n [Translation]\n*{}*\n\n{}\n\n_{}_'.format(comments['comment'],
                                                                             comments['translated_title'],
                                                                             comments['translated_comment'],
                                                                             (comments['date']).strftime('%Y-%m-%d'))
    RequestManager().slackAttachmentsWithFieldsMessager('#test-b0t', data['pretext'], "", data['text'], "", "",
                                                        "Android Reviews Bot", data['footer'], data['title'],
                                                        data['content'], data['thumb_url'], data['footer_icon'])
Beispiel #4
0
    def __init__(self):
        self.authorizer = Authorizer("auth_info.json")

        self.request_manager = RequestManager()

        self.sockets: Dict[int, socket.socket] = {}  # fileno : sock

        self.clients: Dict[int, Client] = {}  # fileno : client
        self.authorized_clients: Dict[str, Client] = {}  # username : client

        self.buffered_data: Dict[int, str] = {}  # fileno : data

        self.poller = select.poll()

        self.remove_idle_clients_forever()
def send_message(comments):
    star = ":star:"
    data = {
        'score': comments['score'],
        'title': comments['title'],
        'date': comments['date'],
        'comment': comments['comment'],
        'pretext': '`TEST` UtaPass iOS has a new review!',
        'text': ''.join(star * int(comments['score']) + ' Score : %s' % str(comments['score'])),
        'content': u'{}\n\n [Translation]\n*{}*\n\n{}\n\n_{}  ver.{}_'.format(comments['comment'],
                                                                              comments['translated_title'],
                                                                              comments['translated_comment'],
                                                                              (comments['date']).strftime('%Y-%m-%d'),
                                                                              comments['version']),
        'thumb_url': 'https://img.au-market.com/mapi/pc_icon/39767/3976700000002/100211_116788.png',
        'footer': 'App Store reviews crawler',
        'footer_icon': 'https://banner2.kisspng.com/20180729/cup/kisspng-app-store-iphone-apple-app-store-icon-transparent-5b5e1adc964cf5.4117097315328939166156.jpg',
    }
    RequestManager().slackAttachmentsWithFieldsMessager('#test-b0t', data['pretext'], "", data['text'], "", "",
                                                        "iOS Reviews Bot", data['footer'], data['title'],
                                                        data['content'], data['thumb_url'], data['footer_icon'])
    def get_cypto_value(self,
                        start_date=datetime.date(datetime.now() -
                                                 timedelta(days=1)),
                        stop_date=datetime.date(datetime.now()),
                        currency="XBT"):
        """
        Crypto assets information gathered from CoinMarketCap
        Assets denomination can be found in ISO-4217 from IETF
        (https://tools.ietf.org/html/draft-stanish-x-iso4217-a3-01)
        Parameters
        ----------
        start_date : datetime
            starting date for currency retrieval (default value: yesterday)
        stop_date : datetime
            stop date for currency retrieval (default value = today)
        currency : string
            crypto currency to get information from (XBTC, XETH, ...)
        Returns
        -------
        data : JSON object
            data retreived from CoinMarketCap
        """
        url = 'https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
        parameters = {
            'start': '1',
            'limit': '1',
            'convert': f'{base_currency}'
        }
        headers = {
            'Accepts': 'application/json',
            'Accept-Encoding': 'deflate, gzip'
        }

        if self.api_key_coinmarketcap:
            headers['X-CMC_PRO_API_KEY'] = self.api_key_coinmarketcap

        crypto_manager = RequestManager(headers)
        data = crypto_manager.send_request(parameters, url)
        return data
Beispiel #7
0
from EWSClientType import EWSClientType
from RequestManager import RequestManager
from FileManager import FileManager

try:
    import thread
except ImportError:
    import _thread as thread
import time

pi_id = str(3)

if len(sys.argv) > 1:
    pi_id = str(sys.argv[1])

rm = RequestManager()
fm = FileManager()

HOST = "wss://cs70esocmi.execute-api.us-east-1.amazonaws.com/dev"


def send_to_display_controller(message):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = '127.0.0.1'
    port = 1234

    s.connect((host, port))
    s.sendall(bytes(message, encoding="utf-8"))
    s.close()

 def __init__(self):
     self._torManager = TorManager()
     self._steamScraper = SteamScraper(730)
     self._requestManager = RequestManager(None)
     self._logger = logging.getLogger('BatchMain')
     self._logger.setLevel(logging.DEBUG)
Beispiel #9
0
import threading
import socket
import pickle
import struct
from RequestManager import RequestManager

requestManager = RequestManager()
requestManagerLock = threading.Lock()
bufferSize = 4096
host = ''
port = 20041


def sendMsg(sock, msg):
    msg = struct.pack('>I', len(msg)) + msg
    sock.sendall(msg)


def recvMsg(sock):
    raw_msglen = recvall(sock, 4)
    if not raw_msglen:
        return None
    msglen = struct.unpack('>I', raw_msglen)[0]
    return recvall(sock, msglen)


def recvall(sock, n):
    data = ''.encode()
    while len(data) < n:
        packet = sock.recv(min(n - len(data), bufferSize))
        if not packet:
Beispiel #10
0
def startup(args: argparse.Namespace, **kwargs: Dict[str, Any]) -> None:
    global announce, dispatcher, group, httpServer, notification, validator
    global registration, remote, request, security, statistics, storage, event
    global rootDirectory
    global aeStatistics
    global supportedReleaseVersions, cseType, defaultSerialization, cseCsi, cseRi, cseRn
    global cseOriginator
    global isHeadless

    rootDirectory = os.getcwd()  # get the root directory
    os.environ[
        "FLASK_ENV"] = "development"  # get rid if the warning message from flask.
    # Hopefully it is clear at this point that this is not a production CSE

    # Handle command line arguments and load the configuration
    if args is None:
        args = argparse.Namespace(
        )  # In case args is None create a new args object and populate it
        args.configfile = None
        args.resetdb = False
        args.loglevel = None
        args.headless = False
        for key, value in kwargs.items():
            args.__setattr__(key, value)
    isHeadless = args.headless

    if not Configuration.init(args):
        return

    # Initialize configurable constants
    supportedReleaseVersions = Configuration.get(
        'cse.supportedReleaseVersions')
    cseType = Configuration.get('cse.type')
    cseCsi = Configuration.get('cse.csi')
    cseRi = Configuration.get('cse.ri')
    cseRn = Configuration.get('cse.rn')
    cseOriginator = Configuration.get('cse.originator')

    defaultSerialization = Configuration.get('cse.defaultSerialization')

    # init Logging
    Logging.init()
    if not args.headless:
        Logging.console('Press ? for help')
    Logging.log('============')
    Logging.log('Starting CSE')
    Logging.log(f'CSE-Type: {cseType.name}')
    Logging.log('Configuration:')
    Logging.log(Configuration.print())

    # Initiatlize the resource storage
    storage = Storage()

    # Initialize the event manager
    event = EventManager()

    # Initialize the statistics system
    statistics = Statistics()

    # Initialize the registration manager
    registration = RegistrationManager()

    # Initialize the resource validator
    validator = Validator()

    # Initialize the resource dispatcher
    dispatcher = Dispatcher()

    # Initialize the request manager
    request = RequestManager()

    # Initialize the security manager
    security = SecurityManager()

    # Initialize the HTTP server
    httpServer = HttpServer()

    # Initialize the notification manager
    notification = NotificationManager()

    # Initialize the group manager
    group = GroupManager()

    # Import a default set of resources, e.g. the CSE, first ACP or resource structure
    # Import extra attribute policies for specializations first
    importer = Importer()
    if not importer.importAttributePolicies() or not importer.importResources(
    ):
        return

    # Initialize the remote CSE manager
    remote = RemoteCSEManager()

    # Initialize the announcement manager
    announce = AnnouncementManager()

    # Start AEs
    startAppsDelayed(
    )  # the Apps are actually started after the CSE finished the startup

    # Start the HTTP server
    event.cseStartup()  # type: ignore
    httpServer.run()  # This does return (!)

    Logging.log('CSE started')
    if isHeadless:
        # when in headless mode give the CSE a moment (2s) to experience fatal errors before printing the start message
        BackgroundWorkerPool.newActor(
            delay=2,
            workerCallback=lambda: Logging.console('CSE started')
            if not shuttingDown else None).start()

    #
    #	Enter an endless loop.
    #	Execute keyboard commands in the keyboardHandler's loop() function.
    #
    commands = {
        '?': _keyHelp,
        'h': _keyHelp,
        '\n': lambda c: print(),  # 1 empty line
        '\x03': _keyShutdownCSE,  # See handler below
        'c': _keyConfiguration,
        'C': _keyClearScreen,
        'D': _keyDeleteResource,
        'i': _keyInspectResource,
        'l': _keyToggleLogging,
        'Q': _keyShutdownCSE,  # See handler below
        'r': _keyCSERegistrations,
        's': _keyStatistics,
        't': _keyResourceTree,
        'T': _keyChildResourceTree,
        'w': _keyWorkers,
    }

    #	Endless runtime loop. This handles key input & commands
    #	The CSE's shutdown happens in one of the key handlers below
    loop(commands, catchKeyboardInterrupt=True, headless=args.headless)
    shutdown()