Best Python code snippet using ATX
request.py
Source:request.py
1# -*- coding: utf-8 -*-2"""3ãªã¯ã¨ã¹ããµã¼ãã¹ ãµã³ãã«ã³ã¼ã4<< --注æ-- >>5On FP-version6As FP-version need the whole form with pictures or images you have to7custmoize the following source cord.We leave that job to you as the each8designs of form will be quite diffent.9On SP-version10The templatetags will provide the links.11As the SP-version only needs to create the link,12you can use this cord as the templatetags.13*A sample for the template14{% get_request_form request_users=player_friends_list submit_value="sendrequest" title="testtitle" body="bossisstrong" callbackurl=callbackurl mobile_url=mobile_url touch_url=touch_url option_params=option_params %}15{% get_request_form player_friends_list "sendrequest" "testtitle" "bossisstrong" callbackurl mobile_url touch_url option_params %}16ãFPçã«ã¤ãã¦17ãFPçã§ã¯ç»åãªã©ãå«ããã©ã¼ã ãçæããå¿
è¦ãããã¾ããããã©ã¼ã ã®ãã¶ã¤ã³ã¯18 åå ´åã«ãã£ã¦èããç°ãªãã¾ãã®ã§å
±éåã¯ãã¦ãã¾ããã19 ä¸è¨ã®ã³ã¼ããåèã«ãèªèº«ã®templatetagsããæ¸ãä¸ããã20SPçã«ã¤ãã¦21 templatetagsã§ãªã³ã¯ãæä¾ãã¦ãã¾ã22 SPçã¯ãªã³ã¯çæã®ã¿ãªã®ã§ãtemplatetagsã¨ãã¦å©ç¨ã§ãã¾ã23<< -------- >>24* ãã³ãã¬ã¼ãã§ã¯ä»¥ä¸ã®ããã«ä½¿ã25ä¾26{% get_request_form request_users=player_friends_list submit_value="ï¾ï½¸ï½´ï½½ï¾ãéä¿¡ãã" title="ï¾ï½½ï¾ï¾ï½²ï¾ï¾" body="ãã¹ãå¼·ãã" callbackurl=callbackurl mobile_url=mobile_url touch_url=touch_url option_params=option_params %}27{% get_request_form player_friends_list "ï¾ï½¸ï½´ï½½ï¾ãéä¿¡ãã" "ï¾ï½½ï¾ï¾ï½²ï¾ï¾" "ãã¹ãå¼·ãã" callbackurl mobile_url touch_url option_params %}28"""29import os30import urllib31from django import template32from gsocial.log import Log33register = template.Library()34abs_path = os.path.dirname(os.path.abspath(__file__))35file_path = abs_path + '/../templates/opensocial/request.html'36file_path_sp = abs_path + '/../templates/opensocial/request_sp.html'37@register.inclusion_tag(file_path)38def get_request_form( request_users,39 submit_value,40 title,41 body,42 callbackurl,43 mobile_url,44 touch_url,45 option_params={} ):46 u"""47 ãªã¯ã¨ã¹ããµã¼ãã¹ã®ãã©ã¼ã ãçæããè¿ã48 ãã£ã¼ãã£ã¼ãã©ã³ç49 å¤é¨ãã³ãã¬ã¼ã: gsocial/templates/opensocial/request.html50 使ãæ¹::51 {% get_request_form <request_users> <submit_value> <title> <body> <callbackurl> <mobile_url> <touch_url> <option_params> %}52 å¼æ°:53 :request_users: ãªã¯ã¨ã¹ããéä¿¡ãããã¦ã¼ã¶ãªã¹ã54 ï¼to_user_id[]ã«æ¸¡ããã©ã¡ã¼ã¿ï¼55 :submit_value: éä¿¡ãã¿ã³ã®æè¨56 :title: ãªã¯ã¨ã¹ãã®ã¿ã¤ãã«ï¼å¿
é ï¼57 :body: æ¬æ58 :callbackurl: ãªã¯ã¨ã¹ãããå¾ã«é·ç§»ããURL59 :mobile_url: ãªã¯ã¨ã¹ããã¦ã¼ã¶ãã¯ãªãã¯ããéã®é£ã³å
ã®URLï¼FPï¼60 :touch_url: ãªã¯ã¨ã¹ããã¦ã¼ã¶ãã¯ãªãã¯ããéã®é£ã³å
ã®URLï¼SPï¼61 :option_params: ãªãã·ã§ã³ãã£ã¯ã·ã§ããª62 option_params:63 :backto_url: ãªã¯ã¨ã¹ãé信確èªç»é¢ããã¢ããªã¸æ»ãããã®URL64 :mobile_image: ã¡ãã»ã¼ã¸ã«å«ããç»åã®URLï¼FPï¼65 :touch_image: ã¡ãã»ã¼ã¸ã«å«ããç»åã®URLï¼SPï¼66 :list_type: ãªã¯ã¨ã¹ãã®å¯¾è±¡ã¨ãªãã¦ã¼ã¶ã®ç¨®å¥67 :editable: ã¡ãã»ã¼ã¸ãã¦ã¼ã¶ã«å
¥åããã68 :expire_time: ãªã¯ã¨ã¹ããæéåãã¨ãªãæ¥æ(UTC FORMAT)69 Create the form for the request service and return it.(For FP)70 Customize the following source cord with your own designs of the forms.71 Arguments:72 :request_users: A Userlist whom you want to send request.(A parameter to be handed to to_user_id[])73 :submit_value: A letter on submit botton74 :title: The title of request(indispensable)75 :body: Message76 :callbackurl: A URL which will be redirected after the request.77 :mobile_url: A URL which will be redirected after the click(FP).78 :touch_url: A URL which will be redirected after the click(SP).79 :option_params: a optional dictionary80 option_params:81 :backto_url: A URL of the application from the "request sent confirmation"screen82 :mobile_image: URL of the image which will be contain in the messageï¼FPï¼83 :touch_image: URL of the image which will be contain in the messageï¼SPï¼84 :list_type: The type of subjected users.85 :editable: Whether User is allowed to edit or not.86 :expire_time: The expire date of the request(UTC FORMAT)87 """88 # checks the content of option_params89 # option_paramsã®ä¸èº«ããã§ãã¯90 # TODO : ãã£ã¨ç¶ºéºã«ããã91 keys = option_params.keys()92 backto_url = option_params['backto_url'] if 'backto_url' in keys else None93 mobile_image = option_params['mobile_image'] if 'mobile_image' in keys else None94 touch_image = option_params['touch_image'] if 'touch_image' in keys else None95 list_type = option_params['list_type'] if 'list_type' in keys else None96 editable = option_params['editable'] if 'editable' in keys else None97 expire_time = option_params['expire_time'] if 'expire_time' in keys else None98 # title is indispensable,so check.99 # titleã¯å¿
é ã®ããããã§ãã¯100 if not title:101 Log.error('title is empty.', body)102 raise103 # if list_type was not setted,use "specified"104 # list_typeã®æå®ãç¡ãã£ãå ´åãspecifiedãæå®ãã105 if list_type == None:106 list_type = 'specified'107 # body is indispensable when editable is True,so check108 # bodyã¯editableãtrueã§ãªãå ´åã¯å¿
é ã®ããããã§ãã¯109 # TODO : editable==Trueã®å ´åãã¡ãã»ã¼ã¸ãã¦ã¼ã¶ã«å
¥åããã110 # ãã®ããããã©ã¼ã çæã®htmlå´ã§ãå
¥åãã©ã¼ã ãçæããå¿
è¦ããã111 if editable != True:112 if body == None:113 Log.error('body is empty.', body)114 raise115 if request_users:116 temp = []117 for user in request_users:118 user_params = {}119 user_params['id'] = user['id'] if 'id' in user else None120 user_params['nickname'] = user['nickname'] if 'nickname' in user else None121 user_params['thumbnail'] = user['thumbnail'] if 'thumbnail' in user else None122 temp.append(user_params)123 return {124 'request_users': temp,125 'submit_value': submit_value,126 'title': title,127 'body': body,128 'callbackurl': callbackurl,129 'mobile_url': mobile_url,130 'touch_url': touch_url,131 'backto_url': backto_url,132 'mobile_image': mobile_image,133 'touch_image': touch_image,134 'list_type': list_type,135 'editable': editable,136 'expire_time': expire_time,137 }138@register.inclusion_tag(file_path_sp)139def get_request_form_sp( request_users,140 submit_value,141 title,142 body,143 callbackurl,144 mobile_url,145 touch_url,146 option_params={} ):147 u"""148 ãªã¯ã¨ã¹ããµã¼ãã¹ã®ãªã³ã¯ãä½æããè¿ã149 ã¹ãã¼ããã©ã³ç150 å¤é¨ãã³ãã¬ã¼ã: gsocial/templates/opensocial/request_sp.html151 使ãæ¹::152 {% get_request_form <request_users> <submit_value> <title> <body> <callbackurl> <mobile_url> <touch_url> <option_params> %}153 å¼æ°:154 :request_users: ãªã¯ã¨ã¹ããéä¿¡ãããã¦ã¼ã¶ãªã¹ã155 ï¼to_user_id[]ã«æ¸¡ããã©ã¡ã¼ã¿ï¼156 :submit_value: éä¿¡ãã¿ã³ã®æè¨157 :title: ãªã¯ã¨ã¹ãã®ã¿ã¤ãã«ï¼å¿
é ï¼158 :body: æ¬æ159 :callbackurl: ãªã¯ã¨ã¹ãããå¾ã«é·ç§»ããURL160 :mobile_url: ãªã¯ã¨ã¹ããã¦ã¼ã¶ãã¯ãªãã¯ããéã®é£ã³å
ã®URLï¼FPï¼161 :touch_url: ãªã¯ã¨ã¹ããã¦ã¼ã¶ãã¯ãªãã¯ããéã®é£ã³å
ã®URLï¼SPï¼162 :option_params: ãªãã·ã§ã³ãã£ã¯ã·ã§ããª163 option_params:164 :backto_url: ãªã¯ã¨ã¹ãé信確èªç»é¢ããã¢ããªã¸æ»ãããã®URL165 :mobile_image: ã¡ãã»ã¼ã¸ã«å«ããç»åã®URLï¼FPï¼166 :touch_image: ã¡ãã»ã¼ã¸ã«å«ããç»åã®URLï¼SPï¼167 :list_type: ãªã¯ã¨ã¹ãã®å¯¾è±¡ã¨ãªãã¦ã¼ã¶ã®ç¨®å¥168 :editable: ã¡ãã»ã¼ã¸ãã¦ã¼ã¶ã«å
¥åããã169 :expire_time: ãªã¯ã¨ã¹ããæéåãã¨ãªãæ¥æ(UTC FORMAT)170 Create the link for the request service and return it.(For SP)171 Arguments:172 :request_users: A Userlist whom you want to send request.(A parameter to be handed to to_user_id[])173 :submit_value: A letter on submit botton174 :title: The title of request(indispensable)175 :body: Message176 :callbackurl: A URL which will be redirected after the request.177 :mobile_url: A URL which will be redirected after the click(FP).178 :touch_url: A URL which will be redirected after the click(SP).179 :option_params: a optional dictionary180 option_params:181 :backto_url: A URL of the application from the "request sent confirmation"screen182 :mobile_image: URL of the image which will be contain in the messageï¼FPï¼183 :touch_image: URL of the image which will be contain in the messageï¼SPï¼184 :list_type: The type of subjected users.185 :editable: Whether User is allowed to edit or not.186 :expire_time: The expire date of the request(UTC FORMAT)187 """188 # check the content of option_params189 # option_paramsã®ä¸èº«ããã§ãã¯190 # TODO : ãã£ã¨ç¶ºéºã«ããã191 keys = option_params.keys()192 backto_url = option_params['backto_url'] if 'backto_url' in keys else None193 mobile_image = option_params['mobile_image'] if 'mobile_image' in keys else None194 touch_image = option_params['touch_image'] if 'touch_image' in keys else None195 list_type = option_params['list_type'] if 'list_type' in keys else None196 editable = option_params['editable'] if 'editable' in keys else None197 expire_time = option_params['expire_time'] if 'expire_time' in keys else None198 # title is indispensable ,so check199 # titleã¯å¿
é ã®ããããã§ãã¯200 if not title:201 Log.error('title is empty.', body)202 raise203 # if list_type was not setted ,use "specified"204 # list_typeã®æå®ãç¡ãã£ãå ´åãspecifiedãæå®ãã205 if list_type == None:206 list_type = 'specified'207 # if editable is True body is indispensable,so check208 # bodyã¯editableãtrueã§ãªãå ´åã¯å¿
é ã®ããããã§ãã¯209 # TODO : editable==Trueã®å ´åãã¡ãã»ã¼ã¸ãã¦ã¼ã¶ã«å
¥åããã210 # ãã®ããããã©ã¼ã çæã®htmlå´ã§ãå
¥åãã©ã¼ã ãçæããå¿
è¦ããã211 if editable != True:212 if body == None:213 Log.error('body is empty.', body)214 raise215 # encode216 # ã¨ã³ã³ã¼ããã217 callbackurl = urllib.quote(callbackurl)218 # create a parameter to be handed to user_to_id219 # user_to_idã«æ¸¡ããã©ã¡ã¼ã¿ãçæ220 request_user_ids_str = ','.join(request_users)221 return {222 'request_users': request_user_ids_str,223 'submit_value': submit_value,224 'title': title,225 'body': body,226 'callbackurl': callbackurl,227 'mobile_url': mobile_url,228 'touch_url': touch_url,229 'backto_url': backto_url,230 'mobile_image': mobile_image,231 'touch_image': touch_image,232 'list_type': list_type,233 'editable': editable,234 'expire_time': expire_time,...
kmeans.py
Source:kmeans.py
1##################################2# FORAGE DE DONNES #3# TP2 - CLUSTERING DE COULEURS #4# Auteurs : - MELLIER Valentin #5# - LAUGIER Alexis #6##################################7#Libs utilisés dans le fichier kmeans.py8from PIL.Image import *9from random import *10from math import sqrt11def euclidian_distance(p1, p2):12 return sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2+(p1[2]-p2[2])**2)13def manhattan_distance(p1, p2):14 return (abs(p1[0]-p2[0])+abs(p1[1]-p2[1])+abs(p1[2]-p2[2]))15def KMeansOnImage(imagepath,k,iter,dist):16 #Ouverture de l'image de référence17 untouch_image=open(imagepath).load()18 #Ouverture de l'image qui sera modifié19 touch_image = open(imagepath)20 #Récupération des dimensions21 width, height = touch_image.size22 #Génération aléatoire de k centroïdes dans l'image23 centroids = generateKColors(k,touch_image)24 #Chargement de l'image qui sera modifiée25 Update_image = touch_image.load()26 for i in range(0,iter):27 #Variable contenant les pixels rattachés à chaque centroïde28 get_pix_for_each_centroids=[[] for r in range(k)]29 #On parcourt l'image30 for x in range(width):31 for y in range(height): 32 centroids_dist_from_pix=[]33 #Pour chaque centroïde34 for elem in centroids:35 #On stocke les distances du pixel(x,y) à chaque centroïde36 if dist=="manhattan" : 37 centroids_dist_from_pix.append(manhattan_distance(elem,untouch_image[x,y]))38 elif dist=="euclidian":39 centroids_dist_from_pix.append(euclidian_distance(elem,untouch_image[x,y]))40 41 42 #On assigne le pixel au centroïde le plus proche43 get_pix_for_each_centroids[centroids_dist_from_pix.index(min(centroids_dist_from_pix))].append(untouch_image[x,y])44 Update_image[x,y] = centroids[centroids_dist_from_pix.index(min(centroids_dist_from_pix))] 45 #On replace chaque centroïde en calculant la moyenne des distances aux autres pixels46 centroids=computeMean(centroids, get_pix_for_each_centroids)47 touch_image.save("./result/result_image_kmeans.png")48 49 50 51def computeMean(centroids, centroidsPixList):52 #On calcule la moyenne et on retourne la nouvelle valeur du centroïde53 for elem in centroidsPixList:54 r_sum=055 g_sum=056 b_sum=057 for rgbtuple in elem:58 r_sum+=rgbtuple[0]59 g_sum+=rgbtuple[1]60 b_sum+=rgbtuple[2]61 centroids[centroidsPixList.index(elem)]=(int(r_sum/(len(elem)+1)),int(g_sum/(len(elem)+1)),int(b_sum/(len(elem)+1)))62 return centroids63#Définition de centroïdes random dans l'image64def generateKColors(k,image):65 init_Kcentroid_list=[]66 for i in range(0,k):67 init_Kcentroid_list.append(image.getpixel((randint(0,image.size[0]-1),randint(0,image.size[1]-1))))68 return init_Kcentroid_list...
main.py
Source:main.py
...29 self.select_support()30 self.start_training()31 self.training.start()32 def tap_training_button(self):33 Util.touch_image(self.images.home.training_button)34 def select_training(self):35 Util.touch_image(self.images.select.next_button)36 def select_umamusume(self):37 Util.touch_image(self.target_umamusume.thumbnail)38 Util.touch_image(self.images.select.next_button)39 def select_random_parents(self):40 Util.touch_image(self.images.select.parents_random_select)41 Util.touch_image(self.images.select.ok_button)42 Util.touch_image(self.images.select.next_button)43 def select_support(self):44 Util.touch_image(self.images.select.support_random_select)45 Util.touch_image(self.images.select.ok_button)46 def start_training(self):47 Util.touch_image(self.images.select.start_training)48 Util.touch_image(self.images.select.confirm_starting_training)49if __name__ == '__main__':50 args = sys.argv51 if not len(args) == 2:52 print('Invalid arguments.')53 exit(1)54 umamusume_name = args[1]55 main = Main(umamusume_name)...
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!!