Best Python code snippet using playwright-python
resumewar.py
Source:resumewar.py
1# -*- coding: utf-8 -*-2"""3Created on Tue Apr 9 08:09:18 201945@author: Fer6"""78import numpy as np9from matplotlib import pyplot as plt10#import skimage.measure as skm11from PIL import Image12from PIL import ImageFont13from PIL import ImageDraw14import facebook as fb15from pathlib import Path16import time1718def distancia(x1,y1,x2,y2):19 return np.sqrt((x1-x2)**2+(y2-y1)**2)2021def upload(message, access_token, img_path=None):22 graph = fb.GraphAPI(access_token)23 if img_path:24 post = graph.put_photo(image=open(img_path, 'rb'),25 message=message)26 else:27 post = graph.put_object(parent_object='me',28 connection_name='feed',29 message=message)30 return post['post_id']31 32def getAccessToken(filename='access_token.txt'):33 return Path(filename).read_text().strip()34 35def recoloreo(M,atk,defe,colorarr,labeled,props):36 m = M-M*(labeled == props[defe][1])37 m = m + (labeled == props[defe][1])*colorarr[atk]38 return m3940def suma_255(m1,m2):41 return m1+255*m24243def save_all(names,files):44 if len(names)!=len(files):45 raise ValueError('Los elementos deben tener la misma longitud')46 for i in range(len(names)):47 np.save(names[i],files[i])48 return 04950def replace(vec,chau,hola):51 vec[chau] = vec[hola]52 return vec53 54def three_times(f,a,b,c):55 return f(*a),f(*b),f(*c)56 57def hacer_imagen(mat):58 return Image.fromarray(mat).convert('L')59 60def gen_text(text,place,color,centroidx,centroidy,font,draw):61 tw,th = draw.textsize(text,font = font)62 x0 = centroidy[place]-tw/263 y0 = centroidx[place]-th/264 draw.text((x0-1,y0),text,font = font,fill = "black")65 draw.text((x0+1,y0),text,font = font,fill = "black")66 draw.text((x0,y0+1),text,font = font,fill = "black")67 draw.text((x0,y0-1),text,font = font,fill = "black")68 draw.text((x0,y0),text,font = font, fill = color)69 return draw70#%%71"""72img0 = Image.open('baires.png')73r0,g0,b0,what = img0.split()74rojo0 = np.array(r0)7576#%%77imth = rojo0 < 15978labeled, N_objects = skm.label( imth, neighbors=8, return_num = True)79objects = skm.regionprops(labeled) 8081props = [(object.area, object.label, object.centroid[0], object.centroid[1]) for object in objects]82props.sort(key=lambda x: x[0])8384centroidx = np.zeros(len(props))85centroidy = np.zeros(len(props))86for i in range(len(props)):87 centroidx[i] = props[-i-1][2]88 centroidy[i] = props[-i-1][3]89 90distancias = np.zeros((len(props),len(props)))91for i in range(len(props)):92 for j in range(len(props)):93 distancias[i,j] = distancia(centroidx[i],centroidy[i],centroidx[j],centroidy[j])9495lejos = int(np.amax(distancias) + 100)9697for i in range(len(props)):98 distancias[i,i] = lejos99labels = ['Palermo', 'Villa Lugano', 'Villa Soldati', 'Flores', 'Barracas', 'Mataderos', 'Caballito', 'Villa Devoto', 'Belgrano', 'Nueva Pompeya', 'Villa Urquiza', 'Saavedra', 'Parque Avellaneda', 'Recoleta', 'Balvanera', 'Liniers', 'Almagro', 'Villa Riachuelo', 'Villa Crespo', 'Parque Chacabuco', 'Parque Patricios', 'Nuñez', 'Villa del Parque', 'Villa Pueyrredón', 'La Boca', 'Retiro', 'Chacarita', 'Monte Castro', 'Boedo', 'Villa Luro', 'Puerto Madero', 'AgronomÃa', 'Vélez Sarsfield', 'Floresta', 'Colegiales', 'Villa General Mitre', 'San Nicolás', 'Paternal', 'Constitución', 'Villa Santa Rita', 'Monserrat', 'San Cristóbal', 'Villa Ortúzar', 'Versalles', 'San Telmo', 'Coghlan', 'Villa Real', 'Parque Chas']100"""101#%%102def hacer_turno(lugar,turns = 1,uplo = True,overwrite = True, save = True,restart = False):103 font = ImageFont.truetype("arial.ttf",60)104 #borders = np.load('borders.npy')105 borders = np.load(lugar+'fronteras.npy')106 end = False107 #%%108 #counter = np.load('counter'+lugar+'.npy')109 labeled = np.load(lugar+'labeled.npy')110 props = np.load(lugar+'props.npy')111 distancias = np.load(lugar+'distanciastart.npy')112 labels = np.load(lugar+'labelstart.npy')113114 if restart:115 d2 = np.load(lugar+'distanciastart.npy')116 l2 = np.load(lugar+'labelstart.npy') 117 counter = np.array([0])118 rojo2 = np.load(lugar+'rojostart.npy')119 verde2 = np.load(lugar+'verdestart.npy')120 azul2 = np.load(lugar+'azulstart.npy')121 matr2 = np.load(lugar+'matrstart.npy')122 matb2 = np.load(lugar+'matbstart.npy')123 matg2 = np.load(lugar+'matgstart.npy')124 else:125 d2 = np.load(lugar+'distancias.npy')126 l2 = np.load(lugar+'labels.npy')127 counter = np.load(lugar+'counter.npy')128 rojo2 = np.load(lugar+'rojo.npy')129 verde2 = np.load(lugar+'verde.npy')130 azul2 = np.load(lugar+'azul.npy')131 matr2 = np.load(lugar+'matr.npy')132 matb2 = np.load(lugar+'matb.npy')133 matg2 = np.load(lugar+'matg.npy')134135 i = 0136 lejos = np.amax(distancias)137 centroidx = np.load(lugar+'centx.npy')138 centroidy = np.load(lugar+'centy.npy')139 #%%140 while i < turns and not end:141 attack = np.random.randint(0,len(l2))142 if np.any(l2[:] != l2[attack]):143 defender = np.argmin(d2[attack][:]) 144 for j in range(len(l2)):145 if l2[j] == l2[attack]:#cambia la distancia del perdedor al ganador y sus aliados146 d2[defender][j] = lejos147 d2[j][defender] = lejos148 if l2[j] == l2[defender]:#cambia la distancia del perdedor a sus ex-aliados149 d2[defender][j] = distancias[defender][j]150 d2[j][defender] = distancias[j][defender]151 pre = len(np.unique(l2))152 lpre = l2[defender]153 matr2,matg2,matb2 = three_times(recoloreo,[matr2,attack,defender,rojo2,labeled,props],[matg2,attack,defender,verde2,labeled,props],[matb2,attack,defender,azul2,labeled,props])154 rojo2,verde2,azul2 = three_times(replace,[rojo2,defender,attack],[verde2,defender,attack],[azul2,defender,attack])155 borderr = (borders/(2**defender))%2 >= 1156 borderg, borderb = np.zeros(np.shape(matr2)),np.zeros(np.shape(matr2))157 for j in range(len(labels)):158 if l2[j] == l2[attack]:159 borderg = borderg+((borders/(2**j))%2 >= 1)160 l2[defender] = l2[attack]161 if save:162 we = save_all([lugar+'matr',lugar+'matg',lugar+'matb',lugar+'rojo',lugar+'verde',lugar+'azul',lugar+'labels',lugar+'distancias',lugar+'counter'],[matr2,matg2,matb2,rojo2,verde2,azul2,l2,d2,counter + 1])163 posterior = len(np.unique(l2))164 for j in range(len(labels)):165 if l2[j] == lpre:166 borderb = borderb+((borders/(2**j))%2 >= 1)167 borderg = (borderg==1)168 borderb = (borderb==1)169 borderg = (borderg-(borderg*borderr))==1170 borderb = (borderb-(borderg*borderb))==1171 borderb = (borderb-(borderr*borderb))==1172 matrp,matgp,matbp = three_times(suma_255,[matr2,borderr],[matg2,borderg],[matb2,borderb])173 r,g,b = three_times(hacer_imagen,[matrp],[matgp],[matbp])174 im = Image.merge("RGB", (r, g, b))175 draw = ImageDraw.Draw(im)176 draw = gen_text(labels[defender],defender,"red",centroidx,centroidy,font,draw)177 draw = gen_text(l2[defender],attack,"green",centroidx,centroidy,font,draw)178 if pre==posterior:179 exaliado = np.argwhere(l2 == lpre)[0][0]180 draw = gen_text(lpre,exaliado,"blue",centroidx,centroidy,font,draw)181 if overwrite:182 im.save(lugar+'imagen.png')183 else:184 im.save(lugar+str(counter[0])+'.png')185 if lugar == 'baires':186 status_text = l2[attack]+' conquistó al barrio de '+labels[defender]187 if lpre != labels[defender]:188 status_text = status_text + ', previamente bajo el control de '+lpre189 if pre!= posterior:190 if posterior > 1:191 status_text = status_text +'. '+ lpre + ' ha sido completamente eliminado, quedan '+str(posterior)+' barrios.'192 else:193 status_text = status_text +'. '+ lpre + ' ha sido completamente eliminado, '+l2[0]+' es el barrio campeón de la Ciudad de Buenos Aires.'194 else:195 status_text = status_text+'.'196 elif lugar == 'argentina':197 status_text = l2[attack]+' conquistó a la provincia de '+labels[defender]198 if lpre != labels[defender]:199 status_text = status_text + ', previamente bajo el control de '+lpre200 if pre!= posterior:201 if posterior > 1:202 status_text = status_text +'. '+ lpre + ' ha sido completamente eliminada, quedan '+str(posterior)+' provincias.'203 else:204 status_text = status_text +'. '+ lpre + ' ha sido completamente eliminada, '+l2[0]+' es la provincia campeona de la República Argentina.'205 else:206 status_text = status_text+'.'207 elif lugar == 'partidoscaba' or lugar == 'partidossincaba':208 status_text = l2[attack]+' conquistó al partido de '+labels[defender]209 if lpre != labels[defender]:210 status_text = status_text + ', previamente bajo el control de '+lpre211 if pre!= posterior:212 if posterior > 1:213 status_text = status_text +'. '+ lpre + ' ha sido completamente eliminado, quedan '+str(posterior)+' partidos.'214 else:215 status_text = status_text +'. '+ lpre + ' ha sido completamente eliminado, '+l2[0]+' es el partido campeón del conurbano bonaerense.'216 else:217 status_text = status_text+'.'218 if uplo and overwrite:219 try:220 upload(status_text, getAccessToken(lugar+'access_token.txt'), lugar+'imagen.png')221 except:222 pass223 if uplo and not overwrite:224 try:225 upload(status_text, getAccessToken(lugar+'access_token.txt'), lugar+str(counter[0])+'.png') 226 except:227 pass228 #print(l2[attack]+' conquisto a '+labels[defender]+' desde '+labels[attack])229 print(status_text)230 counter = counter + 1231 i = i + 1232 #time.sleep(60*60)233 else:234 end = True235 #print(i)
...
order.py
Source:order.py
1import pyautogui2from tkinter import *3import tkinter as tk4import time5import os6import re7import pyperclip8class App(tk.Tk):9 # msc = 100010 # global status_text11 # status_text = ''12 def __init__(self):13 super().__init__()14 self.title('ç¹é¤å·¥å
·')15 self.lbl = tk.Label(self,16 text='第ä¸æ¥ï¼ç¡®è®¤menuä¸èåæ¯å¦æ£ç¡®ï¼æ¯ä¸ªæ件æå¤è®¤15个èåï¼ï¼',17 anchor=W,)18 self.lbl.grid(row=0, column=0, stick=W, columnspan=4)19 self.lbl2 = tk.Label(self,20 text='第äºæ¥ï¼ç¹å»QQ群åºç¨ä¸ç群æ票ï¼',21 anchor=W,)22 self.lbl2.grid(row=1, column=0, stick=W)23 self.lbl3 = tk.Label(self,24 text='第ä¸æ¥ï¼ç¹å»å¼å§ï¼',25 anchor=W,)26 self.lbl3.grid(row=2, column=0, stick=W)27 self.lbl6 = tk.Label(self,28 text='',29 anchor=W)30 self.lbl6.grid(row=3, column=0, stick=W, columnspan=2)31 self.button = tk.Button(self,32 text='å¼å§',33 width=15,34 command=self.getMenuList)35 self.button.grid(row=4, column=0, columnspan=1)36 self.button = tk.Button(self,37 text='éåº',38 width=15,39 command=self.quit)40 self.button.grid(row=4, column=1, columnspan=1)41 self.lbl5 = tk.Label(self,42 text='',43 anchor=W)44 self.lbl5.grid(row=5, column=0, stick=W, columnspan=2)45 self.status_text = StringVar()46 self.lbl4 = tk.Label(self,47 textvariable=self.status_text,48 anchor=W)49 self.lbl4.grid(row=6, column=0, stick=W, columnspan=2)50 def update(self):51 global status_text52 self.status_text.set(str(status_text))53 self._upd = self.after(1000, self.update)54 def order_auto(self, menuTheme, menuList):55 # global status_text56 # self.update()57 # å·²ç¥menuTheme,menuList,åå¸ç¾¤æ票ç¹é¤58 los = pyautogui.locateOnScreen('picture/newvote.png', confidence=0.9)59 if los is not None:60 cent_xy = pyautogui.center(los)61 pyautogui.click(cent_xy)62 status_text = 'å¹é
å°newvote'63 # self.lbl4.config(text=self.status_text)64 los = pyautogui.locateOnScreen('picture/addItem.png', confidence=0.99)65 while los is not None:66 cent_xy = pyautogui.center(los)67 pyautogui.click(cent_xy)68 pyautogui.moveRel(40, 0)69 self.status_text = 'å¹é
å°add item'70 self.lbl4.config(text=self.status_text)71 los = pyautogui.locateOnScreen('picture/addItem.png', confidence=0.99)72 else:73 with open('log/log.txt', 'a', encoding='utf-8') as file_object:74 file_object.write(time.asctime(time.localtime(time.time())) + ',没æå¹é
å°addItem.png;\n')75 pyautogui.scroll(1000)76 i = 077 los = pyautogui.locateOnScreen('picture/theme.png', confidence=0.99)78 if los is not None:79 cent_xy = pyautogui.center(los)80 pyautogui.click(cent_xy)81 pyperclip.copy(f'ç¹é¤ï¼{menuTheme}ï¼')82 pyautogui.hotkey('ctrl', 'v')83 # pyautogui.typewrite(menuTheme) # ä¸æ¯æè¾å
¥ä¸æ84 self.status_text = 'å¹é
å°theme'85 self.lbl4.config(text=self.status_text)86 while i < 3:87 pyautogui.press('tab')88 pyperclip.copy(menuList[i])89 pyautogui.hotkey('ctrl', 'v')90 # pyautogui.typewrite(menuList[i])91 i += 192 # try:93 # pyautogui.press('tab')94 # pyautogui.press('tab')95 # time.sleep(5)96 # pyperclip.copy(menuList[i])97 # pyautogui.hotkey('ctrl', 'v')98 # # pyautogui.typewrite(menuList[i])99 # i += 1100 # except IndexError:101 # pass102 # else:103 while i < 15:104 try:105 pyperclip.copy(menuList[i])106 except IndexError:107 break108 else:109 pyautogui.press('tab')110 pyautogui.press('tab')111 pyautogui.press('tab')112 pyautogui.hotkey('ctrl', 'v')113 # pyautogui.typewrite(menuList[i])114 i += 1115 pyautogui.scroll(-1000)116 los = pyautogui.locateOnScreen('picture/checkBox.png', confidence=0.99)117 if los is not None:118 cent_xy = pyautogui.center(los)119 pyautogui.click(cent_xy)120 pyautogui.press('tab')121 pyautogui.typewrite(str(len(menuList))) # æ¯äººå¯å¤éæ大æ°é122 time.sleep(0.5)123 self.status_text = 'å¹é
å°checkBox'124 self.lbl4.config(text=self.status_text)125 los = pyautogui.locateOnScreen('picture/confirm.png', confidence=0.99)126 if los is not None:127 cent_xy = pyautogui.center(los)128 pyautogui.click(cent_xy)129 self.status_text = 'å¹é
å°confirm'130 self.lbl4.config(text=self.status_text)131 else:132 with open('log/log.txt', 'a', encoding='utf-8') as file_object:133 file_object.write(time.asctime(time.localtime(time.time())) + ',没æå¹é
å°confirm.png;\n')134 else:135 with open('log/log.txt', 'a', encoding='utf-8') as file_object:136 file_object.write(time.asctime(time.localtime(time.time()))+',没æå¹é
å°checkBox;\n')137 else:138 with open('log/log.txt', 'a', encoding='utf-8') as file_object:139 file_object.write(time.asctime(time.localtime(time.time())) + ',没æå¹é
å°theme.png;\n')140 else:141 with open('log/log.txt', 'a', encoding='utf-8') as file_object:142 file_object.write(time.asctime(time.localtime(time.time()))+',没æå¹é
å°newvote.png;\n')143 # self.lbl4.config(text=self.status_text)144 def getMenuList(self):145 # ä¾æ¬¡æå¼menu/.txtæ件ï¼è§£æåºmenuTheme, menuList146 for files in os.listdir('menu/'):147 if os.path.splitext(files)[1] == '.txt':148 regx = r'[\n\t]*(.+)[\n\t]*'149 with open('menu/' + files, 'r', encoding='utf-8') as file_object:150 contents = file_object.read()151 contents_list = re.findall(regx, contents)152 # print(os.path.splitext(files)[0])153 # print(contents_list)154 self.order_auto(menuTheme=os.path.splitext(files)[0], menuList=contents_list)155 time.sleep(3)156if __name__ == '__main__':157 app = App()158 app.geometry('380x170+200+300')...
cric_info.py
Source:cric_info.py
1import requests2import json3def get_match_details(series_id, match_id):4 match_link = "https://hs-consumer-api.espncricinfo.com/v1/pages/match/details?lang=en&seriesId={series_id}&matchId={match_id}&latest=true".format(5 series_id=series_id, match_id=match_id6 )7 detail_res = requests.get(match_link).text8 match_detail_data = json.loads(detail_res)["match"]9 status_text = match_detail_data["statusText"]10 team_1_score = match_detail_data["teams"][0]["score"]11 team_2_score = match_detail_data["teams"][1]["score"]12 team_1_name = match_detail_data["teams"][0]["team"]["name"]13 team_2_name = match_detail_data["teams"][1]["team"]["name"]14 # team_1_abv = match_detail_data["teams"][0]["team"]["abbreviation"]15 # team_2_abv = match_detail_data["teams"][1]["team"]["abbreviation"]16 try:17 team_1_inning = int(match_detail_data["teams"][0]["inningNumbers"][0])18 except:19 team_1_inning = None20 try:21 team_2_inning = int(match_detail_data["teams"][1]["inningNumbers"][0])22 except:23 team_2_inning = None24 format = match_detail_data["format"]25 match_name = team_1_name + " vs " + team_2_name26 # print(27 # status_text,28 # team_1_score,29 # team_2_score,30 # team_1_name,31 # team_2_name,32 # team_1_inning,33 # team_2_inning,34 # format,35 # )36 # team_1_scrcard = team_1_abv + " - " + team_1_score37 # team_2_scrcard = team_2_abv + " - " + team_2_score38 if format == "TEST":39 if (40 match_name41 and team_1_score42 and team_2_score43 and status_text44 and team_1_inning45 and team_2_inning46 ):47 string = (48 match_name49 + "\n"50 + team_1_name51 + " "52 + str(team_1_inning)53 + "inning"54 + " - "55 + team_1_score56 + "\n"57 + team_2_name58 + " "59 + str(team_2_inning)60 + "inning"61 + " - "62 + team_2_score63 + "\n"64 + status_text65 )66 return string67 elif (68 match_name69 and team_1_score70 and status_text71 and team_1_inning72 and team_2_score == None73 and team_2_inning == None74 ):75 string = (76 match_name77 + "\n"78 + team_1_name79 + " "80 + str(team_1_inning)81 + "inning"82 + " - "83 + team_1_score84 + "\n"85 + status_text86 )87 return string88 elif (89 match_name90 and team_1_score == None91 and team_2_score92 and status_text93 and team_1_inning == None94 and team_2_inning95 ):96 string = (97 match_name98 + "\n"99 + team_2_name100 + " "101 + str(team_2_inning)102 + "inning"103 + " - "104 + team_2_score105 + "\n"106 + status_text107 )108 return string109 elif (110 match_name111 and team_1_score == None112 and team_2_score == None113 and status_text114 and team_1_inning == None115 and team_2_inning == None116 ):117 string = match_name + "\n" + status_text118 return string119 else:120 if match_name and team_1_score and team_2_score and status_text:121 string = (122 match_name123 + "\n"124 + team_1_name125 + " - "126 + team_1_score127 + "\n"128 + team_2_name129 + " - "130 + team_2_score131 + "\n"132 + status_text133 )134 return string135 elif team_2_score == None and status_text and match_name:136 string = (137 match_name138 + "\n"139 + team_1_name140 + " - "141 + team_1_score142 + "\n"143 + status_text144 )145 return string146 elif team_1_score == None and status_text and match_name:147 return (148 match_name149 + "\n"150 + team_2_name151 + " - "152 + team_2_score153 + "\n"154 + status_text155 )156 else:157 return "No Live Data"158 # return status_text159def get_match_dict_list():160 match_dict_list = []161 try:162 response = requests.get(163 "https://hs-consumer-api.espncricinfo.com/v1/pages/matches/current?latest=true"164 ).text165 match_data = json.loads(response)["matches"]166 match_dict_list = [167 {168 "match_name": match["slug"],169 "match_id": match["objectId"],170 "series_id": match["series"]["objectId"],171 "team-1": match["teams"][0]["team"]["longName"],172 "team-2": match["teams"][1]["team"]["longName"],173 }174 for match in match_data175 if match["status"] == "Live"176 ]177 except Exception:178 pass179 match_list = ""180 # print("Choose any one of the following: \n")181 for i in range(0, len(match_dict_list)):182 match_list += (183 str(i)184 + ". "185 + match_dict_list[i]["team-1"]186 + " vs "187 + match_dict_list[i]["team-2"]188 + "\n"189 )190 if match_list:191 return match_list, match_dict_list192 else:...
plugin_logger.py
Source:plugin_logger.py
1#2# This file is part of Magnet2.3# Copyright (c) 2011 Grom PE4#5# Magnet2 is free software: you can redistribute it and/or modify6# it under the terms of the GNU General Public License as published by7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9#10# Magnet2 is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13# GNU General Public License for more details.14#15# You should have received a copy of the GNU General Public License16# along with Magnet2. If not, see <http://www.gnu.org/licenses/>.17#18import random19from magnet_api import *20from magnet_utils import *21def event_room_message(bot, (message, room, nick)):22 text = message.getBody()23 subject = message.getSubject()24 if message.getType() == 'groupchat':25 res = ''26 if nick:27 if text:28 if text[:4]=='/me ':29 res = '* %s %s'%(nick, text[4:])30 else:31 res = '<%s> %s'%(nick, text)32 elif subject:33 res = '*** %s has set the topic to:\n%s'%(nick, subject)34 else:35 res = '*** %s'%(text)36 if res: bot.writelog(room+'.txt', res)37 elif message.getType() != 'groupchat' and not bot.is_bot_owner(room, nick):38 if text:39 bot.writelog('_pmlog.txt', '<%s/%s> %s'%(room, nick, text));40def event_nick_changed(bot, (presence, room, nick, newnick)):41 bot.writelog(room+'.txt', '*** %s is now known as %s'%(nick, newnick))42def event_kicked(bot, (presence, room, nick, actor, reason)):43 actor = actor and ' by %s'%(actor) or ''44 reason = reason and ' (%s)'%(reason) or ''45 bot.writelog(room+'.txt', '*** %s has been kicked%s%s'%(nick, actor, reason))46 "None has been"47def event_banned(bot, (presence, room, nick, actor, reason)):48 actor = actor and ' by %s'%(actor) or ''49 reason = reason and ' (%s)'%(reason) or ''50 bot.writelog(room+'.txt', '*** %s has been banned%s%s'%(nick, actor, reason))51def event_removed_by_affiliation(bot, (presence, room, nick)):52 bot.writelog(room+'.txt', '*** %s has been removed from the room due to an affilliation change'%(nick))53def event_removed_by_membersonly(bot, (presence, room, nick)):54 bot.writelog(room+'.txt', '*** %s has been removed from the room because the room was made members-only'%(nick))55def event_removed_by_shutdown(bot, (presence, room, nick)):56 bot.writelog(room+'.txt', '*** %s has been removed from the room due to service shutdown'%(nick))57def event_left(bot, (presence, room, nick, jid)):58 jid = jid and ' (%s)'%(jid) or ''59 status = presence.getTagData('status')60 status = status and ' (%s)'%(status) or ''61 bot.writelog(room+'.txt', '*** %s%s has left the room%s'%(nick, jid, status))62aff1 = {63 'none': '',64 'member': ' and a member',65 'admin': ' and an administrator',66 'owner': ' and an owner'67}68aff2 = {69 'none': 'unaffiliated',70 'member': 'a member',71 'admin': 'an administrator',72 'owner': 'an owner'73}74def event_role_affiliation_changed(bot, (presence, room, nick, jid, role, affiliation)):75 bot.writelog(room+'.txt', '*** %s is now a %s and %s'%(nick, role, aff2.get(affiliation, affiliation)))76def event_affiliation_changed(bot, (presence, room, nick, jid, affiliation)):77 bot.writelog(room+'.txt', '*** %s is now %s'%(nick, aff2.get(affiliation, affiliation)))78def event_role_changed(bot, (presence, room, nick, jid, role)):79 bot.writelog(room+'.txt', '*** %s is now a %s'%(nick, role))80def event_status_changed(bot, (presence, room, nick, jid, status, status_text)):81 status_text = status_text and ' (%s)'%(status_text) or ''82 bot.writelog(room+'.txt', '*** %s is now %s%s'%(nick, status, status_text))83def event_joined(bot, (presence, room, nick, jid, role, affiliation, status, status_text)):84 jid = jid and ' (%s)'%(jid) or ''85 status_text = status_text and ' (%s)'%(status_text) or ''86 bot.writelog(room+'.txt', '*** %s%s has joined the room as a %s%s and now is %s%s'%(nick, jid, role, aff1.get(affiliation, affiliation), status, status_text))87def event_room_roster(bot, (presence, room, nick, jid, role, affiliation, status, status_text)):88 jid = jid and ' (%s)'%(jid) or ''89 status_text = status_text and ' (%s)'%(status_text) or ''90 bot.writelog(room+'.txt', '^^^ %s%s has joined the room as a %s%s and now is %s%s'%(nick, jid, role, aff1.get(affiliation, affiliation), status, status_text))91def load(bot):92 pass93def unload(bot):94 pass95def info(bot):...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!