|
4 | 4 | from pycamp_bot.commands.auth import admin_needed |
5 | 5 | from pycamp_bot.scheduler.db_to_json import export_db_2_json |
6 | 6 | from pycamp_bot.scheduler.schedule_calculator import export_scheduled_result |
7 | | -from pycamp_bot.utils import escape_markdown |
| 7 | +from pycamp_bot.utils import escape_markdown, get_slot_weekday_name |
8 | 8 |
|
9 | 9 |
|
10 | 10 | DAY_SLOT_TIME = { |
|
14 | 14 | } |
15 | 15 |
|
16 | 16 |
|
17 | | -DIAS = { |
18 | | - 'A':'Jueves', |
19 | | - 'B':'Viernes', |
20 | | - 'C':'Sabado', |
21 | | - 'D':'Domingo', |
22 | | - 'E':'Lunes', |
23 | | - 'F':'Martes', |
24 | | - 'G':'Miercoles', |
25 | | - } |
26 | | - |
27 | | - |
28 | 17 | async def cancel(update, context): |
29 | 18 | await context.bot.send_message( |
30 | 19 | chat_id=update.message.chat_id, |
@@ -153,29 +142,34 @@ async def make_schedule(update, context): |
153 | 142 | ) |
154 | 143 |
|
155 | 144 |
|
156 | | -async def check_day_tab(day, slots, cronograma, i): |
157 | | - try: |
158 | | - if day != DIAS[slots[i-1].code[0]]: |
159 | | - cronograma.append('') |
160 | | - cronograma.append(f'*{day}:*') |
161 | | - except Exception as e: |
162 | | - print("ERROR ", e) |
| 145 | +async def check_day_tab(slot, prev_slot, cronograma): |
| 146 | + def append_day_name(): |
| 147 | + cronograma.append(f'*{get_slot_weekday_name(slot.code[0])}:*') |
| 148 | + |
| 149 | + if prev_slot is None: |
| 150 | + append_day_name() |
| 151 | + elif slot.code[0] != prev_slot.code[0]: |
| 152 | + cronograma.append('') |
| 153 | + append_day_name() |
163 | 154 |
|
164 | 155 |
|
165 | 156 | async def show_schedule(update, context): |
166 | 157 | slots = Slot.select() |
167 | 158 | projects = Project.select() |
168 | 159 | cronograma = [] |
169 | 160 |
|
| 161 | + prev_slot = None |
| 162 | + |
170 | 163 | for i, slot in enumerate(slots): |
171 | | - day = DIAS[slot.code[0]] |
172 | | - await check_day_tab(day, slots, cronograma, i) |
| 164 | + await check_day_tab(slot, prev_slot, cronograma) |
173 | 165 |
|
174 | 166 | for project in projects: |
175 | 167 | if project.slot_id == slot.id: |
176 | 168 | cronograma.append(f'{slot.start}:00 *{escape_markdown(project.name)}*') |
177 | 169 | cronograma.append(f'Owner: @{escape_markdown(project.owner.username)}') |
178 | 170 |
|
| 171 | + prev_slot = slot |
| 172 | + |
179 | 173 | await context.bot.send_message( |
180 | 174 | chat_id=update.message.chat_id, |
181 | 175 | text='\n'.join(cronograma), |
|
0 commit comments