def process(self): sl_repository = SpendingLogRepository(l0qh4.get('db')) spendingcategories = l0qh4.get('spendingcategories') log = sl_repository.find_first(telegram_message_id=self.update.message. reply_to_message.message_id) self.reply(text='\n'.join([ '```', '{:4} {}'.format('#id', log.get_id()), '{:4} {}'.format('sbj', log.get_subject()), '{:4} {}'.format('amt', log.get_amount(human_format=True)), '{:4} {:}'.format('cat', log.get_category_name()), '```' ]), parse_mode=telegram.ParseMode.MARKDOWN_V2)
def execute(self, log: Log, configs: dict = {}): flag_listall = configs.get('list_all', False) wordcategorymap = dict() for word in log.get_subject_words(): wcmapresultset = self._swc_repository.find_all(word=word) for wcmap in wcmapresultset: if wcmap.category_id in wordcategorymap: wordcategorymap[wcmap.category_id] += wcmap.score else: wordcategorymap[wcmap.category_id] = wcmap.score categories = l0qh4.get('spendingcategories') if len(wordcategorymap) == 0 or flag_listall == True: proposed_categories = [{ "id": category.id, "name": self._get_name(category) } for category in categories.listall()] else: wordcategorymap = sorted(wordcategorymap.items(), reverse=True, key=lambda x: x[1]) proposed_categories = [{ "id": category.id, "name": self._get_name(category) } for category in categories.list_byids( [ca[0] for ca in wordcategorymap])] return proposed_categories
def is_authorized(self) -> bool: tlg_username = self.username if tlg_username is None: return False users = l0qh4.get('users') if not users.is_active(telegram_username=tlg_username): return False chat_info = self.update.message.chat if chat_info.type == 'group' and chat_info.id not in self.__chatgroup_ids: return False return True
def process(self): log_message = LogMessage(self.get_messagecontent()) db = l0qh4.get('db') addlog_service = AddLogService() log = addlog_service.execute({ "subject" : log_message.subject(), "amount" : log_message.amount(), "payment_method" : log_message.payment_method(), "transaction_type" : log_message.transaction_type(), "created_by" : self.username, "telegram_message_id" : self.message_id })
def _editlog(self): """ Update on edit message """ db = l0qh4.get('db') sl_repository = SpendingLogRepository(db) log = sl_repository.find_first( telegram_message_id=self.update.edited_message.message_id) log_message = LogMessage(self.update.edited_message.text) if log is None or not log_message.is_valid(): return log.set_subject(log_message.subject()) log.set_amount(log_message.amount()) log.set_payment_method(log_message.payment_method()) log.set_transaction_type(log_message.transaction_type()) sl_repository.store(log)
def process(self): logs = self._sl_repository.find_intimerange('today') totalamount = sum([log.get_amount() for log in logs]) if self.hasOption('d') is True: users = l0qh4.get('users') spendingrows = [ '[{}] {:10.10} | {:<3}'.format( users.get_alias(telegram_username=log.get_created_by()), log.get_subject(), log.get_amount(human_format=True)) for log in logs ] self.reply(text='\n'.join([ '```', '\n'.join(spendingrows), '{:=>20}'.format('='), f'Tổng cộng: {totalamount:,}', '```' ]), parse_mode=telegram.ParseMode.MARKDOWN_V2) return else: self.reply(f'Tổng cộng hôm nay: {totalamount:,}') return
def __init__(self): self._sl_repository = SpendingLogRepository(l0qh4.get('db'))
def __init__(self): db = l0qh4.get('db') self._sl_repository = SpendingLogRepository(db) self._swc_repository = SpendingWordCategoryRepository(db) self._scategories = l0qh4.get('spendingcategories')
def __init__(self): self._sl_repository = SpendingLogRepository(l0qh4.get('db')) self._spendingcategories = l0qh4.get('spendingcategories')
def _onconstruct(self): self._sl_repository = SpendingLogRepository(l0qh4.get('db')) self._scategories = l0qh4.get('spendingcategories')
def process(self): categories = l0qh4.get('spendingcategories').listall() content = [f'{cate.id:2} {cate.name:10}' for cate in categories] self.reply('\n'.join(['```', '\n'.join(content), '```']), parse_mode=telegram.ParseMode.MARKDOWN_V2)
def is_authorized(self) -> bool: tlg_username = self.username if tlg_username is None: return False users = l0qh4.get('users') return users.is_active(telegram_username=tlg_username)
def __init__(self): self._sl_repository = SpendingLogRepository(l0qh4.get('db')) self._swc_repository = SpendingWordCategoryRepository(l0qh4.get('db'))
def __init__(self): db = l0qh4.get('db') self._swc_repository = SpendingWordCategoryRepository(db)
def get_category(self): categories = l0qh4.get('spendingcategories') return categories.get(self.get_category_id())