Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/pycamp_bot/commands/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from pycamp_bot.commands.base import msg_to_active_pycamp_chat
from pycamp_bot.commands.manage_pycamp import active_needed, get_active_pycamp
from pycamp_bot.commands.auth import admin_needed, get_admins_username
from pycamp_bot.commands.schedule import DIAS
from pycamp_bot.utils import escape_markdown
from pycamp_bot.utils import escape_markdown, get_slot_weekday_name

current_projects = {}

Expand Down Expand Up @@ -546,7 +545,7 @@ async def show_my_projects(update, context):

for vote in votes:
slot_day_code = vote.project.slot.code[0]
slot_day_name = DIAS[slot_day_code]
slot_day_name = get_slot_weekday_name(slot_day_code)

if slot_day_code != prev_slot_day_code:
text_chunks.append(f'*{slot_day_name}*')
Expand Down
36 changes: 15 additions & 21 deletions src/pycamp_bot/commands/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pycamp_bot.commands.auth import admin_needed
from pycamp_bot.scheduler.db_to_json import export_db_2_json
from pycamp_bot.scheduler.schedule_calculator import export_scheduled_result
from pycamp_bot.utils import escape_markdown
from pycamp_bot.utils import escape_markdown, get_slot_weekday_name


DAY_SLOT_TIME = {
Expand All @@ -14,17 +14,6 @@
}


DIAS = {
'A':'Jueves',
'B':'Viernes',
'C':'Sabado',
'D':'Domingo',
'E':'Lunes',
'F':'Martes',
'G':'Miercoles',
}


async def cancel(update, context):
await context.bot.send_message(
chat_id=update.message.chat_id,
Expand Down Expand Up @@ -153,29 +142,34 @@ async def make_schedule(update, context):
)


async def check_day_tab(day, slots, cronograma, i):
try:
if day != DIAS[slots[i-1].code[0]]:
cronograma.append('')
cronograma.append(f'*{day}:*')
except Exception as e:
print("ERROR ", e)
async def check_day_tab(slot, prev_slot, cronograma):
def append_day_name():
cronograma.append(f'*{get_slot_weekday_name(slot.code[0])}:*')

if prev_slot is None:
append_day_name()
elif slot.code[0] != prev_slot.code[0]:
cronograma.append('')
append_day_name()


async def show_schedule(update, context):
slots = Slot.select()
projects = Project.select()
cronograma = []

prev_slot = None

for i, slot in enumerate(slots):
day = DIAS[slot.code[0]]
await check_day_tab(day, slots, cronograma, i)
await check_day_tab(slot, prev_slot, cronograma)

for project in projects:
if project.slot_id == slot.id:
cronograma.append(f'{slot.start}:00 *{escape_markdown(project.name)}*')
cronograma.append(f'Owner: @{escape_markdown(project.owner.username)}')

prev_slot = slot

await context.bot.send_message(
chat_id=update.message.chat_id,
text='\n'.join(cronograma),
Expand Down
23 changes: 23 additions & 0 deletions src/pycamp_bot/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pycamp_bot.models import Pycamp

def escape_markdown(string):
# See: https://core.telegram.org/bots/api#markdownv2-style

Expand All @@ -7,3 +9,24 @@ def escape_markdown(string):
new_string = new_string.replace(char, f'\\{char}')

return new_string


def get_slot_weekday_name(slot_day_code):
ISO_WEEKDAY_NAMES = {
0: 'Lunes',
1: 'Martes',
2: 'Miércoles',
3: 'Jueves',
4: 'Viernes',
5: 'Sábado',
6: 'Domingo',
}

pycamp_start_weekday = Pycamp.get(Pycamp.active == True).init.weekday()

# Convert slot day code to a zero-based code, to use it as an
# offset to get the weekday name of the slot
offset = ord(slot_day_code) - ord('A')
day_name = ISO_WEEKDAY_NAMES[pycamp_start_weekday + offset]

return day_name