def remove_from_subscribers(chat_id, user_id):
        file = open(Helper.file_path('subscribers/%s.txt' % chat_id), 'r')
        lines = file.readlines()
        file.close()

        file = open(Helper.file_path('subscribers/%s.txt' % chat_id), 'w')
        for line in lines:
            if line.rstrip() != str(user_id):
                file.write(line)
        file.close()
    def add_to_subscribers(chat_id, user_id):
        if os.path.exists(Helper.file_path('subscribers/%s.txt' % chat_id)):
            with open(Helper.file_path('subscribers/%s.txt' % chat_id),
                      'r') as data_file:
                for line in data_file:
                    if str(user_id) in line.rstrip():
                        return

        with open(Helper.file_path('subscribers/%s.txt' % chat_id),
                  'a+') as data_file:
            data_file.write(str(user_id) + '\n')
Ejemplo n.º 3
0
    def write_to_orders_file(chat_id, message_id, user, drink):
        order_count = 0
        for line in open(
                Helper.file_path('orders/%s-%s.txt' % (chat_id, message_id)),
                'r'):
            if ' - ' in line:
                order_count += 1

        order_count += 1

        with open(Helper.file_path('orders/%s-%s.txt' % (chat_id, message_id)),
                  'a+') as data_file:
            data_file.write('%d. %s - %s\n' % (order_count, user, drink))
Ejemplo n.º 4
0
    def update_orders_in_group(bot, chat_id, message_id):
        with open(Helper.file_path('orders/%s-%s.txt' % (chat_id, message_id)),
                  'r') as data_file:
            orders = data_file.read()

        bot.edit_message_text(text=orders,
                              chat_id=chat_id,
                              message_id=message_id)
    def send_notification_to_subscribers(bot, update, message):
        with open(Helper.file_path('subscribers/%s.txt' % update.message.chat.id), 'r') as data_file:
            for line in data_file:
                # bot.send_message(chat_id=line.rstrip(),
                #                  text='%s volunteered to be the kopi boy/girl, order now or else...'
                #                  % update.message.from_user.first_name,
                #                  reply_markup=KeyboardHandler().keyboard_reply_markup(message))

                try:
                    bot.send_message(chat_id=line.rstrip(),
                                     text="Stanly's Coffee is now open, please place your order:",
                                     reply_markup=KeyboardHandler().keyboard_reply_markup(message))
                except TelegramError as error:
                    logging.warning('Unable to notify subscriber "%s", error: "%s"' % (line.rstrip(), error))
    def generate_drink_combis(self):
        # Read drinks.json so that keyboard can be populated later
        with open(Helper.file_path('drinks.json')) as data_file:
            drinks_data = json.load(data_file)

        drinks = drinks_data['0']
        combinations = []

        for i in range(1, 5):
            iterables = [drinks]

            for j in range(1, i + 1):
                iterables.append(drinks_data[str(j)])

            for combination in itertools.product(*iterables):
                combinations.append('-'.join(combination))

        return combinations
Ejemplo n.º 7
0
    def update_done_order(bot, chat_id, item_num):
        list_of_orders_in_chat = glob.glob(
            Helper.file_path('orders/%s-*.txt' % (chat_id)))
        latest_order_file = max(list_of_orders_in_chat, key=os.path.getctime)

        row_to_find = str(item_num) + '.'

        final_order_message = ''
        with open(latest_order_file, 'r') as data_file:
            for line in data_file:
                if line.startswith(row_to_find):
                    line = line.rstrip() + ' [done]\n'

                final_order_message = final_order_message + line

        with open(latest_order_file, 'w') as data_file:
            data_file.write(final_order_message)

        message_id = re.search('(\d+)\.txt', latest_order_file)[1]

        bot.edit_message_text(text=final_order_message,
                              chat_id=chat_id,
                              message_id=message_id)
def read_config_file():
    with open(Helper.file_path('firebase_config.json')) as config_file:
        config = json.load(config_file)
    return config
Ejemplo n.º 9
0
 def create_orders_file(chat_id, message_id, opening_message):
     with open(Helper.file_path('orders/%s-%s.txt' % (chat_id, message_id)),
               'a+') as data_file:
         data_file.write('%s\n\n' % opening_message)