def edit_user(self, id, acl_group_id, user_id, perms): rule = Acl_role_binding(id=id, acl_group_id=acl_group_id, user_id=user_id, perms=perms) session.merge(rule) session.commit()
async def update_db(self, ctx): with open("merlin-latest", "r") as f: data = f.readlines() new_people = [] new_logins = [] for line in data: line = line.split(":") login = line[0] name = line[4].split(",", 1)[0] try: year = line[4].split(",")[1] except IndexError: continue new_people.append(Valid_person(login=login, year=year, name=name)) new_logins.append(login) for person in new_people: session.merge(person) for person in session.query(Valid_person): if person.login not in new_logins: try: # check for muni int(person.login) person.year = "MUNI" except ValueError: person.year = "dropout" session.commit() await ctx.send("Update databaze probehl uspesne")
async def update_db(self, ctx, convert_0xit: bool = False): with open("merlin-latest", "r") as f: data = f.readlines() found_people = [] found_logins = [] new_logins = [] login_results = session.query(Valid_person.login).all() # Use unpacking on results old_logins = [value for value, in login_results] for line in data: line = line.split(":") login = line[0] name = line[4].split(",", 1)[0] try: year = line[4].split(",")[1] except IndexError: continue if convert_0xit and year.endswith("1r"): person = session.query(Valid_person).\ filter(Valid_person.login == login).\ one_or_none() if person is not None and person.year.endswith("0r"): year = year.replace("1r", "0r") found_people.append(Valid_person(login=login, year=year, name=name)) found_logins.append(login) for login in found_logins: if login not in old_logins: new_logins.append(login) await ctx.send(f"Našel jsem {len(new_logins)} nových loginů.") for person in found_people: session.merge(person) cnt_new = 0 for person in session.query(Valid_person): if person.login not in found_logins: try: # check for muni int(person.login) person.year = "MUNI" except ValueError: person.year = "dropout" elif convert_0xit and person.login in new_logins: if person.year.endswith("1r"): person.year = person.year.replace("1r", "0r") cnt_new += 1 session.commit() await ctx.send("Aktualizace databáze proběhla úspěšně.") if convert_0xit: await ctx.send(f"Debug: Našel jsem {cnt_new} nových prvaků.")
def update_review(self, id, tier, anonym: bool, text): review = Review(id=id, tier=tier, anonym=anonym, text_review=text, date=datetime.date.today()) session.merge(review) session.commit()
def set_programme(self, shortcut, name, link): programme = Programme( shortcut=shortcut, name=name, link=link ) session.merge(programme) session.commit()
def add_vote(self, review_id, vote: bool, author): relevance = ReviewRelevance( member_ID=author, vote=vote, review=review_id ) session.merge(relevance) session.commit()
def set_subject_details(self, shortcut, name, credits, semester, end, card, type, for_year, degree): subject = Subject_details( shortcut=shortcut, name=name, credits=credits, semester=semester, end=end, card=card, type=type, year=for_year, degree=degree, ) session.merge(subject) session.commit()
def edit_role(self, id, acl_group_id, role_id_name, perms): try: int(role_id_name) role_id = role_id_name role_name = None except ValueError: role_id = None role_name = role_id_name rule = Acl_role_binding(id=id, acl_group_id=acl_group_id, role_id=role_id, role_name=role_name, perms=perms) session.merge(rule) session.commit()
async def update_db(self, ctx): if ctx.author.id != config.admin_id: await ctx.send( messages.insufficient_rights.format( user=utils.generate_mention(ctx.author.id))) return with open("merlin-latest", "r") as f: data = f.readlines() new_people = [] new_logins = [] for line in data: line = line.split(":") login = line[0] name = line[4].split(",", 1)[0] try: year = line[4].split(",")[1] except IndexError: continue new_people.append(Valid_person(login=login, year=year, name=name)) new_logins.append(login) for person in new_people: session.merge(person) for person in session.query(Valid_person): if person.login not in new_logins: try: # check for muni int(person.login) print("Muni pls") person.year = "MUNI" except ValueError: person.year = "dropout" session.commit() await ctx.send("Update databaze probehl uspesne")
def add_subject(self, shortcut): subject = Subject(shortcut=shortcut) session.merge(subject) session.commit()
def update_subject_sem(self, shortcut, sem): subject = Subject_details(shortcut=shortcut, semester=sem) session.merge(subject) session.commit()
def update_subject_degree(self, shortcut, degree): subject = Subject_details(shortcut=shortcut, degree=degree) session.merge(subject) session.commit()
def update_subject_type(self, shortcut, type, for_year): subject = Subject_details(shortcut=shortcut, type=type, year=for_year) session.merge(subject) session.commit()
def add_subject(self, shortcut): # FIXME Outdated, moved to subject_repo.py subject = Subject(shortcut=shortcut) session.merge(subject) session.commit()
def update_subject(self, subject: Subject_details): session.merge(subject) session.commit()
def load_dump(filename: str): init_db(False) session.query(Karma).delete() session.query(Karma_emoji).delete() session.query(Permit).delete() session.query(Valid_person).delete() session.commit() print(f'Loading dump from {filename}') data = database.base.metadata.tables.keys() for row in data: print(row) with open(filename, "r", encoding='utf-8') as backup_file: data = backup_file.readlines() inserts = [line for line in data if line.startswith("INSERT")] karma_values = [] for insert in inserts: values = insert.split("VALUES", 1)[1] if insert.startswith("INSERT INTO `bot_karma`"): values = values[1:-2].replace('\'', '') values = values.replace('(', '').replace(')', '') values = values.split(',') for i in range(0, len(values), 3): karma_values.append( Karma(member_ID=values[i], karma=values[i + 1])) elif insert.startswith("INSERT INTO `bot_karma_giving`"): values = values[1:-2].replace('\'', '') values = values.replace('(', '').replace(')', '') values = values.split(',') for i in range(0, len(values), 4): karma_values.append( Karma(member_ID=values[i], positive=values[i + 1], negative=values[i + 2])) elif insert.startswith("INSERT INTO `bot_karma_emoji`"): values = values[1:-2].replace('\'', '') values = values.replace('(', '').replace(')', '') values = values.split(',') for i in range(0, len(values), 2): session.add( Karma_emoji(emoji_ID=values[i], value=values[i + 1])) elif insert.startswith("INSERT INTO `bot_permit`"): values = values[1:-2] values = values.replace('(', '').replace(')', '') values = re.split(r',(?=\')', values) values = [value.replace('\'', '') for value in values] for i in range(0, len(values), 3): session.add(Permit(login=values[i], discord_ID=values[i + 2])) elif insert.startswith("INSERT INTO `bot_valid_persons`"): values = values[1:-2].replace('\'', '') values = values.replace('(', '').replace(')', '') values = values.split(',') for i in range(0, len(values), 5): session.add( Valid_person( login=values[i], name=values[i + 1], year=values[i + 2], code=values[i + 3] if values[i + 3] != "NULL" else None, status=values[i + 4])) for karma in karma_values: session.merge(karma) session.commit()
def add(self, shortcut: str, name: str, category: str): subject = Subject(shortcut=shortcut, name=name, category=category) session.merge(subject) session.commit()
def edit_group(self, id, name, parent_id=None): group = Acl_groups(id=id, name=name, parent_id=parent_id) session.merge(group) session.commit()
def set_emoji_value(self, emoji_id: str, value: int): emoji = Karma_emoji(emoji_ID=utils.str_emoji_id(emoji_id), value=str(value)) # Merge == 'insert on duplicate key update' session.merge(emoji) session.commit()
def edit_rule(self, id, acl_group_id, acl_snowflake): rule = Acl_rules(id=id, acl_group_id=acl_group_id, acl_snowflake=acl_snowflake) session.merge(rule) session.commit()