I have the code like below:
if text == 'today':
    date1, date2 = dt.today_()
    result, data = ga.get_sessions_today_data(user_id, date1, date2)
    result, data, caption = get_final_caption(result, data, date1, date2, 'hour', 'sessions')
    handle_result(chat_id, result, data, caption)
elif text == 'yesterday':
    date1, date2 = dt.yesterday()
    result, data = ga.get_sessions_today_data(user_id, date1, date2)
    result, data, caption = get_final_caption(result, data, date1, end_date, 'hour', 'sessions')
    handle_result(chat_id, result, data, caption)
...
The code is repeated many-many times, just dt.function() and ga.function() are different. How could I optimize the code?
 
    