def add_timestamp(colum): sheet = googleConnect.getSheet() timeFormat = "%y-%m-%d-%H-%M" eastern = timezone('US/Eastern') timestamp = datetime.now(eastern).strftime(timeFormat) sheet.update_cell(colum, 1, timestamp)
def expenses(msg): sheet = googleConnect.getSheet(2) spending = 0.0 chat_id = msg['chat']['id'] date = msg['text'] for x in sheet.findall(date): if(x.row == 1): spending = sheet.cell(2,(x.col)).value print("Expense for: {} is {}€".format(date, spending)) bot.sendMessage(chat_id, "Expense for: {} is {}€".format(date, spending))
def compare_price_description_length(): sheet = googleConnect.getSheet() columValue = len(sheet.col_values(VALUES_COLUM)) + 1 columDescription = len(sheet.col_values(DESCRIPTION_COLUM)) + 1 if columValue > columDescription: return "Please enter the description." elif columValue < columDescription: return "Please enter the value." else: return "All values added."
def add_value_to_sheet(msg): sheet = googleConnect.getSheet() if (check_if_value_is_number(msg)): # add price columEntries = len(sheet.col_values(VALUES_COLUM)) + 1 sheet.update_cell(columEntries, VALUES_COLUM, msg) add_timestamp(columEntries) else: # add description columEntries = len(sheet.col_values(DESCRIPTION_COLUM)) + 1 sheet.update_cell(columEntries, DESCRIPTION_COLUM, msg) add_timestamp(columEntries)
def handle_command(msg, chatId): sheet = googleConnect.getSheet() if msg == "/month": final_response = "Your expenses are: \n" # position where monthly expenses are calculated in google sheets row = 1 colum = 7 # generates message for each month that has expenses while True: month = sheet.cell(row, colum).value monthly_expense = sheet.cell(row + 1, colum).value if month == "": break monthly_respsonse = month + ": " + monthly_expense + "\n" final_response += monthly_respsonse colum += 1 send_message(final_response, chatId)
def addPrice(msg): sheet = googleConnect.getSheet(2) chat_id = msg['chat']['id'] global value global place global checkPlace global checkValue timestamp = datetime.datetime.now().strftime("%y-%m-%d-%H-%M") print("Adding Values to spreadsheet") print("Value: {}".format(value)) print("Place: {}".format(place)) print("timestamp: {}".format(timestamp)) columEntries = len(sheet.col_values(1))+1 sheet.update_cell(columEntries, 1, timestamp) sheet.update_cell(columEntries, 2, value) sheet.update_cell(columEntries, 3, place) sheet.update_cell(columEntries, 4, timestamp[:5]) checkPlace = False checkValue = False bot.sendMessage(chat_id, "Values added.")