Best Python code snippet using autotest_python
registNaverToOther.py
Source:registNaverToOther.py
1from tkinter import filedialog, filedialog2import xlrd, xlwt3import os,getpass4stock = 495def AtoN(alphabet):6 idxAlp = {"A":1,"B":2,"C":3,"D":4,"E":5,"F":6,"G":7,"H":8,"I":9,"J":10,"K":11,"L":12,"M":13,"N":14,"O":15,"P":16,"Q":17,"R":18,"S":19,"T":20,"U":21,"V":22,"W":23,"X":24,"Y":25,"Z":26}7 alphabet = alphabet.upper()8 idx = -19 for i in range(len(alphabet)):10 idx += idxAlp[alphabet[len(alphabet)-1-i]]*(26**i)11 return idx12def cartegoryConverter(code):13 if code == 50000567:14 return ['00110007000500000000','16692000','100000064200001420300026288','1009448']15 else:16 return ['need','insert','code','to here']17def shipFeeEMS(fee):18 # ì ë£/4,000ì/ì ê²°ì 3942622119 # ì ë£/3,000ì/ì ê²°ì 3768789120 # ì ë£/2,500ì/ì ê²°ì 3841374221 # ë¬´ë£ 3713196822 fee = int(fee)23 if fee == 0:24 return 3713196825 elif 0 < fee <= 2500:26 return 3841374227 elif 2500 < fee <= 3000:28 return 3768789129def priceConverter(naverPrice):30 if naverPrice < 1000:31 return round(naverPrice*1.075+5,-1)32 elif naverPrice < 10000:33 return round(naverPrice*1.075+50,-2)-1034 elif naverPrice < 30000:35 return round(naverPrice*1.075+500,-3)-1036 else:37 return round(naverPrice*1.075+5000,-4)-10038def optionConverter(opT, opV):39 tail = ',ì ì,ë
¸ì¶,'+str(stock)+','+str(stock)40 if opT != '' and opV != '':41 opTitle = opT.split('/')42 tempOpTitle = []43 for ii in opTitle:44 ii = ii.strip()45 if 'ìì'==ii or 'ì¬ì´ì¦'==ii:46 tempOpTitle.append(ii)47 elif 'size'==ii or 'í¬ê¸°'==ii:48 tempOpTitle.append('ì¬ì´ì¦')49 elif '컬ë¬'==ii or 'ì¹¼ë¼'==ii:50 tempOpTitle.append('ìì')51 elif 'ì íìµì
'==ii:52 tempOpTitle.append('ìì')53 elif 'ì í'==ii:54 tempOpTitle.append('ìì')55 elif 'ìµì
'==ii:56 tempOpTitle.append('ìì')57 else: 58 tempOpTitle = []59 opTitle = tempOpTitle60 if len(opTitle)==1:61 # EMS62 singeArray = opV.split(',')63 tempCell = ''64 for j in singeArray:65 tempCell += (j+tail+'\n')66 return ['ì íí',opTitle[0],tempCell,'01' if opTitle[0] == 'ìì' else '02',opV.replace(',','|'),("0|"*len(singeArray))[:-1],((str(stock)+"|")*len(singeArray))[:-1],'']67 elif len(opTitle)==2:68 # EMS69 doubleArray = opV.split(',')70 ary0 = []71 ary1 = []72 for doub in doubleArray:73 if len(doub.split('/'))==2:74 ary0.append(doub.split('/')[0].strip())75 ary1.append(doub.split('/')[1].strip())76 ary0 = list(dict.fromkeys(ary0))77 ary0.sort()78 ary1 = list(dict.fromkeys(ary1))79 ary1.sort()80 tempDoubCell = ''81 for j in ary0:82 for jj in ary1:83 tempDoubCell += '{},{}{}\n'.format(j.strip(),jj.strip(),tail)84 opTitle11 =[]85 for ot in opTitle:86 if ot == 'ìì':87 opTitle11.append('01')88 elif ot == 'ì¬ì´ì¦':89 opTitle11.append('02')90 return ['ì¡°í©í',','.join(opTitle),tempDoubCell,'\n'.join(opTitle11),'{}\n{}'.format('|'.join(ary0),'|'.join(ary1)),("0|"*len(doubleArray))[:-1],((str(stock)+"|")*len(doubleArray))[:-1],'']91 else:92 return ['error','error','error','error','error','error','error','error']93 else:94 return ['','','','','','','',stock]95def convertTo():96 downloadPath = os.environ['USERPROFILE'] +'\\Downloads'97 openFile = filedialog.askopenfile(initialdir=downloadPath,filetypes=[("Excel files", ".xls")])98 if openFile != None: 99 book = xlrd.open_workbook(openFile.name)100 # book = xlrd.open_workbook('C:/Users/titel/Downloads/new_1017/naver_1017.xls')101 sheetNaver = book.sheet_by_index(0)102 103 wtBook = xlwt.Workbook()104 sheetEMS = wtBook.add_sheet('EMS')105 sheet11 = wtBook.add_sheet('11st')106 # nrows, ncols107 for i in range(1, sheetNaver.nrows):108 cartegory = cartegoryConverter(sheetNaver.cell_value(rowx=i,colx=AtoN('b')))109 sheetEMS.write(i,AtoN('j'),cartegory[0])110 sheetEMS.write(i,AtoN('k'),cartegory[1])111 sheetEMS.write(i,AtoN('l'),cartegory[2])112 sheet11.write(i,AtoN('b'),cartegory[3])113 sheetEMS.write(i,AtoN('e'),sheetNaver.cell_value(rowx=i,colx=AtoN('c')))114 sheet11.write(i,AtoN('e'),sheetNaver.cell_value(rowx=i,colx=AtoN('c')))115 price = priceConverter(sheetNaver.cell_value(rowx=i,colx=AtoN('d')))116 sheetEMS.write(i,AtoN('n'),price)117 sheetEMS.write(i,AtoN('o'),price)118 sheet11.write(i,AtoN('ab'),price)119 sheetEMS.write(i,AtoN('aa'),sheetNaver.cell_value(rowx=i,colx=AtoN('j')))120 sheet11.write(i,AtoN('n'),sheetNaver.cell_value(rowx=i,colx=AtoN('j')))121 sheet11.write(i,AtoN('ar'),sheetNaver.cell_value(rowx=i,colx=AtoN('k')))122 sheetEMS.write(i,AtoN('ad'),shipFeeEMS(sheetNaver.cell_value(rowx=i,colx=AtoN('z'))))123 sheet11.write(i,AtoN('dd'),sheetNaver.cell_value(rowx=i,colx=AtoN('z')))124 sheetEMS.write(i,AtoN('ai'),sheetNaver.cell_value(rowx=i,colx=AtoN('ad')))125 sheet11.write(i,AtoN('di'),sheetNaver.cell_value(rowx=i,colx=AtoN('ad')))126 sheet11.write(i,AtoN('dk'),sheetNaver.cell_value(rowx=i,colx=AtoN('ae')))127 options = optionConverter(sheetNaver.cell_value(rowx=i,colx=AtoN('ay')),sheetNaver.cell_value(rowx=i,colx=AtoN('az')))128 sheetEMS.write(i,AtoN('v'),options[0])129 sheetEMS.write(i,AtoN('w'),options[1])130 sheetEMS.write(i,AtoN('x'),options[2])131 sheet11.write(i,AtoN('ad'),options[3])132 sheet11.write(i,AtoN('ae'),options[4])133 sheet11.write(i,AtoN('af'),options[5])134 sheet11.write(i,AtoN('ag'),options[6])135 sheet11.write(i,AtoN('aj'),options[7])136 # sheetEMS.write(i,AtoN(''),sheetNaver.cell_value(rowx=i,colx=AtoN('')))137 # sheet11.write(i,AtoN(''),sheetNaver.cell_value(rowx=i,colx=AtoN('')))138 sheetEMS.write(i,AtoN('b'),'ì¥ì
/Gë§ì¼')139 sheetEMS.write(i,AtoN('c'),'h7minor')140 sheetEMS.write(i,AtoN('d'),'h7minor')141 sheetEMS.write(i,AtoN('m'),'90')142 sheetEMS.write(i,AtoN('t'),stock)143 sheetEMS.write(i,AtoN('u'),stock)144 sheetEMS.write(i,AtoN('y'),'PUT IN IMAGE LINK')145 sheetEMS.write(i,AtoN('ab'),'ì¼ë°íë°°')146 sheetEMS.write(i,AtoN('ac'),15676256)147 sheetEMS.write(i,AtoN('ae'),4640254)148 sheetEMS.write(i,AtoN('af'),1052181)149 sheetEMS.write(i,AtoN('ag'),1052184)150 sheetEMS.write(i,AtoN('ah'),10034)151 sheetEMS.write(i,AtoN('aj'),35)152 sheetEMS.write(i,AtoN('ak'),171104)153 sheetEMS.write(i,AtoN('al'),'ì¸ì¦ëììë')154 sheetEMS.write(i,AtoN('as'),'ì¸ì¦ëììë')155 sheetEMS.write(i,AtoN('aw'),'ì¸ì¦ëììë')156 sheetEMS.write(i,AtoN('bf'),'ê³¼ì¸ìí')157 sheet11.write(i,AtoN('i'),'PUT IN IMAGE LINK')158 sheet11.write(i,AtoN('p'),'01')159 sheet11.write(i,AtoN('r'),'01')160 sheet11.write(i,AtoN('s'),'01')161 sheet11.write(i,AtoN('t'),'108')162 sheet11.write(i,AtoN('ao'),'ë¬ëí¸')163 sheet11.write(i,AtoN('ap'),'Y')164 sheet11.write(i,AtoN('aq'),'01')165 sheet11.write(i,AtoN('as'),'01')166 sheet11.write(i,AtoN('aw'),'01|03\n02|03\n03|03\n04|05')167 sheet11.write(i,AtoN('ax'),'01')168 sheet11.write(i,AtoN('ba'),'891045')169 sheet11.write(i,AtoN('bb'),'23759100')170 sheet11.write(i,AtoN('bc'),'ìíìì¸ì¤ëª
참조')171 sheet11.write(i,AtoN('bd'),'23756033')172 sheet11.write(i,AtoN('be'),'ìíìì¸ì¤ëª
참조')173 sheet11.write(i,AtoN('bf'),'11905')174 sheet11.write(i,AtoN('bg'),'ìíìì¸ì¤ëª
참조')175 sheet11.write(i,AtoN('bh'),'23760413')176 sheet11.write(i,AtoN('bi'),'ìíìì¸ì¤ëª
참조')177 sheet11.write(i,AtoN('bj'),'11800')178 sheet11.write(i,AtoN('bk'),'ìíìì¸ì¤ëª
참조')179 sheet11.write(i,AtoN('cs'),'Y')180 sheet11.write(i,AtoN('ct'),'N')181 sheet11.write(i,AtoN('cy'),'01')182 sheet11.write(i,AtoN('cz'),'01')183 sheet11.write(i,AtoN('da'),'00099')184 sheet11.write(i,AtoN('db'),'1249484')185 sheet11.write(i,AtoN('dc'),'02')186 sheet11.write(i,AtoN('df'),'N')187 sheet11.write(i,AtoN('dg'),'03')188 sheet11.write(i,AtoN('dj'),'01')189 sheet11.write(i,AtoN('dl'),'ìí ì¶ê³ ì§/ë°íêµí 주ìê° ë¬ë¼ì ìëìê±°ì ìê° ë¶ê°í©ëë¤. A/S를 ìíì¤ ê²½ì° í매ììê² ì°ë½ì£¼ìê±°ë ê²ìíì ë¨ê²¨ì£¼ìë©´ ìë´í´ ëë¦¬ê² ìµëë¤. ë¨, ì¼ë¶ í목ì ê²½ì° A/Sê° ë¶ê°ë¥ í ì ììµëë¤.')190 sheet11.write(i,AtoN('dm'),'ìí ì¶ê³ ì§/ë°íêµí 주ìê° ë¬ë¼ì ìëìê±°ì ìê° ë¶ê°í©ëë¤. ë°íì ìíì¤ ê²½ì° í매ììê² ì°ë½ì£¼ìê±°ë ê²ìíì ë¨ê²¨ì£¼ìë©´ ìë´í´ ëë¦¬ê² ìµëë¤.')191 # print('\\'.join(openFile.name.split('/')[0:-1])+'\\Naver_To_EMS_11st.xls')192 wtBook.save('\\'.join(openFile.name.split('/')[0:-1])+'\\Naver_To_EMS_11st.xls')...
netutils.py
Source:netutils.py
...8 except socket.error:9 raise #ValueError, "La stringa %s non e' un valido indirizzo IP" % addr10 return addr_ntoa11inet_ntoa = addr_ntoa12def addr_aton(addr):13 try:14 addr_aton = struct.unpack('!L', socket.inet_aton(addr))[0]15 except socket.error:16 raise ValueError, "La stringa %s non e' un valido indirizzo IP" % addr17 return addr_aton18inet_aton = addr_aton19def get_aton_bounds_from_cidr(base, bits):20 aton_base = inet_aton(base)21 full_aton_mask = 2**32 - 122 aton_mask = 2**(32 - bits) - 123 aton_haddr = aton_base | aton_mask24 aton_laddr = aton_base & (full_aton_mask - aton_mask)25 return (aton_laddr, aton_haddr)26def get_bounds_from_cidr(base, bits):27 aton_laddr, aton_haddr = get_aton_bounds_from_cidr(base, bits)28 return addr_ntoa(aton_laddr), addr_ntoa(aton_haddr)29def get_aton_bounds_from_ip_mask(ip, mask):30 aton_base = inet_aton(ip)31 aton_mask = 2**32 - 1 - inet_aton(mask)32 full_aton_mask = 2**32 - 133 aton_haddr = aton_base | aton_mask34 aton_laddr = aton_base & (full_aton_mask - aton_mask)35 return (aton_laddr, aton_haddr)36def ip_is_inside_inet_aton_range(ip, laddr_aton, haddr_aton):37 ip_aton = addr_aton(ip)38 if (ip_aton <= haddr_aton) and (ip_aton >= laddr_aton):39 return True40 else:41 return False42def ip_is_inside_inet_aton_ranges(ip, aton_ranges):43 ip_aton = addr_aton(ip)44 for laddr_aton, haddr_aton in aton_ranges:45 if (ip_aton <= haddr_aton) and (ip_aton >= laddr_aton):46 return True47 return False48def ip_is_inside_range(ip, laddr, haddr):49 laddr_aton = addr_aton(laddr)50 haddr_aton = addr_aton(haddr)51 return ip_is_inside_inet_aton_range(ip, laddr_aton, haddr_aton)52def explode_ip_range(laddr, haddr):53 laddr_aton = addr_aton(laddr)54 haddr_aton = addr_aton(haddr)55 ip_addrs = map(lambda x: addr_ntoa(x), range(laddr_aton, haddr_aton))56 return ip_addrs57private_ip_ranges = [58 ('192.168.0.0', '192.168.255.255'), ('172.16.0.0', '172.31.255.255'),59 ('10.0.0.0', '10.255.255.255')60]61exp_ip_ranges = [('224.0.0.0', '255.255.255.255')]62aton_private_ranges = map(lambda r: (addr_aton(r[0]), addr_aton(r[1])),63 private_ip_ranges)64aton_exp_ip_ranges = map(lambda r: (addr_aton(r[0]), addr_aton(r[1])),65 exp_ip_ranges)66#------------------------------------------------------------------------------67# TEST network utilities68def aaaa(addr):69 public_srv_addrs = []70 c = 071 for aton_r in aton_private_ranges:72 if ip_is_inside_inet_aton_range(addr, aton_r[0], aton_r[1]):73 break74 else:75 c += 176 if c == len(aton_private_ranges):77 public_srv_addrs.append(addr)78 return public_srv_addrs...
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!!