Best Python code snippet using localstack_python
bot.py
Source:bot.py
...184 server_config = pingbot.Config("./user/config/server.json").load_json()185 mod_channel = server_config[after.id]["mod_channel"]186 changed_items = pingbot.Utils().return_what_updated_server(before, after)187 if mod_channel != None and len(changed_items) > 0:188 await text(pingbot.get_event_message("server_update").format(', '.join(changed_items), pingbot.Utils().return_server_info(after)), channel=mod_channel, emoji="server_update", no_mention=True)189 #await pingbot.Utils(client).text_mod("Server has been modified!\nThe following has been changed: {}\n{}".format(', '.join(changed_items), pingbot.Utils().return_server_info(after)), mod_channel, emoji="server_update")190@client.event191async def on_channel_create(channel):192 if not channel.is_private:193 mod_channel = pingbot.Config("./user/config/server.json").load_json()[channel.server.id]["mod_channel"]194 if mod_channel != None:195 await text(pingbot.get_event_message("channel_create").format(channel.name, pingbot.Utils().return_channel_info(channel)), channel=mod_channel, emoji="channel_create", no_mention=True)196 #await pingbot.Utils(_client).text_mod_chan("Channel `{}` has been created!\n{}".format(channel.name, pingbot.Utils().return_channel_info(channel)), channel, emoji="channel_create")197 pingbot.Utils().channel_checkup(channel)198@client.event199async def on_channel_delete(channel):200 mod_channel = pingbot.Config("./user/config/server.json").load_json()[channel.server.id]["mod_channel"]201 if mod_channel != None:202 await text(pingbot.get_event_message("channel_delete").format(channel.name), channel=mod_channel, emoji="channel_remove", no_mention=True)203 #await pingbot.Utils(_client).text_mod_chan("Channel `{}` was deleted!".format(channel.name), channel, emoji="channel_remove")204 pingbot.Utils().channel_flush(channel)205@client.event206async def on_channel_update(before, after):207 changed_items = pingbot.Utils().return_what_updated_channel(before, after)208 mod_channel = pingbot.Config("./user/config/server.json").load_json()[after.server.id]["mod_channel"]209 if mod_channel != None and len(changed_items) > 0:210 await text(pingbot.get_event_message("channel_update").format(before.name, ', '.join(changed_items), pingbot.Utils().return_channel_info(after)), channel=mod_channel, emoji="channel_update", no_mention=True)211 #await pingbot.Utils(client).text_mod_chan("Channel `{}` was modified!\nThe following has been changed: {}\n{}".format(before.name, ', '.join(changed_items), pingbot.Utils().return_channel_info(after)), after, emoji="channel_update")212@client.event213async def on_member_join(member):214 mod_channel = pingbot.Config("./user/config/server.json").load_json()[member.server.id]["mod_channel"]215 if mod_channel != None:216 await text(pingbot.get_event_message("member_join").format(member, member.id, pingbot.Utils().return_member_info(member)), channel=mod_channel, emoji="member_join", no_mention=True)217 #await pingbot.Utils(_client).text_mod_member("Member `{}` (`{}`) has joined!\n{}".format(member, member.id, pingbot.Utils().return_member_info(member)), member, emoji="member_join")218@client.event219async def on_member_remove(member):220 mod_channel = pingbot.Config("./user/config/server.json").load_json()[member.server.id]["mod_channel"]221 if mod_channel != None:222 await text(pingbot.get_event_message("member_remove").format(member), channel=mod_channel, emoji="member_leave", no_mention=True)223 #await pingbot.Utils(_client).text_mod_member("Member `{}` has left the server.".format(member.name), member, emoji="member_leave")224@client.event225async def on_member_update(before, after):226 pingbot.Utils().server_checkup(after.server)227 server_config = pingbot.Config("./user/config/server.json").load_json()228 status_channel = server_config[after.server.id]["status_channel"]229 if before.nick != None:230 start_fmt = pingbot.get_event_message("start_fmt_with_nick").format(before, before.nick)231 else:232 start_fmt = pingbot.get_event_message("start_fmt_no_nick").format(before)233 if before != client.user or after != client.user and not before.bot and not after.bot:234 if status_channel != None:235 if before.name != after.name:236 if status_channel != None:237 await text(start_fmt + pingbot.get_event_message("member_name_update").format(after.name), channel=status_channel, emoji="member_update_name", no_mention=True)238 #await pingbot.Utils(_client).text_status("Member `{}` changed his/her name from {} to {}!".format(before.name, before.name, after.name), status_channel, emoji="member_update_name")239 elif before.game != after.game:240 if after.game != None :241 if status_channel != None:242 if not pingbot.Utils().cog_exists('fun'):243 await text(start_fmt + pingbot.get_event_message("member_game_update").format(after.game.name), channel=status_channel, emoji="member_update_game", no_mention=True)244 #await pingbot.Utils(client).text_status("Member `{}` is now playing `{}`".format(before.name, after.game.name), status_channel, emoji="member_update_game")245 else:246 await text(start_fmt + pingbot.get_event_message("member_game_update2").format(before.game.name), channel=status_channel, emoji="member_update_game", no_mention=True)247 elif before.nick != after.nick:248 if status_channel != None:249 if after.nick == None:250 await text(start_fmt + pingbot.get_event_message("member_nick_update"), channel=status_channel, emoji="member_update_name", no_mention=True)251 #await pingbot.Utils(client).text_status("Member `{}` has changed his/her nickname from {} to {}!".format(before.name, before.nick, after.nick), status_channel, emoji=emoji["member_update_name"])252 #await pingbot.Utils(_client).text_status("Member `{}` has reset his/her nickname!".format(before.name), status_channel, emoji=emoji["member_update_name"])253 else:254 await text(start_fmt + pingbot.get_event_message("member_nick_update2").format(after.nick), channel=status_channel, emoji="member_update_name", no_mention=True)255 elif before.avatar != after.avatar:256 #await pingbot.Utils(_client).text_mod("Member `{}` has changed his/her avatar to {}!".format(after.avatar_url), mod_channel)257 if status_channel != None:258 await text(start_fmt + pingbot.get_event_message("member_avatar_update").format(after.avatar_url), channel=status_channel, emoji="member_update_avatar", no_mention=True, no_bold=True)259 #await pingbot.Utils(_client).text_status("Member `{}` has changed his/her avatar to {}!".format(after.avatar_url), status_channel, emoji=emoji["member_update_avatar"])260@client.event261async def on_member_ban(member):262 mod_channel = pingbot.Config("./user/config/server.json").load_json()[member.server.id]["mod_channel"]263 if mod_channel != None:264 await text(pingbot.get_event_message("member_ban").format(member), channel=mod_channel, emoji="member_ban", no_mention=True)265 #await pingbot.Utils(client).text_mod_member("Member `{}` has been banned.", member, emoji="member_ban")266@client.event267async def on_member_unban(server, user):268 mod_channel = pingbot.Config("./user/config/server.json").load_json()[server.id]["mod_channel"]269 if mod_channel != None:270 await text(pingbot.get_event_message("member_unban").format(user), channel=mod_channel, emoji="member_unban", no_mention=True)271 #await pingbot.Utils(_client).text_mod("Member `{}` has been unbanned.", mod_channel, emoji="member_unban")272@client.command(name="help", aliases=["commands"], pass_context=True)273async def send_help_msg(ctx, command : str=None):274 """275 â Shows this message.276 --------------------277 USAGE: help <optional: command name>278 EXAMPLE: help279 --------------------280 """281 if command == None:282 await send_help_message(ctx, bot=client)283 else:284 await send_help_message(ctx, command=command, bot=client)...
match_event.py
Source:match_event.py
...36 messages = []37 for event in events:38 messages.append(schemas.MatchEventOutput(39 time=event.time,40 message=event.get_event_message(db)41 ))42 return messages43@router.post("/start", response_model=schemas.MatchEventOutput)44async def register_start(45 *,46 request: Request,47 db: Session = Depends(deps.get_db),48 tournament_id: int,49 match_id: int,50 event_in: schemas.MatchEventStartCreate51) -> Any:52 """53 Register the start of the match54 """55 validate_exists(db, tournament_id, match_id)56 event_create = schemas.MatchEventCreateInternal(**event_in.__dict__,57 match_id=match_id, event_type=models.EventType.start)58 event = cruds.match_event.create(db=db, obj_in=event_create)59 event = schemas.MatchEventOutput(time=event.time, message=event.get_event_message(db))60 send_to_queue(request.app.rabbit_client, match_id, event)61 return event62@router.post("/end", response_model=schemas.MatchEventOutput)63async def register_end(64 *,65 request: Request,66 db: Session = Depends(deps.get_db),67 tournament_id: int,68 match_id: int,69 event_in: schemas.MatchEventEndCreate70) -> Any:71 """72 Register the end of the game73 """74 validate_exists(db, tournament_id, match_id)75 event_create = schemas.MatchEventCreateInternal(**event_in.__dict__,76 match_id=match_id, event_type=models.EventType.end)77 event = cruds.match_event.create(db=db, obj_in=event_create)78 event = schemas.MatchEventOutput(time=event.time, message=event.get_event_message(db))79 send_to_queue(request.app.rabbit_client, match_id, event)80 return event81@router.post("/goal", response_model=schemas.MatchEventOutput)82async def register_goal(83 *,84 request: Request,85 db: Session = Depends(deps.get_db),86 tournament_id: int,87 match_id: int,88 event_in: schemas.MatchEventGoalCreate89) -> Any:90 """91 Register a goal for a team92 """93 validate_exists(db, tournament_id, match_id)94 data = event_in.__dict__95 data['integer_value'] = data['team_id']96 del data['team_id']97 event_create = schemas.MatchEventCreateInternal(**data, match_id=match_id,98 event_type=models.EventType.goal)99 event = cruds.match_event.create(db=db, obj_in=event_create)100 event = schemas.MatchEventOutput(time=event.time, message=event.get_event_message(db))101 send_to_queue(request.app.rabbit_client, match_id, event)102 return event103@router.post("/halftime", response_model=schemas.MatchEventOutput)104async def register_half_time(105 *,106 request: Request,107 db: Session = Depends(deps.get_db),108 tournament_id: int,109 match_id: int,110 event_in: schemas.MatchEventHalfTimeCreate111) -> Any:112 """113 Registers half time for the match114 """115 validate_exists(db, tournament_id, match_id)116 event_create = schemas.MatchEventCreateInternal(**event_in.__dict__,117 match_id=match_id, event_type=models.EventType.half_time)118 event = cruds.match_event.create(db=db, obj_in=event_create)119 event = schemas.MatchEventOutput(time=event.time, message=event.get_event_message(db))120 send_to_queue(request.app.rabbit_client, match_id, event)121 return event122@router.post("/stoppage", response_model=schemas.MatchEventOutput)123async def register_stoppage(124 *,125 request: Request,126 db: Session = Depends(deps.get_db),127 tournament_id: int,128 match_id: int,129 event_in: schemas.MatchEventStoppageCreate130) -> Any:131 """132 Registers stoppage in the match133 """134 validate_exists(db, tournament_id, match_id)135 data = event_in.__dict__136 data['integer_value'] = data['minutes']137 del data['minutes']138 event_create = schemas.MatchEventCreateInternal(**data, match_id=match_id,139 event_type=models.EventType.stoppage_time)140 event = cruds.match_event.create(db=db, obj_in=event_create)141 event = schemas.MatchEventOutput(time=event.time, message=event.get_event_message(db))142 send_to_queue(request.app.rabbit_client, match_id, event)143 return event144@router.post("/substitution", response_model=schemas.MatchEventOutput)145async def register_substitution(146 *,147 request: Request,148 db: Session = Depends(deps.get_db),149 tournament_id: int,150 match_id: int,151 event_in: schemas.MatchEventSubstitutionCreate152) -> Any:153 """154 Registers a player substitution in a match155 """156 validate_exists(db, tournament_id, match_id)157 data = event_in.__dict__158 data['player_id'] = data['player_out']159 data['integer_value'] = data['player_in']160 del data['player_in']161 del data['player_out']162 event_create = schemas.MatchEventCreateInternal(**data, match_id=match_id,163 event_type=models.EventType.substitution)164 event = cruds.match_event.create(db=db, obj_in=event_create)165 event = schemas.MatchEventOutput(time=event.time, message=event.get_event_message(db))166 send_to_queue(request.app.rabbit_client, match_id, event)167 return event168@router.post("/warning", response_model=schemas.MatchEventOutput)169async def register_warning(170 *,171 request: Request,172 db: Session = Depends(deps.get_db),173 tournament_id: int,174 match_id: int,175 event_in: schemas.MatchEventWarningCreate176) -> Any:177 """178 Registers a player substitution in a match179 """180 validate_exists(db, tournament_id, match_id)181 data = event_in.__dict__182 data['string_value'] = data['warning_type']183 del data['warning_type']184 event_create = schemas.MatchEventCreateInternal(**data, match_id=match_id,185 event_type=models.EventType.warning)186 event = cruds.match_event.create(db=db, obj_in=event_create)187 event = schemas.MatchEventOutput(time=event.time, message=event.get_event_message(db))188 send_to_queue(request.app.rabbit_client, match_id, event)...
urls.py
Source:urls.py
1from django.conf.urls import patterns, url2urlpatterns = patterns('',3 url(r'^post_message/(?P<eventid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)/(?P<userfrom>[\S\s-]+)/$', 'user_activity.app_message_api.get_message', name='get_json'),4 url(r'^post_message/(?P<eventid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)/$', 'user_activity.app_message_api.get_message', name='get_json'),5 url(r'^post_message/(?P<eventid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/$', 'user_activity.app_message_api.get_message', name='get_json'),6 url(r'^post_message/(?P<eventid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)/(?P<userfrom>[\S\s-]+)$', 'user_activity.app_message_api.get_message', name='get_json'),7 url(r'^post_message/(?P<eventid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)$', 'user_activity.app_message_api.get_message', name='get_json'),8 url(r'^post_message/(?P<eventid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)$', 'user_activity.app_message_api.get_message', name='get_json'),9 url(r'^post_an_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)/(?P<userfrom>[\S\s-]+)/$', 'user_activity.app_message_api.get_an_message', name='get_json'),10 url(r'^post_an_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)/$', 'user_activity.app_message_api.get_an_message', name='get_json'),11 url(r'^post_an_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/$', 'user_activity.app_message_api.get_an_message', name='get_json'),12 url(r'^post_an_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)/(?P<userfrom>[\S\s-]+)$', 'user_activity.app_message_api.get_an_message', name='get_json'),13 url(r'^post_an_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)$', 'user_activity.app_message_api.get_an_message', name='get_json'),14 url(r'^post_an_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)$', 'user_activity.app_message_api.get_an_message', name='get_json'),15 16 url(r'^adm_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)/(?P<userfrom>[\S\s-]+)/(?P<examine>[\w-]+)/$', 'user_activity.app_message_api.get_admin_message', name='get_json'),17 url(r'^adm_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)/$', 'user_activity.app_message_api.get_admin_message', name='get_json'),18 url(r'^adm_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/$', 'user_activity.app_message_api.get_admin_message', name='get_json'),19 url(r'^adm_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)/(?P<userfrom>[\S\s-]+)/(?P<examine>[\w-]+)$', 'user_activity.app_message_api.get_admin_message', name='get_json'),20 url(r'^adm_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)/(?P<username>[\S\s-]+)$', 'user_activity.app_message_api.get_admin_message', name='get_json'),21 url(r'^adm_message/(?P<messageid>[\w-]+)/(?P<question>[\S\s-]+)/(?P<date>[\w-]+)/(?P<userid>[\w-]+)$', 'user_activity.app_message_api.get_admin_message', name='get_json'),22 23 url(r'^get_event_msg/(?P<eventid>[\w-]+)/$', 'user_activity.app_message_api.get_event_message', name='get_json'),24 url(r'^get_event_msg/(?P<eventid>[\w-]+)$', 'user_activity.app_message_api.get_event_message', name='get_json'),25 url(r'^get_event_msg/(?P<eventid>[\w-]+)/(?P<offset>[\d-]+)/(?P<page>[\d-]+)/$', 'user_activity.app_message_api.get_event_message', name='get_json'),26 url(r'^get_event_msg/(?P<eventid>[\w-]+)/(?P<offset>[\w-]+)/(?P<page>[\d-]+)$', 'user_activity.app_message_api.get_event_message', name='get_json'),27 28 url(r'^get_user_msg/(?P<userid>[\w-]+)/(?P<date>[\d-]+)/$', 'user_activity.app_message_api.get_user_message', name='get_json'),29 url(r'^get_user_msg/(?P<userid>[\w-]+)/(?P<date>[\d-]+)$', 'user_activity.app_message_api.get_user_message', name='get_json'),30 url(r'^get_user_msg/(?P<userid>[\w-]+)/$', 'user_activity.app_message_api.get_user_message', name='get_json'),31 url(r'^get_user_msg/(?P<userid>[\w-]+)$', 'user_activity.app_message_api.get_user_message', name='get_json'),32 url(r'^test_ip/$','user_activity.app_message_api.test_ip', name='get_json' )...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!