Exemplo n.º 1
0
def time_mash(stamp, lang=None):
    day = 0
    text = ''
    if lang is None:
        lang = {'day': 'д. ', 'hour': 'ч. ', 'min': ' мин.'}
    seconds = stamp - time_now()
    hours = int(seconds / (60 * 60))
    if hours > 24:
        day = int(hours / 24)
        hours -= day * 24
        text += str(day) + lang['day'] + str(hours) + lang['hour']
    elif hours > 0:
        text += str(hours) + lang['hour']
    elif hours < 0:
        hours = 0
    minutes = int((seconds / 60) - (day * 24 * 60) - (hours * 60))
    response = objects.log_time(stamp, tag=objects.italic, form='au_normal')
    if minutes >= 0:
        response += '\nОсталось:' + objects.italic('  ~ ' + text +
                                                   str(minutes) + lang['min'])
    return response
Exemplo n.º 2
0
def former(growing, pub_link, background_coefficient):
    text = ''
    money = None
    keys = post_keys(e_post)
    if growing['title'] != 'none':
        text_to_image = re.sub('/', ' / ', growing['title'])
        text_to_image = re.sub(r'\(.*?\)|[—.,]|г\.', '', text_to_image)
        text_to_image = re.sub('e-mail', 'email', re.sub(r'\s+', ' ', text_to_image))
        if growing['money'] != 'none':
            more = ''
            if growing['money'][1] != 'none':
                more += '+'
            money = numeric_replace(int(growing['money'][0])) + more
            if growing['money'][2] == ' евро.':
                money += u' \u20AC '
            elif growing['money'][2] == ' бел. руб.':
                money += ' бел. руб. '
            elif growing['money'][2] == ' долларов.':
                money += u' \u0024 '
            else:
                money += u' \u20BD '
        growing['tag_picture'] = image(re.sub(r'[—\s-]', ' ', text_to_image.strip()), money, background_coefficient)
        text = growing['tag_picture'] + '👨🏻‍💻 ' + bold(growing['title']) + '\n'
    if growing['experience'] != 'none':
        text += '🏅 Опыт работы ➡ ' + growing['experience'].capitalize() + '\n'
    if growing['education'] != 'none':
        text += '👨‍🎓 Образование ➡ ' + growing['education'].capitalize() + '\n'
    if money:
        text += '💸 ' + bold('З/П ') + str(money) + '\n'
    if growing['description'] != 'none':
        text += '{}\n'
    text += bold('📔 Контакты\n')
    if growing['org_name'] != 'none':
        text += growing['org_name'] + '\n'
    if growing['contact'] != 'none':
        text += growing['contact'] + '\n'
    if growing['numbers'] != 'none':
        text += growing['numbers'] + '\n'
    if growing['email'] != 'none':
        text += growing['email'] + ' ➡ Резюме\n'
    if growing['metro'] != 'none':
        text += '🚇 ' + growing['metro'] + '\n'

    if growing['geo'].lower() != 'none':
        text += '\n📍 http://maps.yandex.ru/?text=' + growing['geo'] + '\n'
    text += '\n🔎 ' + pub_link + '\n'

    if growing['tags'] != 'none':
        text += objects.italic('\n💼ТЕГИ: ')
        for i in growing['tags']:
            text += '#' + i + ' '
        text = text[:-1] + '\n'

    if growing['description'] != 'none':
        len_text = 4094 - len(text)
        if len_text - len(growing['description']) >= 0:
            text = text.format(growing['description'])
        else:
            text = text.format(growing['description'][:len_text])

    text += '————\nРазместить вакансию @Superworksbot'
    text += instagram_image(instagram_former(growing), background_coefficient)

    if growing['short_place'] == 'none' or growing['money'] == 'none' or growing['title'] == 'none':
        text = pub_link

    return [text, keys, pub_link, growing]
Exemplo n.º 3
0
def checker():
    from timer import timer
    global main_post_id, mini_post_id, last_date
    while True:
        try:
            sleep(0.1)
            printer_text = main_address + str(main_post_id)
            soup = BeautifulSoup(
                requests.get(printer_text + '?embed=1').text, 'html.parser')
            is_post_not_exist = soup.find('div',
                                          class_='tgme_widget_message_error')
            if is_post_not_exist is None:
                is_post_id_exist = soup.find('div',
                                             class_='tgme_widget_message_link')
                raw = str(
                    soup.find('div',
                              class_='tgme_widget_message_text js-message_text'
                              )).replace('<br/>', '\n')
                if is_post_id_exist:
                    soup = BeautifulSoup(raw, 'html.parser').get_text()
                    time_search = re.search(
                        r'(\d\d) (.*) 10(..)\nРезультаты сражений:', soup)
                    if time_search:
                        reports = {}
                        soup = re.sub('.*\nРезультаты сражений:\n|️', '', soup)
                        trophy_search = re.search(
                            'По итогам сражений замкам начислено:(.*)',
                            soup,
                            flags=re.DOTALL)
                        for row in soup.split('\n\n'):
                            row = re.sub(
                                'По итогам сражений замкам начислено:.+',
                                '',
                                row,
                                flags=re.DOTALL)
                            search_castle = re.search(castles, row)
                            if search_castle:
                                money_search = re.search(
                                    '(на|отобрали) (.*) золотых монет', row)
                                box_search = re.search(
                                    'потеряно (.*) складских ячеек', row)
                                castle = search_castle.group(1)

                                reports[castle] = ': '
                                if e_trident in row:
                                    reports[castle] += e_trident

                                for battle in battle_emoji:
                                    if battle in row:
                                        reports[castle] += battle_emoji.get(
                                            battle)
                                        break

                                if money_search:
                                    if money_search.group(1) == 'на':
                                        reports[castle] += ' -'
                                    elif money_search.group(1) == 'отобрали':
                                        reports[castle] += ' +'
                                    reports[castle] += money_search.group(
                                        2) + '💰'

                                if box_search:
                                    if box_search.group(1) != '0':
                                        reports[
                                            castle] += ' -' + box_search.group(
                                                1) + '📦'

                        if trophy_search:
                            letter = title
                            trophy_list = trophy_search.group(1).split('\n')
                            date = objects.log_time(timer(time_search),
                                                    form='b_channel')
                            for row in trophy_list:
                                search = re.search(
                                    castles + r'.+ \+(\d+) 🏆 очков', row)
                                if search:
                                    castle, trophy = search.groups()
                                    letter += italic(castle +
                                                     str(reports.get(castle)) +
                                                     ' +' + trophy +
                                                     '🏆') + '\n'
                            if stamper(date, '%d/%m/%Y %H:%M') > stamper(
                                    last_date, '%d/%m/%Y %H:%M'):
                                letter += html_link(
                                    printer_text, 'Битва') + ' ' + italic(date)
                                sender(letter, date, 'main')
                            else:
                                printer('пост ' + printer_text +
                                        ' уже был, пропускаю')
                                main_post_id += 1
                    else:
                        printer('пост ' + printer_text +
                                ' не относится к дайджесту, пропускаю')
                        main_post_id += 1
            else:
                printer_text = mini_address + str(mini_post_id)
                soup = BeautifulSoup(
                    requests.get(printer_text + '?embed=1').text,
                    'html.parser')
                is_post_not_exist = soup.find(
                    'div', class_='tgme_widget_message_error')
                if is_post_not_exist is None:
                    is_post_id_exist = soup.find(
                        'div', class_='tgme_widget_message_link')
                    raw = soup.find(
                        'div',
                        class_='tgme_widget_message_text js-message_text')
                    raw = re.sub('️', '', re.sub('<br/>', '\n', str(raw)))
                    if is_post_id_exist:
                        is_post_battle = None
                        soup = BeautifulSoup(raw, 'html.parser').get_text()
                        for row in soup.split('\n'):
                            is_post_battle = re.search(
                                r'Battle (\d{2}) (.*?) 10(\d{2})', row)
                            if is_post_battle:
                                break
                        if is_post_battle:
                            points = None
                            digest = None
                            date = objects.log_time(timer(is_post_battle),
                                                    form='b_channel')
                            for part in soup.split('\n\n'):
                                points_search = re.search('🏆Очки:\n(.*)',
                                                          part,
                                                          flags=re.DOTALL)
                                digest_search = re.search(
                                    '⛳Сводки с полей:\n(.*)',
                                    part,
                                    flags=re.DOTALL)
                                if digest_search:
                                    digest = digest_search.group(1).split('\n')
                                elif points_search:
                                    points = points_search.group(1).split('\n')
                            if stamper(date, '%d/%m/%Y %H:%M') > stamper(
                                    last_date, '%d/%m/%Y %H:%M'):
                                list_tags_a = BeautifulSoup(
                                    raw, 'html.parser').find_all('a')
                                battle_links = []
                                for tag_a in list_tags_a:
                                    if tag_a.get_text() == 'Battle':
                                        battle_links.append(tag_a.get('href'))
                                if len(battle_links) == 1:
                                    search_post = re.search(
                                        main_address, battle_links[0])
                                    if search_post:
                                        raw_post = re.sub(
                                            r'\D', '',
                                            re.sub(main_address, '',
                                                   battle_links[0]))
                                        main_post_id = int(raw_post) + 1
                                        if points and digest:
                                            print(points)
                                            letter = title
                                            for row in digest:
                                                castle_row = re.search(
                                                    '(.*?): .*', row)
                                                points_text = ''
                                                if castle_row:
                                                    for point in points:
                                                        conform = re.search(
                                                            castle_row.group(1)
                                                            + r'.*: \+(\d+)',
                                                            point)
                                                        if conform:
                                                            points_text += ' +' + conform.group(
                                                                1) + '🏆'
                                                letter += italic(
                                                    row + points_text) + '\n'
                                            letter += html_link(
                                                battle_links[0],
                                                'Битва') + ' ' + italic(date)
                                            sender(letter, date, 'mini')
                            else:
                                printer('пост ' + printer_text +
                                        ' уже был, пропускаю')
                                mini_post_id += 1
                        else:
                            printer('пост ' + printer_text +
                                    ' не относится к дайджесту, пропускаю')
                            mini_post_id += 1
                else:
                    sleep(0.02)
        except IndexError and Exception:
            executive()
Exemplo n.º 4
0
async def oldest(server):
    old = 0
    old_values = []
    temp_worksheet = None
    spreadsheet_files = []
    client = gspread.service_account(server['json1'])
    for s in client.list_spreadsheet_files():
        if s['name'] in [i + server['storage'] for i in ['', temp_prefix]]:
            spreadsheet = client.open(s['name'])
            last_worksheet = None
            last_worksheet_id = 1
            for worksheet in spreadsheet.worksheets():
                title = worksheet.title
                if number_secure(title):
                    title = number_secure(title)
                    if int(title) > last_worksheet_id:
                        last_worksheet_id = int(title)
                        last_worksheet = worksheet
                elif title == 'old':
                    last_worksheet = worksheet
            if s['name'] not in spreadsheet_files:
                spreadsheet_files.append(s['name'])
            if last_worksheet:
                values = last_worksheet.col_values(1)
                if s['name'] == temp_prefix + server['storage']:
                    temp_worksheet = last_worksheet
                    old_values = values
                for value in values:
                    value = number_secure(value.split('/')[0])
                    if value:
                        if int(value) > old:
                            old = int(value)
    if old and spreadsheet_files:
        old += 1
        if temp_prefix + server['storage'] not in spreadsheet_files:
            create_temp_spreadsheet(client, server['storage'])
        while True:
            try:
                print_text = server['channel'] + str(old)
                text = requests.get(print_text + '?embed=1')
                response = former(text.text)
                if response.startswith('False'):
                    await asyncio.sleep(8)
                else:
                    try:
                        temp_worksheet.update_cell(
                            len(old_values) + 1, 1, response)
                        old_values.append(response)
                    except IndexError and Exception as error:
                        storage_name = server['storage']
                        search_exceed = re.search('exceeds grid limits',
                                                  str(error))
                        if search_exceed:
                            worksheet_number = 0
                            await asyncio.sleep(100)
                            client = gspread.service_account(server['json1'])
                            temp_spreadsheet = client.open(temp_prefix +
                                                           storage_name)
                            temp_values = temp_spreadsheet.worksheet(
                                'old').col_values(1)

                            dev = Auth.send_dev_message('Устраняем таблицу',
                                                        tag=italic)
                            main_spreadsheet = client.open(storage_name)
                            for w in main_spreadsheet.worksheets():
                                if number_secure(w.title):
                                    title = number_secure(w.title)
                                    if int(title) > worksheet_number:
                                        worksheet_number = int(title)
                            main_worksheet = main_spreadsheet.add_worksheet(
                                str(worksheet_number + 1), limit, 1)
                            main_spreadsheet.batch_update(
                                objects.properties_json(
                                    main_worksheet.id, limit, temp_values))

                            dev_edited = Auth.edit_dev_message(
                                dev,
                                italic('\n— Новая: ' + storage_name + '/' +
                                       str(worksheet_number + 1)))
                            create_temp_spreadsheet(client, storage_name,
                                                    [response])
                            client.del_spreadsheet(temp_spreadsheet.id)
                            Auth.edit_dev_message(dev_edited,
                                                  italic('\n— Успешно'))
                            old_values = [response]
                            await asyncio.sleep(30)
                        else:
                            client = gspread.service_account(server['json1'])
                            temp_worksheet = client.open(
                                temp_prefix + storage_name).worksheet('old')
                            temp_worksheet.update_cell(
                                len(old_values) + 1, 1, response)
                            old_values.append(response)
                    old += 1
                    await asyncio.sleep(1.2)
                    objects.printer(print_text +
                                    ' Добавил в google старый лот')
            except IndexError and Exception:
                await Auth.async_exec()
    else:
        s_name = 'Undefined'
        for name in server_dict:
            if server_dict[name] == server:
                s_name = name
        Auth.send_dev_message(
            'Нет подключения к google.\nНе запущен CW-Notify-Storage-Oldest(' +
            s_name + ')')
Exemplo n.º 5
0
def former(growing, kind, pub_link):
    text = ''
    if growing['title'] != 'none':
        text_to_image = re.sub('/', ' / ', growing['title'])
        text_to_image = re.sub(r'\(.*?\)|[+.,]|г\.', '', text_to_image)
        text_to_image = re.sub('e-mail', 'email',
                               re.sub(r'\s+', ' ', text_to_image))
        growing['tag_picture'] = image(
            re.sub(r'[\s-]', ' ', text_to_image.strip()))
        text = growing['tag_picture'] + '👨🏻‍💻 ' + bold(growing['title']) + '\n'
    if growing['short_place'] != 'none':
        text += '🏙 ' + growing['short_place'] + '\n'
    if growing['experience'] != 'none':
        text += '🏅 Опыт работы ➡ ' + growing['experience'].capitalize() + '\n'
    if growing['education'] != 'none':
        text += '👨‍🎓 Образование ➡ ' + growing['education'].capitalize() + '\n'
    if growing['money'] != 'none':
        more = ''
        if growing['money'][1] != 'none':
            more += '+'
        text += '💸 ' + bold(
            'З/П ') + growing['money'][0] + more + ' руб.' + '\n'
    text += bold('\n📔 Контакты\n')
    if growing['org_name'] != 'none':
        text += growing['org_name'] + '\n'
    if growing['contact'] != 'none':
        text += growing['contact'] + '\n'
    if growing['numbers'] != 'none':
        text += growing['numbers'] + '\n'
    if growing['email'] != 'none':
        text += growing['email'] + ' ➡ Резюме\n'
    if growing['place'] != 'none':
        text += bold('\n🏘 Адрес\n') + growing['place'] + '\n'
    if growing['metro'] != 'none':
        text += '🚇 ' + growing['metro'] + '\n'

    if kind == 'MainChannel':
        keys = None
        if growing['geo'].lower() != 'none':
            text += '\n📍 <a href="http://maps.yandex.ru/?text=' + growing[
                'geo'] + '">На карте</a>\n'
        text += '\n🔎 <a href="' + pub_link + '">Источник</a>\n'
    else:
        keys = keyboard
        text += code('-------------------\n')
        if growing['geo'].lower() != 'none':
            text += '📍http://maps.yandex.ru/?text=' + growing['geo'] + '\n'
        text += '🔎' + pub_link + '🔎\n'
        text += code('-------------------\n')

    if growing['tags'] != 'none':
        text += objects.italic('\n💼ТЕГИ: ')
        for i in growing['tags']:
            text += '#' + re.sub('_+', '_', i) + ' '
        text = text[:-1] + '\n'

    if growing['short_place'] == 'none' or growing[
            'money'] == 'none' or growing['title'] == 'none':
        text = pub_link

    if growing['title'] != 'none':
        search_restricted = re.search('водитель|яндекс|такси|уборщи',
                                      growing['title'].lower())
        if search_restricted:
            text = pub_link

    if growing['org_name'] != 'none':
        search_restricted = re.search('доброном', growing['org_name'].lower())
        if search_restricted:
            text = pub_link

    if growing['experience'] != 'none':
        search_restricted = re.search('6', growing['experience'].capitalize())
        if search_restricted:
            text = pub_link

    return [text, keys, pub_link, growing]