async def add(self, name, email, phone, listId):
        pushData = {
            'api_key': self.api_key,
            'fields[email]': email,
            'list_ids': listId,
            'double_optin': 3,
            'format': self.format
        }
        if name:
            pushData['fields[Name]'] = name
        if phone:
            pushData['fields[phone]'] = '+' + str(phone)

        async with aiohttp.ClientSession() as session:
            async with session.post(self.url, data=pushData) as resp:
                if not resp.status == 200:
                    log_error('Unisender не отвечает!')
                    return

                data = await resp.json()
                if 'error' in data:
                    text = 'Не получилось записать email {}\nОшибка: {}'
                    log_error(text.format(email, data['error']))
                else:
                    log_info('Email {} записан'.format(email))
Exemple #2
0
def read_ast_file(filename):
    log_info(f"Reading input AST: {filename}")
    try:
        ast = ET.parse(filename)
        return ast
    except IOError as e:
        log_err(e.args[1])
        return None
    except Exception as e:
        log_err(str(e))
        return None
Exemple #3
0
def create_ast_file(ps1_file):
    log_info(f"Creating AST for: {ps1_file}")

    cmd = ["PowerShell", "-ExecutionPolicy", "Unrestricted", "-File",
           os.path.abspath(os.path.join("tools", "Get-AST.ps1")),
           "-ps1", os.path.abspath(ps1_file)]

    result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)

    for line in result.stdout.splitlines():
        log_debug(line)

    return result.returncode == 0
Exemple #4
0
    def __init__(self, filename):
        self._version = 0
        self._count = 0
        self._api = None

        logger.log_info("Loading file: %s" % filename)
        self._filename = filename
        try:
            with open(filename, "rb") as f:
                self._data = f.read()
            if self._load():
                self._parse()
        except OSError as e:
            logger.log_err(e.strerror)
Exemple #5
0
    def optimize(self, ast):

        count_in = sum(1 for _ in ast.getroot().iter())
        log_debug(f"{count_in} nodes loaded")

        while optimize_pass(ast):
            self.stats.modifications += 1

        log_info(f"{self.stats.modifications} modifications applied")

        count_out = sum(1 for _ in ast.getroot().iter())
        ratio = "{:02.2f}".format(count_out / count_in * 100.00)
        log_debug(f"{count_out} nodes in output ({ratio}%)")

        return ast
Exemple #6
0
    async def send_msg(self, msgText):
        url = self.urlStart + 'sendMessage'
        sendData = {'chat_id': self.chat, 'text': msgText}

        try:
            async with aiohttp.ClientSession() as session:
                async with session.get(url, params=sendData) as resp:
                    data = await resp.json()
                    if not data['ok']:
                        text = 'Ошибка {} при отправке Telegram-сообщения {}.'
                        log_error(text.format(data['description'], msgText))
                        return
                    else:
                        log_info('Отправлено Telegram-сообщение {}.'.format(
                            msgText))
                        return
        except aiohttp.ClientConnectorError as e:
            log_error('Ошибка подключения к API Telegram.')
            return
Exemple #7
0
    async def __send(self, msgData):
        try:
            async with aiohttp.ClientSession() as session:
                async with session.get(self.url, params=msgData) as resp:
                    pass
        except aiohttp.ServerDisconnectedError as resp:
            if not resp.message.code == 200:
                log_error('GoIP не отвечает!')
                return

            if 'ERROR' in resp.message.reason:
                text = 'Не получилось отправить смс {} на номер {}'
                text += '\nОшибка: {}'
                log_error(
                    text.format(msgData['m'], msgData['p'],
                                resp.message.reason))
            else:
                log_info('Смс {} на номер {} отправлено'.format(
                    msgData['m'], msgData['p']))
Exemple #8
0
    def rebuild(self, node):
        self.stats.nodes = 0
        self._parent_map = parent_map(node)

        log_info(f"Rebuilding script to: {self.output_filename}")

        with open(self.output_filename, "w") as self.output:
            self._rebuild_internal(node)

            log_info(f"{self.stats.nodes} nodes traversed")
            log_info(f"{self.output.tell()} bytes written")
Exemple #9
0
def main():
    welcome()
    set_log_level(LogLevel.DEBUG)
    parse_args()
    if OPTIONS.setdefault("test", False):
        test()
    elif OPTIONS.setdefault("file", None) is not None:
        api = ApiSetSchema(OPTIONS["file"])
        logger.log_info("Version: %d" % api.version)
        logger.log_info("Count: %d" % api.count)
        for entry in api.entries:
            for value in entry.values:
                logger.log_info("%s -> %s" % (entry.name, value.value))
    else:
        usage()
Exemple #10
0
def test():
    welcome()
    set_log_level(LogLevel.DEBUG)

    for sample in glob.glob("data/*.dll"):
        api = ApiSetSchema(sample)
        logger.log_info("Version: %d" % api.version)
        logger.log_info("Count: %d" % api.count)
        logger.log_info("Writing entries to " + sample + ".txt")

        with open(sample + ".csv", "w", newline="") as csvfile:
            writer = csv.DictWriter(csvfile,
                                    fieldnames=['Name', 'Value'],
                                    delimiter=';')
            writer.writeheader()
            for entry in api.entries:
                for value in entry.values:
                    writer.writerow({"Name": entry.name, "Value": value.value})