21
21
22
22
timezone = pytz .timezone ("Asia/Singapore" )
23
23
24
+
24
25
def get_category_text (sheet_id , entry_type ):
25
26
msg = ""
26
27
markup_list = []
@@ -215,7 +216,8 @@ def config_category(update, context) -> int:
215
216
)
216
217
payment_list = gs .get_main_dropdown_value (sheet_id , "Payment" )
217
218
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 ),
219
221
)
220
222
return CS .CONFIG_PAYMENT
221
223
elif config == EntryType .OTHERS :
@@ -264,7 +266,8 @@ def config_payment(update, context) -> int:
264
266
if len (sub_markup_list ) > 1 :
265
267
sub_markup_list .pop (0 )
266
268
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 ),
268
271
)
269
272
return CS .CONFIG_SUBPAYMENT
270
273
except Exception as e :
@@ -347,7 +350,9 @@ def remarks(update: Update, context) -> int:
347
350
return CS .REMARKS
348
351
msg , markup_list = get_category_text (sheet_id , entry_type )
349
352
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
+ )
351
356
return CS .CATEGORY
352
357
except Exception as e :
353
358
update .message .reply_text (ERROR_TEXT )
@@ -367,7 +372,8 @@ def category(update, context) -> int:
367
372
context .user_data ["category" ] = f"{ reply } "
368
373
payment_list = get_payment_text (sheet_id )
369
374
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 ),
371
377
)
372
378
return CS .PAYMENT
373
379
elif entry_type == EntryType .OTHERS :
@@ -434,15 +440,16 @@ def payment(update, context) -> int:
434
440
sub_markup_list .pop (0 )
435
441
sub_markup_list .append (BACK_TEXT )
436
442
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 ),
438
445
)
439
446
return CS .SUBPAYMENT
440
447
# This won't be called as there will always be a subpayment, but just in case
441
448
else :
442
449
update .callback_query .edit_message_text (
443
450
f'Payment type: { context .user_data ["payment" ]} ' , reply_markup = None
444
451
)
445
- if context .user_data [ "backlog" ] :
452
+ if context .user_data . get ( "backlog" ) :
446
453
backlog_transaction (context .user_data , update )
447
454
else :
448
455
log_transaction (context .user_data , update )
@@ -468,7 +475,7 @@ def subpayment(update, context) -> int:
468
475
update .callback_query .edit_message_text (
469
476
f'Payment type: { context .user_data ["payment" ]} ' , reply_markup = None
470
477
)
471
- if context .user_data [ "backlog" ] :
478
+ if context .user_data . get ( "backlog" ) :
472
479
backlog_transaction (context .user_data , update )
473
480
else :
474
481
log_transaction (context .user_data , update )
@@ -560,7 +567,6 @@ def backlog_transaction(user_data, update):
560
567
if backlog_month .title () == month :
561
568
gs .row_incremental_all (sheet_id )
562
569
563
-
564
570
# user input data
565
571
entry_type = user_data ["entry_type" ]
566
572
payment = user_data ["payment" ]
@@ -572,6 +578,7 @@ def backlog_transaction(user_data, update):
572
578
# create backlog entry
573
579
gs .create_backlog_entry (sheet_id , backlog_day , backlog_month , row_data )
574
580
581
+
575
582
def cancel (update , context ):
576
583
update .message .reply_text (END_TEXT , reply_markup = None )
577
584
context .user_data .clear ()
@@ -719,12 +726,16 @@ def handle_get_transaction(update, context):
719
726
total_spend , transport_values , other_values = gs .get_day_transaction (
720
727
sheet_id , month , day
721
728
)
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
+ ):
723
734
update .message .reply_text (
724
735
f"No transaction found for { day } { month } " , reply_markup = None
725
736
)
726
737
return ConversationHandler .END
727
-
738
+
728
739
if not total_spend :
729
740
total_spend = "To be determine"
730
741
else :
@@ -811,7 +822,8 @@ def income(update, context) -> int:
811
822
sheet_id = context .user_data ["sheet_id" ]
812
823
work_list = gs .get_work_place (sheet_id )
813
824
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 ),
815
827
)
816
828
return CS .WORK_PLACE
817
829
except Exception as e :
@@ -851,12 +863,14 @@ def cpf(update, context) -> int:
851
863
update .callback_query .message .reply_text (ERROR_TEXT )
852
864
return ConversationHandler .END
853
865
866
+
854
867
def backlog (update , context ) -> int :
855
868
context .user_data .clear ()
856
869
update .message .reply_text (BACKLOG_DATE_TEXT )
857
870
context .user_data ["backlog" ] = True
858
871
return CS .ADD_BACKLOG_ENTRY
859
872
873
+
860
874
def add_backlog_entry (update , context ) -> int :
861
875
reply = update .message .text
862
876
if utils .check_date_format (reply ):
@@ -869,7 +883,7 @@ def add_backlog_entry(update, context) -> int:
869
883
else :
870
884
update .message .reply_text (BACKLOG_DATE_TEXT )
871
885
return CS .ADD_BACKLOG_ENTRY
872
-
886
+
873
887
telegram_id = update .effective_user .id
874
888
context .user_data ["sheet_id" ] = db .get_user_sheet_id (telegram_id )
875
889
update .message .reply_text (
@@ -880,6 +894,7 @@ def add_backlog_entry(update, context) -> int:
880
894
)
881
895
return CS .ENTRY
882
896
897
+
883
898
def setup_handlers (dispatcher ):
884
899
# Configuration-related states and handlers
885
900
config_states = {
@@ -900,7 +915,9 @@ def setup_handlers(dispatcher):
900
915
CS .SUBCATEGORY : [CallbackQueryHandler (subcategory )],
901
916
CS .PAYMENT : [CallbackQueryHandler (payment )],
902
917
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
+ ],
904
921
}
905
922
906
923
# Quick add-related states and handlers
0 commit comments