def update_club(db, id): club = db.get_club_id(id) print("Input required values and press enter...") new_c = Club() inp = input("Coach: ") new_c.coach = inp if inp is not '' else club[2] inp = input("League: ") new_c.league = inp if inp is not '' else club[3] inp = input("Is club plays at euro cups (True or False): ") new_c.euro_cups = inp == "True" if inp is not '' else club[4] db.update_club(new_c, id)
def on_get(self, req: falcon.Request, res: falcon.Response, club_id: str): if club_id.isnumeric(): obj = Club.by_id(club_id) else: obj = Club.by_permalink(club_id) if obj and obj.is_enabled: return self.send_response( res, obj.toJSON([ "_id", "description", "email", "name", "permalink", "website" ])) raise falcon.HTTPNotFound()
def select_all_clubs(): results = run_sql("SELECT * FROM clubs") clubs = [] for result in results: club = Club(result["name"], result["number_of_courts"], result["id"]) clubs.append(club) return clubs
def on_post(self, req: falcon.Request, res: falcon.Response): user_id = req.media['user_id'] guild_id = req.media['guild_id'] club = ClubModel.by_discord_id(guild_id) if not club or not club.is_enabled: raise falcon.HTTPBadRequest("ClubNotExists") if not club.verified_role_id: raise falcon.HTTPBadRequest("ClubNotConfigured") # check if user is already verified with server user = UserModel.by_discord_id(user_id) if user and user.is_verified and MemberModel.check_existence( user._id, club._id): lib.rpc.bot_add_roles(user_id, guild_id, [club.verified_role_id]) raise falcon.HTTPBadRequest("AlreadyVerified") # create a signed token token = store.token.generate_verification(user_id, guild_id) self.send_response( res, { "url": f"{web_url}/verifications/{token}", "expires": store.token.EXPIRES_VERIFICATION })
def on_get(self, req: falcon.Request, res: falcon.Response, token): data = store.token.validate(store.token.AUD_VERIFICATION, token) if not data: raise falcon.HTTPBadRequest("InvalidToken") # check if club exists and is enabled club = ClubModel.by_discord_id(data["gid"]) if not club or not club.is_enabled: raise falcon.HTTPBadRequest("ClubNotExists") # grab user once we verify existence of club user = UserModel.by_discord_id(data["uid"]) return self.send_response( res, { "user_verified": user is not None, "club": club.toJSON([ "_id", "description", "email", "name", "permalink", "website" ]) })
def select_club(id): sql = "SELECT * FROM clubs WHERE id =%s" value = [id][0] result = run_sql(sql, value)[0] if result is not None: club = Club(result["name"], result["number_of_courts"], result["id"]) return club
def club_create(): if not session["logged_in"] or not session.get("person")["admin"]: return redirect(url_for("cl_page")) db = Database() data = request.form club = Club(data["name"], data["fac_id"], data["adv_id"], data["ch_id"], data["v1_id"], data["v2_id"]) db.add_club(club) return redirect(url_for("cl_page"))
def get_all_clubs(): html = get_clubs_html() soup = soupify(html) clubs = get_clubs(soup) club_objs = [ Club(get_club_name(club), get_club_description(club), get_club_tags(club)) for club in clubs ] return club_objs
def get_clubs_html(column): clubs = [] for link in column.find_all('tr', recursive=False): elements = link.find_all("td", recursive=False) name = elements[0].text number = elements[1].text club = Club(name, number) comp_id = re.search(r'aspx\?id=(.+?)((?=\&)|$)', elements[0].a.get('href')).group(1) club_comp_id = re.search(r'club=(\d+)', elements[0].a.get('href')).group(1) club.add_competition(comp_id, club_comp_id) clubs.append(club) return clubs
def input_club(db): print("Input required values and press enter...") c = Club() c.title = input("Title: ") c.coach = input("Coach: ") c.league = input("League: ") c.euro_cups = input("Is club plays at euro cups (True or False): ") == "True" db.new_club(c)
def create_one_club(club_dict): if "name" in club_dict and "description" in club_dict: matching_clubs = [club for club in db["clubs"] if club.name == club_dict["name"]] if len(matching_clubs) < 1: db["clubs"].append( Club( club_dict["name"], club_dict["description"], club_dict["tags"] if "tags" in club_dict else None ) ) return "success" return "There is already a club with that name." return "Insufficient data to create a club. Both a name and description are required."
def create_new_db_club(driver, club_id): """ Creates new club in database. :param driver: :param club_id: :return: """ name_select = "#verein_head > div > div.dataHeader.dataExtended > div.dataMain > div > div.dataName > h1 > span" full_club_name = driver.find_element_by_css_selector(name_select).text club_image = get_image(driver) new_item = Club(club_id=club_id, club_name=full_club_name, club_logo=club_image) db.add(new_item) db.commit()
def on_post(self, req: falcon.Request, res: falcon.Response, token): data = store.token.validate(store.token.AUD_VERIFICATION, token) if not data: raise falcon.HTTPBadRequest("InvalidToken") # check if club exists and is enabled club = ClubModel.by_discord_id(data["gid"]) if not club or not club.is_enabled: raise falcon.HTTPBadRequest("ClubNotExists") if not club.verified_role_id: raise falcon.HTTPBadRequest("ClubNotConfigured") # grab user once we verify existence of club user = UserModel.by_discord_id(data["uid"]) if user == None and "user" not in req.media: raise falcon.HTTPBadRequest("NoUserDetails") # destroy and lock token if not store.token.destroy(token): raise falcon.HTTPBadRequest("InvalidToken") if user == None: user = UserModel.create({ "discord_id": data["uid"], **req.media["user"] }) try: MemberModel.create({"user_id": user._id, "club_id": club._id}) except Exception as e: logger.warn("Error creating member: ", e) if user.is_verified: lib.rpc.bot_add_roles(data["uid"], data["gid"], [club.verified_role_id]) return self.send_response(res, {"user_verified": True}) else: token = store.token.generate_validation( user._id, "zid" if user.zid else "email") send_validation( to=f"{user.zid}@unsw.edu.au" if user.zid else user.email, name=user.given_name, token=token) return self.send_response(res, {"user_verified": False})
def on_get(self, req: falcon.Request, res: falcon.Response): self.send_response(res, [i.toJSON() for i in Club.get_all()])
def post(self, *args, **kwargs): Club.reset() self.write(self.make_result(1, "club reset OK", None))
def on_post(self, req: falcon.Request, res: falcon.Response): obj = Club.create(req.media) self.send_response(res, obj.toJSON())
def on_get(self, req: falcon.Request, res: falcon.Response, guild_id: str): obj = Club.by_discord_id(guild_id) if not obj: raise falcon.HTTPNotFound() self.send_response(res, obj.toJSON())
def add_club(self): self.db.new_club( Club(rnd_club(), rnd_fullname(), rnd_league(), rnd_bool()))
def on_put(self, req: falcon.Request, res: falcon.Response, guild_id: str): obj = Club.by_discord_id(guild_id) if not obj: raise falcon.HTTPNotFound() obj.update_value(req.media['key'], req.media['value']) return self.send_response(res, True)
'email': '*****@*****.**', 'image': '', 'password': '******', 'password_confirmation': 'password' }) if errors: raise Exception(errors) Ed.save() badminton_north_london = Club( name='North London Badminton Club', image='https://tinyurl.com/y2zjeusz', owner=Nawal, followed_by=[Ed, Nawal], location= 'Finsbury Park, London, Greater London, England, United Kingdom', lat=51.534969, lng=-0.103750, description='Friendly club to play weekly badminton on a Wednesday', category='Sports') badminton_north_london.save() mums_club_Surbiton = Club( name='Mums Meetup Club Surbiton', image='http://tinyurl.com/y5oj22bz', owner=Wendy, followed_by=[Ed, Nawal], location='Surbiton, Greater London, England, United Kingdom', lat=51.3862921, lng=-0.3090997,
def post(self, *args, **kwargs): all_clubs = Club.get_all_clubs() self.write(self.make_result(1, "get all clubs OK", all_clubs))
import repositories.club_repository as club_repository from models.club import Club club_1 = Club("Tennis", 4) club_2 = Club("Squash", 3) club_repository.add_new_club(club_1) club_repository.add_new_club(club_2)