@@ -37,6 +37,10 @@ def check_date_format(date_string):
3737 pattern = r"\b\d{1,2}\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b"
3838 return bool (re .fullmatch (pattern , date_string , re .IGNORECASE ))
3939
40+ def check_month_format (month_string ):
41+ pattern = r"^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$"
42+ return bool (re .fullmatch (pattern , month_string , re .IGNORECASE ))
43+
4044
4145def get_category_text (sheet_id , entry_type ):
4246 msg = ""
@@ -608,26 +612,36 @@ def help(update, context):
608612 update .message .reply_text (HELP_TEXT )
609613
610614
611- def retrieve_transaction (update , context ):
615+ def get_day_transaction (update , context ):
612616 context .user_data .clear ()
613617 telegram_id = update .effective_user .id
614618 try :
615619 context .user_data ["sheet_id" ] = db .get_user_sheet_id (telegram_id )
616- update .message .reply_text (RETRIEVE_TRANSACTION_TEXT )
617- return CS .HANDLE_RETRIEVE_TRANSACTION
620+ update .message .reply_text (GET_TRANSACTION_TEXT )
621+ return CS .HANDLE_GET_TRANSACTION
618622 except Exception as e :
619623 update .message .reply_text (ERROR_TEXT )
620624 return ConversationHandler .END
621625
626+ def get_overall (update , context ):
627+ context .user_data .clear ()
628+ telegram_id = update .effective_user .id
629+ try :
630+ context .user_data ["sheet_id" ] = db .get_user_sheet_id (telegram_id )
631+ update .message .reply_text (GET_OVERALL_TEXT )
632+ return CS .HANDLE_GET_OVERALL
633+ except Exception as e :
634+ update .message .reply_text (ERROR_TEXT )
635+ return ConversationHandler .END
622636
623- def handle_retrieve_transaction (update , context ):
637+ def handle_get_transaction (update , context ):
624638 sheet_id = context .user_data ["sheet_id" ]
625639 reply = update .message .text
626640 msg = ""
627641 try :
628642 if check_date_format (reply ):
629643 day , month = reply .split (" " )
630- total_spend , transport_values , other_values = gs .retrieve_transaction (
644+ total_spend , transport_values , other_values = gs .get_day_transaction (
631645 sheet_id , month , day
632646 )
633647 if not total_spend :
@@ -643,11 +657,32 @@ def handle_retrieve_transaction(update, context):
643657 update .message .reply_text (msg )
644658 return ConversationHandler .END
645659 else :
646- update .message .reply_text (RETRIEVE_TRANSACTION_TEXT )
647- return CS .HANDLE_RETRIEVE_TRANSACTION
660+ update .message .reply_text (GET_TRANSACTION_TEXT )
661+ return CS .HANDLE_GET_TRANSACTION
648662 except Exception as e :
649663 update .message .reply_text (ERROR_TEXT )
650664
665+ def handle_get_overall (update , context ):
666+ sheet_id = context .user_data ["sheet_id" ]
667+ month = update .message .text
668+ msg = ""
669+ try :
670+ if check_month_format (month ):
671+ values = gs .get_overall (sheet_id , month )
672+ msg = "```\n "
673+ for row in values :
674+ if len (row ) == 3 :
675+ msg += "{:<20} {:<10} {:<10}\n " .format (* row )
676+ elif len (row ) == 2 :
677+ msg += "{:<20} {:<10}\n " .format (* row )
678+ msg += "```"
679+ update .message .reply_text (msg , parse_mode = 'Markdown' )
680+ return ConversationHandler .END
681+ else :
682+ update .message .reply_text (GET_OVERALL_TEXT )
683+ return CS .HANDLE_GET_OVERALL
684+ except Exception as e :
685+ update .message .reply_text (ERROR_TEXT )
651686
652687def add_income (update , context ):
653688 context .user_data .clear ()
@@ -749,9 +784,12 @@ def setup_handlers(dispatcher):
749784 }
750785
751786 # Retrieve transaction-related states and handlers
752- retrieve_transaction_states = {
753- CS .HANDLE_RETRIEVE_TRANSACTION : [
754- MessageHandler (Filters .text & ~ Filters .command , handle_retrieve_transaction )
787+ get_transaction_states = {
788+ CS .HANDLE_GET_TRANSACTION : [
789+ MessageHandler (Filters .text & ~ Filters .command , handle_get_transaction )
790+ ],
791+ CS .HANDLE_GET_OVERALL : [
792+ MessageHandler (Filters .text & ~ Filters .command , handle_get_overall )
755793 ],
756794 }
757795
@@ -768,15 +806,16 @@ def setup_handlers(dispatcher):
768806 CommandHandler ("addtransport" , add_transport ),
769807 CommandHandler ("addothers" , add_others ),
770808 CommandHandler ("addincome" , add_income ),
771- CommandHandler ("retrievetransaction" , retrieve_transaction ),
809+ CommandHandler ("getdaytransaction" , get_day_transaction ),
810+ CommandHandler ("getoverall" , get_overall )
772811 ],
773812 states = {
774813 CS .SET_UP : [MessageHandler (Filters .text & ~ Filters .command , set_up )],
775814 CS .RESET_UP : [CallbackQueryHandler (reset_up )],
776815 ** config_states ,
777816 ** entry_states ,
778817 ** quick_add_states ,
779- ** retrieve_transaction_states ,
818+ ** get_transaction_states ,
780819 ** add_income_states ,
781820 },
782821 fallbacks = [CommandHandler ("cancel" , cancel )],
0 commit comments