Created
February 16, 2020 17:58
-
-
Save sosolidkk/c836370cb24ce0390686cba528df8b48 to your computer and use it in GitHub Desktop.
Gist para fazer parse da data que existe no Sigaa para um padrão mais entendível
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
days = {"2": "Seg", "3": "Ter", "4": "Qua", "5": "Qui", "6": "Sex", "7": "Sab"} | |
shift = {"m": "Manhã", "t": "Tarde", "n": "Noite"} | |
time = { | |
"m": { | |
"12": "06:00 às 08:00", | |
"34": "08:00 às 10:00", | |
"56": "10:00 às 12:00", | |
"3456": "08:00 às 12:00", | |
}, | |
"t": { | |
"34": "14:00 às 16:00", | |
"56": "16:00 às 18:00", | |
"345": "14:00 às 17:00", | |
"3456": "14:00 às 18:00", | |
}, | |
"n": { | |
"12": "18:00 às 20:00", | |
"34": "20:00 às 22:00", | |
"123": "18:00 às 21:00", | |
"1234": "18:00 às 22:00", | |
}, | |
} | |
def date_parser(date): | |
date = date.split(" ") | |
print(date) | |
if len(date) == 1: | |
shift_index = -1 | |
for i, c in enumerate(list(date[0])): | |
try: | |
int(c) | |
except: | |
shift_index = i | |
_day = ", ".join([days[day] for day in date[0][:shift_index]]) | |
_shift = shift[date[0][shift_index].lower()] | |
_time = time[date[0][shift_index].lower()][date[0][shift_index + 1 :]] | |
return f"{_day} pela {_shift} de {_time}" | |
elif len(date) > 1: | |
result = [] | |
for item in date: | |
result.append(date_parser(item)) | |
return result | |
print(date_parser("23m3456")) | |
print(date_parser("6M3456")) | |
print(date_parser("24T34")) | |
print(date_parser("6T56 23456N1234")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment