async def shortcut(self, ctx, shortcut=None): """Informations about subject specified by its shorcut""" if not shortcut: await ctx.send(utils.fill_message("shorcut_format", command=ctx.invoked_with)) return programme = review_repo.get_programme(shortcut.upper()) if programme: embed = discord.Embed(title=programme.shortcut, description=programme.name) embed.add_field(name="Link", value=programme.link) else: subject = review_repo.get_subject_details(shortcut.lower()) if not subject: await ctx.send(messages.review_wrong_subject) return embed = discord.Embed(title=subject.shortcut, description=subject.name) if subject.semester == "L": embed.add_field(name="Semestr", value="Letní") else: embed.add_field(name="Semestr", value="Zimní") embed.add_field(name="Typ", value=subject.type) if subject.year: embed.add_field(name="Ročník", value=subject.year) embed.add_field(name="Kredity", value=subject.credits) embed.add_field(name="Ukončení", value=subject.end) embed.add_field(name="Karta předmětu", value=subject.card, inline=False) embed.add_field( name="Statistika úspěšnosti předmětu", value=f"http://fit.nechutny.net/?detail={subject.shortcut}", inline=False, ) utils.add_author_footer(embed, ctx.author) await ctx.send(embed=embed)
async def shortcut(self, ctx, shortcut=None): """Informations about subject specified by its shorcut""" if not shortcut: await ctx.send( utils.fill_message("shorcut_format", command=ctx.invoked_with)) return programme = review_repo.get_programme(shortcut.upper()) if programme: embed = disnake.Embed(title=programme.shortcut, description=programme.name) embed.add_field(name="Link", value=programme.link) else: subject = review_repo.get_subject_details(shortcut) if not subject: subject = review_repo.get_subject_details(f"TV-{shortcut}") if not subject: await ctx.send(messages.review_wrong_subject) return embed = disnake.Embed(title=subject.shortcut, description=subject.name) if subject.semester == "L": semester_value = "Letní" if subject.semester == "Z": semester_value = "Zimní" else: semester_value = "Zimní, Letní" embed.add_field(name="Semestr", value=semester_value) embed.add_field(name="Typ", value=subject.type) if subject.year: embed.add_field(name="Ročník", value=subject.year) embed.add_field(name="Kredity", value=subject.credits) embed.add_field(name="Ukončení", value=subject.end) if "*" in subject.name: embed.add_field(name="Upozornění", value="Předmět není v tomto roce otevřen", inline=False) if subject.shortcut.startswith("TV-"): embed.add_field( name="Rozvrh předmětu v IS", value= f"https://www.vut.cz/studis/student.phtml?sn=rozvrhy&action=gm_rozvrh_predmetu&operation=rozvrh&predmet_id={subject.card}&fakulta_id=814", inline=False) else: embed.add_field( name="Karta předmětu", value= f"https://www.fit.vut.cz/study/course/{subject.shortcut}/.cs", inline=False) embed.add_field( name="Statistika úspěšnosti předmětu", value=f"http://fit.nechutny.net/?detail={subject.shortcut}", inline=False, ) utils.add_author_footer(embed, ctx.author) await ctx.send(embed=embed)
def update_subject_types(self, link, MIT): """Send request to `link`, parse page and find all subjects. Add new subjects to DB, if subject already exists update its years. For MITAI links please set `MIT` to True. If update succeeded return True, otherwise False """ response = requests.get(link) if response.status_code != 200: return False soup = BeautifulSoup(response.content, "html.parser") tables = soup.select("table") # remove last table with information about PVT and PVA subjects (applicable mainly for BIT) if len(tables) % 2: tables = tables[:-1] # specialization shortcut for correct year definition in DB specialization = soup.select("main p strong")[0].get_text() full_specialization = soup.select("h1")[0].get_text() if not review_repo.get_programme(specialization): review_repo.set_programme(specialization, full_specialization, link) sem = 1 year = 1 for table in tables: rows = table.select("tbody tr") for row in rows: shortcut = row.find_all("th")[0].get_text() # update subject DB if not review_repo.get_subject(shortcut.lower()).first(): review_repo.add_subject(shortcut.lower()) columns = row.find_all("td") type = columns[2].get_text() degree = "BIT" for_year = "VBIT" if type == "P": if MIT and year > 2: # any year for_year = f"L{specialization}" else: for_year = f"{year}{specialization}" else: if MIT: for_year = "VMIT" if MIT: degree = "MIT" detail = review_repo.get_subject_details(shortcut.lower()) semester = "Z" if sem == 2: semester = "L" if detail: type_list = detail.type.split(", ") # remove duplicated types -> bug fix if type_list.count(type) != 1: type_list.append(type) type_list = list(dict.fromkeys(type_list)) review_repo.update_subject_type(shortcut, ", ".join(type_list), detail.year) if not detail: # subject not in DB review_repo.set_subject_details( shortcut, columns[0].get_text(), # name columns[1].get_text(), # credits semester, columns[3].get_text(), # end columns[0].find("a").attrs["href"], # link type, for_year, degree, ) elif for_year not in detail.year.split(", "): # subject already in DB with different year (applicable mainly for MIT) if type not in type_list: type += f", {detail.type}" if detail.year: for_year += f", {detail.year}" review_repo.update_subject_type(shortcut, type, for_year) elif semester not in detail.semester.split(", "): # subject already in DB with different semester (e.g. RET) semester += f", {detail.semester}" review_repo.update_subject_sem(shortcut, semester) elif degree not in detail.degree.split(", "): # subject already in DB with different degree (e.g. RET) degree += f", {detail.degree}" review_repo.update_subject_degree(shortcut, degree) sem += 1 if sem == 3: year += 1 sem = 1 return True