Best Python code snippet using avocado_python
caigoushunyiSpider.py
Source:caigoushunyiSpider.py
...61 """62 # è·åå°æ´ä¸ªé¡µé¢çæ°æ®ä¿¡æ¯63 all_content = ''.join(response.xpath("//tr[@valign='top']").xpath("string(.)").extract())64 # å¼æ æ¶é´65 parse_opentime = parse_name(parse_name(all_content, re_parse_address__openTime_bidDeadline), re_parse_openTime) if parse_name(all_content, re_parse_address__openTime_bidDeadline) else ''66 # ææ æªæ¢æ¶é´67 parse_biddeadline = parse_name(parse_name(all_content, re_parse_address__openTime_bidDeadline), re_parse_bidDeadline) if parse_name(all_content,re_parse_address__openTime_bidDeadline) else ''68 # å¼æ å°ç¹69 parse_address = parse_name(parse_name(all_content, re_parse_address__openTime_bidDeadline),re_parses_address) if parse_name(all_content, re_parse_address__openTime_bidDeadline) else ''70 # å
¬åæé71 parse_noticetime = parse_name(all_content, re_parse_noticeTime) if parse_name(all_content, re_parse_noticeTime) else ''72 # éè´äººåä½å称73 parse_company = parse_name(parse_name(all_content, re_parse_caigou), re_parse_company) if parse_name(all_content, re_parse_caigou) else ''74 # éè´åä½è系人75 parse_purchase_person = parse_name(parse_name(all_content, re_parse_caigou), re_parse__purchase_person) if parse_name(all_content, re_parse_caigou) else ''76 # éè´åä½èç³»æ¹å¼77 parse__purchase_telephone = parse_name(parse_name(all_content, re_parse_caigou), re_parse__purchase_telephone) if parse_name(all_content, re_parse_caigou) else ''78 # åå®æ¶é´79 parse_priceTime = parse_name(parse_name(all_content, re_parse_priceTimeAndbidDocument), re_parse_priceTime) if parse_name(all_content, re_parse_priceTimeAndbidDocument) else ''80 # åå®å°ç¹81 parse_bidDocument = parse_name(parse_name(all_content, re_parse_priceTimeAndbidDocument),re_parse_bidDocument) if parse_name(all_content,re_parse_priceTimeAndbidDocument) else ''82 # 代çæºæå称83 parse_agency = parse_name(parse_name(all_content, re_parse_daili), re_parse_agency) if parse_name(all_content, re_parse_daili) else ''84 # 代çæºæè系人85 parse_agency_person = parse_name(parse_name(all_content, re_parse_daili), re_parse_agency_person) if parse_name(all_content, re_parse_daili) else ''86 # 代çæºæèç³»æ¹å¼87 parse_agency_telephone = parse_name(parse_name(all_content, re_parse_daili), re_parse_agency_telephone) if parse_name(all_content, re_parse_daili) else ''88 # é¢ç®éé¢89 parse_budget = parse_name(all_content, re_parse_budget)90 """91 æ¹å¼äºï¼ä»¥pæ ç¾çå½¢å¼ç´æ¥å¨é¡µé¢ä¸éè¿æ£åè·åå段æ°æ®92 """93 p_list = response.xpath('//tr[@valign="top"]//p')94 bid_content = "\n".join([ParsePipeline.process_content(p.xpath('.//text()').extract()) for p in p_list])95 budget = parse_name(bid_content, re_budget)96 project = parse_name(bid_content, re_project)97 company = parse_name(bid_content, re_company)98 noticeTime = parse_name(bid_content, re_noticeTime)99 pricetime = parse_name(bid_content, re_priceTime)100 bidDocument = parse_name(bid_content, re_bidDocument)101 bidDeadline = parse_name(bid_content, re_bidDeadline)102 openTime = parse_name(bid_content, re_openTime)103 address = parse_name(bid_content, re_address)104 agency = parse_name(bid_content, re_agency)105 purchase_demand = parse_name(all_content, re_purchase_demand)106 agency_person = parse_name(bid_content, re_agency_person)107 purchase_telephone = parse_name(bid_content, re_purchase_telephone)108 purchase_person = parse_name(bid_content, re_purchase_person)109 agency_telephone = parse_name(bid_content, re_agency_telephone)110 """111 è·åå段æ°æ®112 """113 item['url'] = response.url114 item['company'] = company if company else parse_company115 item['purchase_person'] = purchase_person if purchase_person else parse_purchase_person116 item['purchase_telephone'] = purchase_telephone if purchase_telephone else parse__purchase_telephone117 item['agency'] = agency if agency else parse_agency118 item['agency_person'] = agency_person if agency_person else parse_agency_person119 item['agency_telephone'] = agency_telephone if agency_telephone else parse_agency_telephone120 item['inserttime'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")121 item['project'] = project if project else re.findall(r'(.*)ææ å
Œ', item['title'])[0]122 item['bidDocument'] = parse_bidDocument if parse_bidDocument else bidDocument123 item['budget'] = budget if budget else parse_budget...
ArrowTagger.py
Source:ArrowTagger.py
1import PIL.Image, PIL.ImageTk2from tkinter import *3import cv24import numpy as np5import os6import ParseArrow7PARSE_PATH = ParseArrow.PARSE_PATH8PARSE_NAME = ParseArrow.PARSE_NAME9PARSE_LOG = ParseArrow.PARSE_LOG10TAG_PATH = "./TaggedArrow/"11TAG_LOG = "00TagProgress.txt"12class ArrowTagger:13 def __init__(self):14 print("Let's start tagging...")15 self.root = Tk()16 #self.frame = Frame(self.root,width=300,height=300)17 self.root.bind("<Left>",self.LeftKey)18 self.root.bind("<Right>",self.RightKey)19 self.root.bind("<Up>",self.UpKey)20 self.root.bind("<Down>",self.DownKey)21 self.root.bind("<Button-3>",self.UndoTag)22 self.root.bind("<Button-2>",self.putoff)23 # Variables24 self.left = 0 # Number of each type of images25 self.right = 026 self.down = 027 self.up = 028 self.toTag = 0 # Tag progress29 self.ReadProgress()30 self.log = [] # Working log31 # Open file32 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag33 self.img = cv2.imread(self.workingFile)34 cv2.namedWindow("Arrow")35 cv2.imshow("Arrow",self.img)36 def UndoTag(self,event):37 if not self.log:38 print("Nothing to undo")39 return40 print("\tUndo")41 self.toTag -= 142 last_job = self.log.pop()43 if last_job is 'left':44 self.left -= 145 os.rename(TAG_PATH+'left_%d.bmp' % self.left, PARSE_PATH + PARSE_NAME % self.toTag)46 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag47 self.img = cv2.imread(self.workingFile)48 cv2.imshow("Arrow",self.img)49 self.saveProgress()50 elif last_job is 'right':51 self.right -= 152 os.rename(TAG_PATH+'right_%d.bmp' % self.right, PARSE_PATH + PARSE_NAME % self.toTag)53 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag54 self.img = cv2.imread(self.workingFile)55 cv2.imshow("Arrow",self.img)56 self.saveProgress()57 elif last_job is 'up':58 self.up -= 159 os.rename(TAG_PATH+'up_%d.bmp' % self.up, PARSE_PATH + PARSE_NAME % self.toTag)60 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag61 self.img = cv2.imread(self.workingFile)62 cv2.imshow("Arrow",self.img)63 self.saveProgress()64 elif last_job is 'down':65 self.down -= 166 os.rename(TAG_PATH+'down_%d.bmp' % self.down, PARSE_PATH + PARSE_NAME % self.toTag)67 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag68 self.img = cv2.imread(self.workingFile)69 cv2.imshow("Arrow",self.img)70 self.saveProgress()71 print("Now working on: %d" % self.toTag)72 def putoff(self,event):73 print("\t141")74 self.toTag += 175 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag76 self.img = cv2.imread(self.workingFile)77 cv2.imshow("Arrow",self.img)78 self.saveProgress()79 print("Now working on: %d" % self.toTag)80 def LeftKey(self,event):81 print("\tLeft Key pressed.")82 os.rename(self.workingFile,TAG_PATH + 'left_%d.bmp' % self.left)83 self.log.append('left')84 self.left += 185 self.toTag += 186 self.saveProgress()87 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag88 self.img = cv2.imread(self.workingFile)89 cv2.imshow("Arrow",self.img)90 print("Now working on: %d" % self.toTag)91 def RightKey(self,event):92 print("\tRight Key pressed.")93 os.rename(self.workingFile,TAG_PATH + 'right_%d.bmp' % self.right)94 self.log.append('right')95 self.right += 196 self.toTag += 197 self.saveProgress()98 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag99 self.img = cv2.imread(self.workingFile)100 cv2.imshow("Arrow",self.img)101 print("Now working on: %d" % self.toTag)102 def UpKey(self,event):103 print("\tUp Key pressed.")104 os.rename(self.workingFile,TAG_PATH + 'up_%d.bmp' % self.up)105 self.log.append('left')106 self.up += 1107 self.toTag += 1108 self.saveProgress()109 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag110 self.img = cv2.imread(self.workingFile)111 cv2.imshow("Arrow",self.img)112 print("Now working on: %d" % self.toTag)113 def DownKey(self,event):114 print("\tDown Key pressed.")115 os.rename(self.workingFile,TAG_PATH + 'down_%d.bmp' % self.down)116 self.log.append('down')117 self.down += 1118 self.toTag += 1119 self.saveProgress()120 self.workingFile = PARSE_PATH + PARSE_NAME % self.toTag121 self.img = cv2.imread(self.workingFile)122 cv2.imshow("Arrow",self.img)123 print("Now working on: %d" % self.toTag)124 def ReadProgress(self):125 try:126 tag_log = open(TAG_PATH+TAG_LOG,'r')127 except FileNotFoundError:128 print("Tagging log file not found. variables set to 0")129 return130 self.toTag = int(tag_log.readline().replace("\n",""))131 self.left = int(tag_log.readline().replace("\n",""))132 self.right = int(tag_log.readline().replace("\n",""))133 self.up = int(tag_log.readline().replace("\n",""))134 self.down = int(tag_log.readline())135 136 def saveProgress(self):137 print("Save start...")138 f = open(TAG_PATH + TAG_LOG,'w')139 f.write("%d\n" % self.toTag)140 f.write("%d\n" % self.left)141 f.write("%d\n" % self.right)142 f.write("%d\n" % self.up)143 f.write("%d" % self.down)...
parser.py
Source:parser.py
...50 return out51def parse_create_table():52 if not alt(match, 'CREATE TABLE '):53 return54 name = parse_name()55 with parens():56 columns =many(parse_column_spec)57 return CreateTable(name, columns)58def parse_alter_table():59 if not alt(match, 'ALTER TABLE '):60 return61 table = parse_name()62 alteration = (parse_add_constraint()63 or parse_alter_column()64 or fail())65 return AlterTable(table, alteration)66def parse_alter_column():67 if not alt(match, 'ALTER COLUMN '):68 return69 name = parse_name()70 alteration = parse_set_default() or parse_drop_default() or fail()71 return AlterColumn(name, alteration)72def parse_set_default():73 if not alt(match, 'SET DEFAULT '):74 return75 return SetDefault(parse_value())76def parse_drop_default():77 if not alt(match, 'DROP DEFAULT'):78 return79 return DropDefault()80def parse_value():81 return match('".*"')82def parse_add_constraint():83 if not alt(match, "ADD CONSTRAINT "):84 return85 name = parse_name()86 constraint = parse_unique_constraint() or parse_add_foreign_key() or fail()87 return AddConstraint(name, constraint)88def parse_unique_constraint():89 if alt(match, 'UNIQUE '):90 with parens():91 return UniqueConstraint(parse_name_list())92def parse_add_foreign_key():93 if not alt(match, "FOREIGN KEY "):94 return95 with parens():96 name = parse_name()97 match('REFERENCES ')98 table = parse_name()99 with parens():100 cols = parse_name_list()101 return ForeignKey(name, table, cols)102def parse_create_index():103 if not alt(match, "CREATE INDEX "):104 return105 name = parse_name()106 match("ON ")107 table = parse_name()108 with parens():109 cols = parse_name_list()110 return CreateIndex(name, table, cols)111def parse_name_list():112 """ parse (`col1`, `col2` ...) """113 cols = []114 while True:115 cols.append(parse_name())116 if not alt(match, ', '):117 return cols118@contextmanager119def parens():120 match('\(')121 yield122 match('\) *')123parse_name = lambda: match('`([^`]+)` *')124def parse_column_spec():125 out = CreateTable.ColumnSpec(126 name=parse_name(),127 type=match('(\w+) ?'),128 required=bool(match('NOT NULL ?|')),129 primary_key=bool(match('PRIMARY KEY ?|')),130 unique=bool(match('UNIQUE ?|'))131 )132 match(', |')133 return out134def parse_release_savepoint():135 if not alt(match, "RELEASE SAVEPOINT "):136 return137 return ReleaseSavepoint(parse_name())138def parse_rollback():139 if not alt(match, "ROLLBACK TO SAVEPOINT "):140 return141 return RollbackToSavepoint(parse_name())142def parse_show_tables():143 if alt(match, "SHOW TABLES"):...
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!!