Skip to content

Commit

Permalink
fix category bug
Browse files Browse the repository at this point in the history
  • Loading branch information
shayki5 committed Jun 13, 2024
1 parent c8d852c commit 0e99d0f
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
import sys
import time
from datetime import datetime

# Telegram bot token
TOKEN = os.getenv('TOKEN')
Expand Down Expand Up @@ -34,29 +35,29 @@ def get_data_from_sheets_on_start():
# Reset states
states = {'not_found_values': [], 'current_index': 0}
# Get all values from column D
column_d_values = sheet.col_values(4)[-20:]
print(column_d_values)
column_d_values = sheet.col_values(4)[-15:]
#print(column_d_values)

column_d_values_full = sheet.col_values(4)
# Reverse the list of column D values
reversed_column_d_values = column_d_values_full[::-1]
# Get the indices of each cell in the last 20 values from column D
indices = [len(column_d_values_full) - 1 - reversed_column_d_values.index(value) for value in column_d_values]
# Get the index of the first cell among the last 20 values
first_cell_index = min(indices)
# Print the index
print("Index of the first cell in the last 20 values in column D:", first_cell_index+1)
column_d = sheet.col_values(4)[1:]

for index, value in enumerate(column_d_values, start=first_cell_index+1):
last_15_cells = [(row, value) for row, value in enumerate(column_d[-15:], start=len(column_d) - 13)]

for row, value in last_15_cells:
first_cell_index = row
break

print("Index of the first cell in the last 15 values in column D:", first_cell_index)

for index, value in enumerate(column_d_values, start=first_cell_index):
corresponding_value_e = sheet.cell(index, 5).value
print(f"name: {value}, category: {corresponding_value_e}")
#print(f"name: {value}, category: {corresponding_value_e}")
if corresponding_value_e == "not found":
states['not_found_values'].append(value)
if states['not_found_values']:
requests.get(WHATSAPP_URL)
ask_user_for_input()
else:
print("no empty categories found.")
print("No empty categories found.")
bot.stop_polling()
sys.exit()

Expand Down

0 comments on commit 0e99d0f

Please sign in to comment.