def choose_groups(chat_id, to_add):
    """
    Предлагает юзеру выбрать группы для подписки/отписки
    :param chat_id: ID юзера
    :param to_add: Если True, то диалог добавления, если False - удаления
    """
    storage = Shelver(config.database_file)
    global list_of_buttons
    list_of_usergroups = storage.find_all('.*_users')
    list_of_buttons = [elem[:-6] for elem in list_of_usergroups]
    markup = types.ReplyKeyboardMarkup()
    # Позволяем ресайзить клаву
    markup.resize_keyboard = True
    # Если добавляем
    if to_add:
        for i in range(len(list_of_buttons)):
            if chat_id not in storage.get(list_of_usergroups[i]):
                markup.row('/{0}:+{1}'.format('group' + str(i), list_of_buttons[i]))
        markup.row('/0:Закрыть')
        tb.send_message(chat_id, 'Выберите нужные категории. Как закончите - нажмите "Закрыть"',
                        reply_markup=markup)
        list_users_to_subscribe.append(chat_id)
    if not to_add:
        for i in range(len(list_of_buttons)):
            if chat_id in storage.get(list_of_usergroups[i]):
                markup.row('/{0}:-{1}'.format('group' + str(i), list_of_buttons[i]))
        markup.row('/0:Закрыть')
        tb.send_message(chat_id, 'Выберите нужные категории. Как закончите - нажмите "Закрыть"',
                        reply_markup=markup)
        list_users_to_unsibscribe.append(chat_id)
Beispiel #2
0
def get_token():
    """
    Получает токен из локального хранилища
    :return: (str) значение токена
    """
    # Небольшой хак, чтобы хранилище всегда было в корне проекта
    storage = Shelver(os.path.join(os.path.dirname(__file__), config.database_file))
    return storage.get('token')
def get_token():
    """
    Получает токен из локального хранилища
    :return: (str) значение токена
    """
    # Небольшой хак, чтобы хранилище всегда было в корне проекта
    storage = Shelver(os.path.join(os.path.dirname(__file__), config.database_file))
    return storage.get('token')
Beispiel #4
0
# -*- coding: utf-8 -*-
"""
При изменении списка групп, необходимо запустить этот файл
"""

from shelver import Shelver
from config import database_file, categories, cat_entries


list_categories = categories.split(',')
list_entries = cat_entries.split('\n')
storage = Shelver(database_file)
if len(list_categories) != len(list_entries):
    print('Размерности массивов не совпадают! Проверьте списки.')
else:
    for i in range(len(list_categories)):
        for j in range(len(list_entries[i].split(','))):
            print('Inserting {0} into {1}'.format(list_entries[i].split(',')[j], list_categories[i]))
            storage.append(list_categories[i], list_entries[i].split(',')[j].strip(), strict=False)

print(len(storage.get('Новости')[1]))




Beispiel #5
0
def get_list_of_groups_in_category(category_name):
    storage = Shelver(config.database_file)
    return storage.get(category_name.strip())
def get_list_of_groups_in_category(category_name):
    storage = Shelver(config.database_file)
    return storage.get(category_name.strip())
# -*- coding: utf-8 -*-

from shelver import Shelver
import shelve
import config

storage = Shelver(config.database_file)
print(config.categories)
for entry in config.categories.split(','):
    storage.save(entry.strip(), [])
    storage.save(entry.strip() + config.users_db_postfix, [])

list_categories = config.categories.split(',')
list_entries = config.cat_entries.split('\n')
if len(list_categories) != len(list_entries):
    print('Размерности массивов не совпадают! Проверьте списки.')
else:
    for i in range(len(list_categories)):
        for j in range(len(list_entries[i].split(','))):
            print('Inserting {0} into {1}'.format(
                list_entries[i].split(',')[j], list_categories[i]))
            storage.append(list_categories[i],
                           list_entries[i].split(',')[j].strip(),
                           strict=True)

print(len(storage.get('News')[1]))

storage.save('expire_time', 0)
storage.save('token', 0)
storage.close()
#!/usr/bin/python3.4
# -*- coding: utf-8 -*-

from shelver import Shelver
import shelve
import config

storage = Shelver(config.database_file)
print(config.categories)
for entry in config.categories.split(","):
    storage.save(entry.strip(), [])
    storage.save(entry.strip() + config.users_db_postfix, [])


list_categories = config.categories.split(",")
list_entries = config.cat_entries.split("\n")
if len(list_categories) != len(list_entries):
    print("Размерности массивов не совпадают! Проверьте списки.")
else:
    for i in range(len(list_categories)):
        for j in range(len(list_entries[i].split(","))):
            print("Inserting {0} into {1}".format(list_entries[i].split(",")[j], list_categories[i]))
            storage.append(list_categories[i], list_entries[i].split(",")[j].strip(), strict=True)

print(len(storage.get("News")[1]))


storage.save("expire_time", 0)
storage.save("token", 0)
storage.close()