Best Python code snippet using dbt-osmosis_python
submit_tool.py
Source:submit_tool.py
1import requests2import json3import time4from cn.code_predict import base64_api5from pic_code import get_pic_code6header = {7 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36",8 'content-type': "application/json"9}10token_url = 'https://fsservice.wjj.foshan.gov.cn/fw2/foying/wechatpublic/wx/user/getTokenByCh5'11submit_url = 'https://fsservice.wjj.foshan.gov.cn/fw2/foying/wechatpublic/wx/VaccineOrder/addVaccineOrderByCh5'12def get_token():13 body = {14 "orderChannel": "ch5"15 }16 res = requests.post(token_url, headers=header, data=json.dumps(body))17 data = res.text18 # data = '{"ResCode": "100","ResMsg": "æå","entity": {"allowOrderUserType": "au1","orderChannel": "ch5","token": "token-adda3382c5ebfc8c84bd28f5d4c0087a065121622552785493"}}'19 dataObj = json.loads(data)20 token = dataObj["entity"]["token"]21 return token22today = time.strftime("%Y-%m-%d", time.localtime())23def submit(token, platformScheduleId, base_organize_name, base_organize_ID, base_organize_phone,24 base_organize_address, ):25 needleTimes = "1" # é次26 img_path = 'pic_code.jpeg'27 result = base64_api(uname='bozi0822', pwd='111111qq', img=img_path, typeid=11)28 body = {29 "token": token,30 "bookType": "personal", # 个人é¢çº¦31 "baseOrganizeId": base_organize_ID, # æ¥ç§åä½32 "platformScheduleId": platformScheduleId, # æçid33 "baseOrganizeName": base_organize_name, #34 "baseOrganizeAddress": base_organize_address,35 "baseOrganizePhone": base_organize_phone,36 "scheduleDateStr": today, # æ¥ç§é¢çº¦æ¶é´ 2021-06-0237 "workAddress": workAddress,38 "homeAddress": homeAddress,39 "peopleCode": "pc1", # èä¸ ä¸ç¨å40 "needleTimes": needleTimes, # é次41 "realName": realName, # å§å42 "idCardNo": idCardNo, # 身份è¯43 "telephone": telephone, # çµè¯44 "sex": "1", # æ§å«Â 1ç·45 "idCardNoType": "01", # è¯ä»¶ç±»å 01身份è¯46 "picCode": result, # éªè¯ç #################################47 "birthday": ""48 }49 print('submit body=>' + str(body))50 res = requests.post(token_url, headers=header, data=json.dumps(body))51 data = res.text52 print('submit=>' + data)53all = [54 {"groupArea": "ç¦
ååº",55 "groupStreets": {56 "ç³æ¹¾è¡é", "å¼ æ§è¡é", "ç¥åºè¡é", "ååºé"57 }},58 {"groupArea": "åæµ·åº",59 "groupStreets": {60 "æ¡åè¡é", "丹ç¶é", "ç®å±±é", "大沥é", "éæ°´é"61 }},62 {"groupArea": "顺德åº",63 "groupStreets": {64 "大è¯è¡é", "伦æè¡é", "åæ»é", "éæé"65 }},66]67url2 = 'https://fsservice.wjj.foshan.gov.cn/fw2/foying/wechatpublic/wx/userBooking/getScheduleByDate'68url1 = 'https://fsservice.wjj.foshan.gov.cn/fw2/foying/wechatpublic/wx/userBooking/getOrganizeByGroupArea'69def find_info(groupArea, groupStreet, base_organize_name):70 body = {71 "groupArea": groupArea,72 "groupStreet": groupStreet73 }74 res = requests.post(url1, headers=header, data=json.dumps(body))75 # print(res.text)76 data = res.text77 resList = []78 #################################################################################################################################79 # data = '{"ResCode":"100","ResMsg":"è·åæºæå表æå","entityList":[{"address":"åæ»é人æè·¯10å·éè¿","allowOrderUserType":"au1","id":"08a99f34553c471bad32da56fa93c1651621942656007","organizeEnCode":"4406060530","organizeName":"åæ»æåä¸å¿æ°å ç«è大å临æ¶æ¥ç§ç¹","showFlag":"1","telephone":"0757-26656485"},{"address":"ä½å±±å¸ç¦
ååºç»¿æ¯è¥¿è·¯10å·50å·éº","allowOrderUserType":"au1","id":"2d1fc3a0991a4c7ca75a2a8d954730061617154824217","organizeEnCode":"4406040434","organizeName":"ç³æ¹¾éè¡éçªæ社åºå«çæå¡ç«ä¸´æ¶æ¥ç§ç¹","showFlag":"0","telephone":""},{"address":"ä½å±±å¸ç¦
ååºå¥æ§æå¥æ§æ°åº42å·","allowOrderUserType":"au1","id":"424c9471da194d53b77d36006f7435621618800142086","organizeEnCode":"4406040405","organizeName":"ç¦
ååºäººæ°å»é¢å¥æ§æ°å 临æ¶æ¥ç§ç¹","showFlag":"0","telephone":""},{"address":"ä½å±±å¸ç¬¬ä¸äººæ°å»é¢å¥åº·ç®¡çä¸å¿3å·æ¥¼1楼大å ","allowOrderUserType":"au1,au2","id":"501977ac24ab436f8b2c4bcc6cf2b9601617249299578","organizeEnCode":"4406040130","organizeName":"ä½å±±å¸ç¬¬ä¸äººæ°å»é¢æ°å ç«èæ¥ç§ç¹","showFlag":"0","telephone":""},{"address":"ç³æ¹¾éè¡éæ¾ç³åè¿è·¯88å·æ¾ç³ç 头","allowOrderUserType":"au1","id":"56c1e81068ae4227817a0ff4574e2e3c1617155817357","organizeEnCode":"4406040433","organizeName":"ä½å±±å¸ç¦
ååºç³æ¹¾éè¡é大åæ¥ç§ç¹","showFlag":"0","telephone":""},{"address":"ç¦
ååºç³æ¹¾éè¡éæ±¾æ±åè·¯9å·ä¸æ¥¼","allowOrderUserType":"au1","id":"6bce5464beda48cbb4a691a1d25f4cad1616920840275","organizeEnCode":"4406040401","organizeName":"ç¦
ååºä¸å¿å»é¢é水社åºå«çæå¡ç«æ°å æ¥ç§é¨è¯","showFlag":"0","telephone":"83385330"},{"address":"ä½å±±å¸ç¦
ååºæåä¸è·¯72å·","allowOrderUserType":"au1","id":"8d833ddbd4304f1ba83a3ee3a6c3fa861620958775430","organizeEnCode":"4406040403","organizeName":"æ±å¾·ï¼ä½å±±ï¼éª¨ç§å»é¢æ°å ç«è临æ¶æ¥ç§ç¹","showFlag":"0","telephone":""},{"address":"ç¦
ååºç³æ¹¾éè¡éä¸ååè·¯3å·6å·æ¥¼å¿ä¿å","allowOrderUserType":"au1","id":"8f12e1de035a4ee18e645815d2f1c3151616920568069","organizeEnCode":"4406040430","organizeName":"ç¦
ååºä¸å¿å»é¢é¢é²æ¥ç§é¨è¯","showFlag":"1","telephone":"82778663"},{"address":"ç³æ¹¾éè¡éåè¿è·¯1å·æ¾ç³å°å¦æï¼å
楼ï¼","allowOrderUserType":"au1","id":"a660b4b013394f1d958495c664374e871616920000674","organizeEnCode":"4406040436","organizeName":"ç³æ¹¾éè¡é社åºå«çæå¡ä¸å¿æ°å åºå®æ¥ç§ç¹","showFlag":"0","telephone":""},{"address":"ç¦
ååºç³æ¹¾éè¡éåè¿è·¯1å·æ¾ç³å°å¦æï¼ä¸æ¥¼ï¼","allowOrderUserType":"au1","id":"bd66900acd2348378be06fd13f16bc731616919497529","organizeEnCode":"4406040432","organizeName":"ç³æ¹¾éè¡é社åºå«çæå¡ä¸å¿é¢é²æ¥ç§é¨è¯","showFlag":"0","telephone":""},{"address":"ä½å±±å¸ç¦
ååºæ·±æ大éæ·±æ社åºå«çæå¡ç«æ","allowOrderUserType":"au1","id":"e836b9aeb52e4acca41160ad0ce0130c1617156391382","organizeEnCode":"4406040445","organizeName":"ç³æ¹¾éè¡éæ·±æ社åºå«çæå¡ç«æ¡åº·æ¥¼","showFlag":"0","telephone":""}]}'80 info_dic = json.loads(data)81 # print("\n")82 # print("==========", groupStreet, "===============")83 # print(info_dic["entityList"])84 global base_organize_ID85 global base_organize_phone86 global base_organize_address87 for entity in info_dic["entityList"]:88 if base_organize_name == entity["organizeName"]:89 base_organize_address = entity["address"]90 base_organize_ID = entity["id"]91 base_organize_phone = entity["telephone"]92 # print("=======================================================")93 # print(entity["address"])94 # print(entity["id"])95 # print(entity["organizeName"])96 # print(entity["telephone"])97 body2 = {98 "scheduleDate": today,99 "baseOrganizeID": base_organize_ID100 }101 res = requests.post(url2, headers=header, data=json.dumps(body2))102 # print(res.text)103 data = res.text104 # data = '{"ResCode":"100","ResMsg":"è·åæçä¿¡æ¯æå","entityList":[{"beginTimeStr":"14:30:00","count":300,"endTimeStr":"15:30:00","scheduleID":"9086ee28830d43d5866362d4f98349df1622176400468","vaccineProducer":"å京çç©ï¼å«é¿æ¥ãå
°å·åæé½ï¼"},{"beginTimeStr":"15:30:00","count":0,"endTimeStr":"16:30:00","scheduleID":"e68e3605c8314a20a22792c77851130a1622176430593","vaccineProducer":"å京çç©ï¼å«é¿æ¥ãå
°å·åæé½ï¼"}]}'105 schedule_ID = ""106 schedule_dic = json.loads(data)107 for item in schedule_dic["entityList"]:108 count = item["count"]109 vaccineProducer = item["vaccineProducer"]110 countInt = int(count)111 if countInt > 0:112 todayTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())113 timeName = time.strftime("%Y%m%d", time.localtime())114 res_content = vaccineProducer + ' ==å©ä½æ°éï¼' + str(count) + 'ã' + todayTime + 'ã'115 print(res_content)116 with open("log" + timeName + ".txt", "a", newline='') as f:117 f.write(res_content + '\n')118 f.close()119 schedule_ID = item["scheduleID"]120 return base_organize_ID, base_organize_phone, base_organize_address, schedule_ID121#################################èªå·±çä¿¡æ¯####################################122workAddress = "" # å
¬å¸å°å123homeAddress = "" # ä½å124realName = "" # å§å125idCardNo = "" # 身份è¯126telephone = "" # çµè¯127groupArea = "顺德åº",128groupStreet = "åæ»é",129base_organize_name = "åæ»æåä¸å¿æ°å ç«è大å临æ¶æ¥ç§ç¹"130###############################################################################131if __name__ == '__main__':132 get_pic_code()133 base_organize_ID, base_organize_phone, base_organize_address, schedule_ID = find_info(groupArea, groupStreet,134 base_organize_name)135 token = get_token()136 submit(token=token, platformScheduleId=schedule_ID, base_organize_name=base_organize_name,137 base_organize_ID=base_organize_ID, base_organize_phone=base_organize_phone,...
manager.py
Source:manager.py
...23 self.interval = interval24 def run(self):25 while True:26 time.sleep(self.interval)27 self.manager.flush_organize()28class Manager(Loggable):29 # NOTE : this massive class is a source of many problems of mm and30 # is in dire need of breaking up and refactoring.31 """ An abstraction over media monitors core pyinotify functions.32 These include adding watched,store, organize directories, etc.33 Basically composes over WatchManager from pyinotify """34 def __init__(self):35 self.wm = pyinotify.WatchManager()36 # These two instance variables are assumed to be constant37 self.watch_channel = getsig('watch')38 self.organize_channel = getsig('organize')39 self.watch_listener = StoreWatchListener(signal = self.watch_channel)40 self.__timeout_thread = ManagerTimeout(self)41 self.__timeout_thread.daemon = True42 self.__timeout_thread.start()43 self.organize = {44 'organize_path' : None,45 'imported_path' : None,46 'recorded_path' : None,47 'problem_files_path' : None,48 'organizer' : None,49 'problem_handler' : None,50 'organize_listener' : OrganizeListener(signal=51 self.organize_channel),52 }53 def dummy(sender, event): self.watch_move( event.path, sender=sender )54 dispatcher.connect(dummy, signal=getsig('watch_move'), 55 sender=dispatcher.Any, weak=False)56 def subwatch_add(sender, directory):57 self.__add_watch(directory, self.watch_listener)58 dispatcher.connect(subwatch_add, signal=getsig('add_subwatch'),59 sender=dispatcher.Any, weak=False)60 # A private mapping path => watch_descriptor61 # we use the same dictionary for organize, watch, store wd events.62 # this is a little hacky because we are unable to have multiple wd's63 # on the same path.64 self.__wd_path = {}65 # The following set isn't really necessary anymore. Should be66 # removed...67 self.watched_directories = set([])68 # This is the only event that we are unable to process "normally". I.e.69 # through dedicated handler objects. Because we must have access to a70 # manager instance. Hence we must slightly break encapsulation.71 def watch_move(self, watch_dir, sender=None):72 """ handle 'watch move' events directly sent from listener """73 self.logger.info("Watch dir '%s' has been renamed (hence removed)" %74 watch_dir)75 self.remove_watch_directory(normpath(watch_dir))76 def watch_signal(self):77 """ Return the signal string our watch_listener is reading78 events from """79 return getsig(self.watch_listener.signal)80 def __remove_watch(self,path):81 """ Remove path from being watched (first will check if 'path'82 is watched) """83 # only delete if dir is actually being watched84 if path in self.__wd_path:85 wd = self.__wd_path[path]86 self.wm.rm_watch(wd, rec=True)87 del(self.__wd_path[path])88 def __add_watch(self,path,listener):89 """ Start watching 'path' using 'listener'. First will check if90 directory is being watched before adding another watch """91 self.logger.info("Attempting to add listener to path '%s'" % path)92 self.logger.info( 'Listener: %s' % str(listener) )93 if not self.has_watch(path):94 wd = self.wm.add_watch(path, pyinotify.ALL_EVENTS, rec=True,95 auto_add=True, proc_fun=listener)96 if wd: self.__wd_path[path] = wd.values()[0]97 def __create_organizer(self, target_path, recorded_path):98 """ creates an organizer at new destination path or modifies the99 old one """100 # TODO : find a proper fix for the following hack101 # We avoid creating new instances of organize because of the way102 # it interacts with pydispatch. We must be careful to never have103 # more than one instance of OrganizeListener but this is not so104 # easy. (The singleton hack in Organizer) doesn't work. This is105 # the only thing that seems to work.106 if self.organize['organizer']:107 o = self.organize['organizer']108 o.channel = self.organize_channel109 o.target_path = target_path110 o.recorded_path = recorded_path111 else:112 self.organize['organizer'] = Organizer(channel=113 self.organize_channel, target_path=target_path,114 recorded_path=recorded_path)115 def get_problem_files_path(self):116 """ returns the path where problem files should go """117 return self.organize['problem_files_path']118 def set_problem_files_path(self, new_path):119 """ Set the path where problem files should go """120 self.organize['problem_files_path'] = new_path121 self.organize['problem_handler'] = \122 ProblemFileHandler( PathChannel(signal=getsig('badfile'),123 path=new_path) )124 def get_recorded_path(self):125 """ returns the path of the recorded directory """126 return self.organize['recorded_path']127 def set_recorded_path(self, new_path):128 self.__remove_watch(self.organize['recorded_path'])129 self.organize['recorded_path'] = new_path130 self.__create_organizer( self.organize['imported_path'], new_path)131 self.__add_watch(new_path, self.watch_listener)132 def get_organize_path(self):133 """ returns the current path that is being watched for134 organization """135 return self.organize['organize_path']136 def set_organize_path(self, new_path):137 """ sets the organize path to be new_path. Under the current138 scheme there is only one organize path but there is no reason139 why more cannot be supported """140 # if we are already organizing a particular directory we remove the141 # watch from it first before organizing another directory142 self.__remove_watch(self.organize['organize_path'])143 self.organize['organize_path'] = new_path144 # the OrganizeListener instance will walk path and dispatch an organize145 # event for every file in that directory146 self.organize['organize_listener'].flush_events(new_path)147 #self.__add_watch(new_path, self.organize['organize_listener'])148 def flush_organize(self):149 path = self.organize['organize_path']150 self.organize['organize_listener'].flush_events(path)151 def get_imported_path(self):152 return self.organize['imported_path']153 def set_imported_path(self,new_path):154 """ set the directory where organized files go to. """155 self.__remove_watch(self.organize['imported_path'])156 self.organize['imported_path'] = new_path157 self.__create_organizer( new_path, self.organize['recorded_path'])158 self.__add_watch(new_path, self.watch_listener)159 def change_storage_root(self, store):160 """ hooks up all the directories for you. Problem, recorded,161 imported, organize. """162 store_paths = mmp.expand_storage(store)...
myfunc.py
Source:myfunc.py
1import os2import shutil3from glob import glob4# unify path name5def unify_path_name(organize_dirctrory_path):6 organize_dirctrory_path = organize_dirctrory_path.replace('\ ', ' ')7 organize_dirctrory_path = organize_dirctrory_path.strip(' ')8 if organize_dirctrory_path[-1] != '/':9 organize_dirctrory_path = organize_dirctrory_path + '/'10 11 return organize_dirctrory_path12# get extension to create files every extension13def check_file_extensions(organize_dirctrory_path):14 file_list = glob(organize_dirctrory_path + '*')15 file_extensions = []16 17 for file in file_list:18 if os.path.isfile(file) == True:19 file_extensions.append(file.split('.')[-1])20 21 file_extensions = list(set(file_extensions))22 23 return file_extensions24# create directories to move files25def make_directories(organize_dirctrory_path):26 file_extensions = check_file_extensions(organize_dirctrory_path)27 created_directory = []28 for file_extension in file_extensions:29 mkdir_to_path = organize_dirctrory_path + file_extension30 try:31 os.makedirs(mkdir_to_path)32 except FileExistsError:33 check = ''34 while True:35 print(f'ãã§ã«{organize_dirctrory_path}ãã£ã¬ã¯ããªã«{file_extension}ãã£ã¬ã¯ããªãåå¨ãã¾ãã')36 print('ãã®ã¾ã¾ç¶ãã¦ãè¯ãã§ããï¼[y/n]')37 check = input()38 if check == 'y' or check == 'n':39 break40 else:41 print('yãnãå
¥åãã¦ãã ããã')42 43 if check == 'y':44 continue45 elif check == 'n':46 break47 48 49# move files50def move_f(file_extension, move_path):51 file_ls = glob(move_path + '*')52 for file in file_ls:53 move_f = move_path + file[-3:]...
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!!