2121
2222timezone = pytz .timezone ("Asia/Singapore" )
2323
24+
2425def get_category_text (sheet_id , entry_type ):
2526 msg = ""
2627 markup_list = []
@@ -215,7 +216,8 @@ def config_category(update, context) -> int:
215216 )
216217 payment_list = gs .get_main_dropdown_value (sheet_id , "Payment" )
217218 update .callback_query .message .reply_text (
218- DEFAULT_PAYMENT_TEXT , reply_markup = utils .create_inline_markup (payment_list )
219+ DEFAULT_PAYMENT_TEXT ,
220+ reply_markup = utils .create_inline_markup (payment_list ),
219221 )
220222 return CS .CONFIG_PAYMENT
221223 elif config == EntryType .OTHERS :
@@ -264,7 +266,8 @@ def config_payment(update, context) -> int:
264266 if len (sub_markup_list ) > 1 :
265267 sub_markup_list .pop (0 )
266268 update .callback_query .message .edit_text (
267- DEFAULT_PAYMENT_TEXT , reply_markup = utils .create_inline_markup (sub_markup_list )
269+ DEFAULT_PAYMENT_TEXT ,
270+ reply_markup = utils .create_inline_markup (sub_markup_list ),
268271 )
269272 return CS .CONFIG_SUBPAYMENT
270273 except Exception as e :
@@ -347,7 +350,9 @@ def remarks(update: Update, context) -> int:
347350 return CS .REMARKS
348351 msg , markup_list = get_category_text (sheet_id , entry_type )
349352 try :
350- update .message .reply_text (msg , reply_markup = utils .create_inline_markup (markup_list ))
353+ update .message .reply_text (
354+ msg , reply_markup = utils .create_inline_markup (markup_list )
355+ )
351356 return CS .CATEGORY
352357 except Exception as e :
353358 update .message .reply_text (ERROR_TEXT )
@@ -367,7 +372,8 @@ def category(update, context) -> int:
367372 context .user_data ["category" ] = f"{ reply } "
368373 payment_list = get_payment_text (sheet_id )
369374 update .callback_query .message .reply_text (
370- DEFAULT_PAYMENT_TEXT , reply_markup = utils .create_inline_markup (payment_list )
375+ DEFAULT_PAYMENT_TEXT ,
376+ reply_markup = utils .create_inline_markup (payment_list ),
371377 )
372378 return CS .PAYMENT
373379 elif entry_type == EntryType .OTHERS :
@@ -434,15 +440,16 @@ def payment(update, context) -> int:
434440 sub_markup_list .pop (0 )
435441 sub_markup_list .append (BACK_TEXT )
436442 update .callback_query .message .edit_text (
437- DEFAULT_PAYMENT_TEXT , reply_markup = utils .create_inline_markup (sub_markup_list )
443+ DEFAULT_PAYMENT_TEXT ,
444+ reply_markup = utils .create_inline_markup (sub_markup_list ),
438445 )
439446 return CS .SUBPAYMENT
440447 # This won't be called as there will always be a subpayment, but just in case
441448 else :
442449 update .callback_query .edit_message_text (
443450 f'Payment type: { context .user_data ["payment" ]} ' , reply_markup = None
444451 )
445- if context .user_data [ "backlog" ] :
452+ if context .user_data . get ( "backlog" ) :
446453 backlog_transaction (context .user_data , update )
447454 else :
448455 log_transaction (context .user_data , update )
@@ -468,7 +475,7 @@ def subpayment(update, context) -> int:
468475 update .callback_query .edit_message_text (
469476 f'Payment type: { context .user_data ["payment" ]} ' , reply_markup = None
470477 )
471- if context .user_data [ "backlog" ] :
478+ if context .user_data . get ( "backlog" ) :
472479 backlog_transaction (context .user_data , update )
473480 else :
474481 log_transaction (context .user_data , update )
@@ -560,7 +567,6 @@ def backlog_transaction(user_data, update):
560567 if backlog_month .title () == month :
561568 gs .row_incremental_all (sheet_id )
562569
563-
564570 # user input data
565571 entry_type = user_data ["entry_type" ]
566572 payment = user_data ["payment" ]
@@ -572,6 +578,7 @@ def backlog_transaction(user_data, update):
572578 # create backlog entry
573579 gs .create_backlog_entry (sheet_id , backlog_day , backlog_month , row_data )
574580
581+
575582def cancel (update , context ):
576583 update .message .reply_text (END_TEXT , reply_markup = None )
577584 context .user_data .clear ()
@@ -719,12 +726,16 @@ def handle_get_transaction(update, context):
719726 total_spend , transport_values , other_values = gs .get_day_transaction (
720727 sheet_id , month , day
721728 )
722- if total_spend == None and transport_values == None and other_values == None :
729+ if (
730+ total_spend == None
731+ and transport_values == None
732+ and other_values == None
733+ ):
723734 update .message .reply_text (
724735 f"No transaction found for { day } { month } " , reply_markup = None
725736 )
726737 return ConversationHandler .END
727-
738+
728739 if not total_spend :
729740 total_spend = "To be determine"
730741 else :
@@ -811,7 +822,8 @@ def income(update, context) -> int:
811822 sheet_id = context .user_data ["sheet_id" ]
812823 work_list = gs .get_work_place (sheet_id )
813824 update .message .reply_text (
814- CHOOSE_INCOME_SOURCE_TEXT , reply_markup = utils .create_inline_markup (work_list )
825+ CHOOSE_INCOME_SOURCE_TEXT ,
826+ reply_markup = utils .create_inline_markup (work_list ),
815827 )
816828 return CS .WORK_PLACE
817829 except Exception as e :
@@ -851,12 +863,14 @@ def cpf(update, context) -> int:
851863 update .callback_query .message .reply_text (ERROR_TEXT )
852864 return ConversationHandler .END
853865
866+
854867def backlog (update , context ) -> int :
855868 context .user_data .clear ()
856869 update .message .reply_text (BACKLOG_DATE_TEXT )
857870 context .user_data ["backlog" ] = True
858871 return CS .ADD_BACKLOG_ENTRY
859872
873+
860874def add_backlog_entry (update , context ) -> int :
861875 reply = update .message .text
862876 if utils .check_date_format (reply ):
@@ -869,7 +883,7 @@ def add_backlog_entry(update, context) -> int:
869883 else :
870884 update .message .reply_text (BACKLOG_DATE_TEXT )
871885 return CS .ADD_BACKLOG_ENTRY
872-
886+
873887 telegram_id = update .effective_user .id
874888 context .user_data ["sheet_id" ] = db .get_user_sheet_id (telegram_id )
875889 update .message .reply_text (
@@ -880,6 +894,7 @@ def add_backlog_entry(update, context) -> int:
880894 )
881895 return CS .ENTRY
882896
897+
883898def setup_handlers (dispatcher ):
884899 # Configuration-related states and handlers
885900 config_states = {
@@ -900,7 +915,9 @@ def setup_handlers(dispatcher):
900915 CS .SUBCATEGORY : [CallbackQueryHandler (subcategory )],
901916 CS .PAYMENT : [CallbackQueryHandler (payment )],
902917 CS .SUBPAYMENT : [CallbackQueryHandler (subpayment )],
903- CS .ADD_BACKLOG_ENTRY : [MessageHandler (Filters .text & ~ Filters .command , add_backlog_entry )],
918+ CS .ADD_BACKLOG_ENTRY : [
919+ MessageHandler (Filters .text & ~ Filters .command , add_backlog_entry )
920+ ],
904921 }
905922
906923 # Quick add-related states and handlers
0 commit comments