Skip to content

Commit 0c1b70e

Browse files
committed
Adds correct time start to slots table and show_schedule
1 parent 83ab496 commit 0c1b70e

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

src/pycamp_bot/commands/schedule.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
from pycamp_bot.scheduler.schedule_calculator import export_scheduled_result
77

88

9-
DAY_LETTERS = []
9+
DAY_SLOT_TIME = {
10+
'day':[], # Guarda el codigo del dia ej: ['A','B']
11+
'slot':[], # Guarda la cantidad de slots del dia iterado ej [5] (se sobreescribe)
12+
'time':[], # Guarda la hora a la que empieza el dia iterado [15] (se sobreescribe)
13+
}
1014

1115

1216
def _dictToString(dicto):
@@ -56,8 +60,8 @@ async def define_slot_days(update, context):
5660
return 1
5761

5862

59-
async def define_slot_times(update, context):
60-
global DAY_LETTERS
63+
async def define_slot_ammount(update, context):
64+
global DAY_SLOT_TIME
6165
text = update.message.text
6266
if text not in ["1", "2", "3", "4", "5", "6", "7"]:
6367
await context.bot.send_message(
@@ -66,24 +70,38 @@ async def define_slot_times(update, context):
6670
)
6771
return 1
6872

69-
DAY_LETTERS = list(string.ascii_uppercase[0:int(text)])
73+
74+
DAY_SLOT_TIME['day'] =list(string.ascii_uppercase[0:int(text)])
7075

7176
await context.bot.send_message(
7277
chat_id=update.message.chat_id,
73-
text="Cuantos slots tiene tu dia {}".format(DAY_LETTERS[0])
78+
text="Cuantos slots tiene tu dia {}".format(DAY_SLOT_TIME['day'][0])
7479
)
7580
return 2
7681

82+
async def define_slot_times(update, context):
83+
text = update.message.text
84+
day = DAY_SLOT_TIME['day'][0]
85+
await context.bot.send_message(
86+
chat_id=update.message.chat_id,
87+
text="A que hora empieza tu dia {}".format(day)
88+
)
89+
DAY_SLOT_TIME['slot'] = [text]
90+
return 3
91+
7792

7893
async def create_slot(update, context):
7994
username = update.message.from_user.username
8095
chat_id = update.message.chat_id
8196
text = update.message.text
82-
times = list(range(int(text)+1))[1:]
83-
starting_hour = 10
97+
98+
DAY_SLOT_TIME['time'] = [text]
99+
slot_amount = DAY_SLOT_TIME['slot'][0]
100+
times = list(range(int(slot_amount)+1))[1:]
101+
starting_hour = int(text)
84102

85103
while len(times) > 0:
86-
new_slot = Slot(code=str(DAY_LETTERS[0]+str(times[0])))
104+
new_slot = Slot(code=str(DAY_SLOT_TIME['day'][0]+str(times[0])))
87105
new_slot.start = starting_hour
88106

89107
pycampista = Pycampista.get_or_create(username=username, chat_id=chat_id)[0]
@@ -93,12 +111,12 @@ async def create_slot(update, context):
93111
times.pop(0)
94112
starting_hour += 1
95113

96-
DAY_LETTERS.pop(0)
114+
DAY_SLOT_TIME['day'].pop(0)
97115

98-
if len(DAY_LETTERS) > 0:
116+
if len(DAY_SLOT_TIME['day']) > 0:
99117
await context.bot.send_message(
100118
chat_id=update.message.chat_id,
101-
text="Cuantos slots tiene tu dia {}".format(DAY_LETTERS[0])
119+
text="Cuantos slots tiene tu dia {}".format(DAY_SLOT_TIME['day'][0])
102120
)
103121
return 2
104122
else:
@@ -137,11 +155,11 @@ async def show_schedule(update, context):
137155
cronograma = {}
138156

139157
for slot in slots:
140-
cronograma[slot.code] = []
158+
cronograma[f'({slot.code}) {slot.start}:00hs'] = []
141159
for project in projects:
142160
if project.slot_id == slot.id:
143-
cronograma[slot.code].append(project.name)
144-
cronograma[slot.code].append('@' + project.owner.username)
161+
cronograma[f'({slot.code}) {slot.start}:00hs'].append(project.name)
162+
cronograma[f'({slot.code}) {slot.start}:00hs'].append('@' + project.owner.username)
145163

146164
await context.bot.send_message(
147165
chat_id=update.message.chat_id,
@@ -189,8 +207,9 @@ async def change_slot(update, context):
189207
load_schedule_handler = ConversationHandler(
190208
entry_points=[CommandHandler('cronogramear', define_slot_days)],
191209
states={
192-
1: [MessageHandler(filters.TEXT, define_slot_times)],
193-
2: [MessageHandler(filters.TEXT, create_slot)]},
210+
1: [MessageHandler(filters.TEXT, define_slot_ammount)],
211+
2: [MessageHandler(filters.TEXT, define_slot_times)],
212+
3: [MessageHandler(filters.TEXT, create_slot)]},
194213
fallbacks=[CommandHandler('cancel', cancel)])
195214

196215

0 commit comments

Comments
 (0)