def scraper_test_update(request,id): #get parameters index=int(request.REQUEST["index"]) fields={} for field in ['merchantItemTitle','pricePlusTax','priceEft','modelNameView','brand','mpnValue','shipping','inStock']: if field in request.REQUEST: fields[field]=request.REQUEST[field] #create merchantItem item=MerchantItem() for field in vars(item): if field in fields.keys(): setattr(item,field,fields[field]) else: setattr(item,field,None) #get test case data=TestCase.get(id=id) #update data.data[index]["meta.refitem"]=item.to_dict() data.save() #return authentication return HttpResponse( AIResponse().serialize() )
def matcher_test_update(request,id): #get parameters index=int(request.REQUEST["index"]) fields={} for field in ['merchantItemTitle','brand','mpnValue','item.itemId']: if field in request.REQUEST: tokens=field.split(".") if len(tokens)>1: fields[tokens[0]]={} fields[tokens[0]][tokens[1]]=request.REQUEST[field] else: fields[field]=request.REQUEST[field] #create merchantItem item=MerchantItem() for field in vars(item): if field in fields.keys(): setattr(item,field,fields[field]) else: setattr(item,field,None) #get test case data=TestCase.get(id=id) #update data.data[index]["meta.refitem"]=item.to_dict() data.save() #return authentication return HttpResponse( AIResponse().serialize() )
def _get_cached_merchant_items(self,merchantid): """ Belirli bir merchant icin cache'de kayitli merchant itemlari alir @type merchantid: str @param merchantid: itemlarin ait oldugu merchantin IDsi @rtype: list (L{cimri.api.cimriservice.data.merchantitem.MerchantItem}) @return: cache'de bulunan itemlarin listesi. cache bolumu yoksa ya da bir hata olusursa None """ #check if we should use the cache if "cache.read" not in self.task.meta: return None #get section to use section=self.task.meta["cache.read"] #read cache content=Cache(section).get("matcher.legacy.items."+str(merchantid)) if content is None: return None #parse try: return MerchantItem.list_from_json(content,[]) except Exception as e: return None
def test_check(request,id,tid): #get controller api api=ControllerAPI(request) report=api.gettaskresults(tid) #if ready, get urls if report[0]["status"]=="complete": #get test case data=TestCase.get(id=id) #set data data.data=report[0]["result"] #if batch, prepare the reference items if data.batch is not None: for index in range(len(data.data)): #find the batch reference data for this item xmlitem=data.data[index]['meta.xmlitem'] for batch in data.batch: if batch['merchant']['merchantId']==xmlitem['merchant']['merchantId'] and batch['merchantItemId']==xmlitem['merchantItemId']: #create merchantItem with values from the xml as reference item=MerchantItem() item.merchantItemTitle=xmlitem["merchantItemTitle"] item.brand=xmlitem["brand"] item.mpnValue=xmlitem["mpnValue"] item.item={"itemId":batch["item"]["itemId"]} data.data[index]["meta.refitem"]=item.to_dict() #update data.status=TestCase.STATUS_READY data.save() #return authentication return HttpResponse( AIResponse(data=data.data).serialize() )
def get_item(self,id,**args): """ Kullanilmiyor """ self.logger.info("api call...") #make call packet=self.call(Template("merchants/items/$id").substitute(id=id),args=args) #parse and return item items=MerchantItem.list_from_json(packet,["merchant"]) #return item return items[0] if items!=None else None
def get_items_by_mpn(self,**args): """ MPN degerlerine dayanarak merchant itemlari alir @type args: dict @param args: API call icin url parametreleri. desteklenen bazi parametreler: mpntype, mpnvalue, start (default=0), max (default=-1), fields (default=""), expandLevel (default=1) @rtype: L{cimri.api.cimriservice.data.merchantitem.MerchantItem} @return: MerchantItem listesi ya da hata durumunda None """ self.logger.info("api call...") #make call packet=self.call("merchants/items/search/mpn",args=args) if packet is None: return None #parse and return items return MerchantItem.list_from_json(packet,["merchantItem"])
def search_items(self,**args): """ Merchant itemlar icin arama yapar @type args: dict @param args: API call icin url parametreleri. desteklenen bazi parametreler: queryString, start (default==0), max (default==-1), status, fields (default==""), expandLevel (default==1) @rtype: L{cimri.api.cimriservice.data.merchantitem.MerchantItem} @return: MerchantItem listesi ya da hata durumunda None """ self.logger.info("api call...") #make call packet=self.call(Template("merchants/$id/items/search/title").substitute(id=id),args=args) if packet is None: return None #parse and return items return MerchantItem.list_from_json(packet,["merchantItem"])
def get_items(self,**args): """ Merchant itemlarini alir @type args: dict @param args: API call icin url parametreleri. desteklenen bazi parametreler: status, sid, start (default=0), max (default=-1), fields (default=""), expandLevel (default=1), catIds, catId, merchantId, sortField, sortOrder, filter, itemId, cimriUrl, mCatNames @rtype: L{cimri.api.cimriservice.data.merchantitem.MerchantItem} @return: MerchantItem listesi ya da hata durumunda None """ self.logger.info("api call...") #sample http://glacier.cimri.com:8080/cimri-service/merchants/items?status=1&max=10 packet=self.call("merchants/items",args=args) if packet is None: return None return MerchantItem.list_from_json(packet,["merchantItem"])
def get_items_by_category(self,**args): """ Kategoriye gore merchant itemlari alir @type args: dict @param args: API call icin url parametreleri. desteklenen bazi parametreler: mStatus, status, sortField, sortOrder, merchantId, start (default=0), max (default=-1), merchantCategory, filter, fields (default=""), expandLevel (default=1) @rtype: L{cimri.api.cimriservice.data.merchantitem.MerchantItem} @return: MerchantItem listesi ya da hata durumunda None """ self.logger.info("api call...") #sample http://glacier.cimri.com:8080/cimri-service/merchant/mItems/category?max-10 packet=self.call("merchants/mItems/category",args=args) if packet is None: return None #parse and return items return MerchantItem.list_from_json(packet,["merchantItem"])
def get_item_by_title(self,**args): """ Merchant item title'ina gore merchant itemlari alir @type args: dict @param args: API call icin url parametreleri. desteklenen bazi parametreler: status, merchantItemTitle, merchantId, start (default=0), max (default=-1), fields (default=""), expandLevel (default=1), merchantItemId @rtype: L{cimri.api.cimriservice.data.merchantitem.MerchantItem} @return: MerchantItem listesi ya da hata durumunda None """ self.logger.info("api call...") #make call packet=self.call("merchants/itembyTitle",args=args) if packet is None: return None #parse and return items return MerchantItem.list_from_json(packet,["merchantItem"])
def get_merchant_items(self,id,**args): """ Belli bir merchantin itemlarini alir @type id: str @param id: merchantId @type args: dict @param args: API call icin url parametreleri. desteklenen bazi parametreler: status, itemId, start (default==0), max (default==-1), fields (default==""), expandLebel (defaul==1) @rtype: L{cimri.api.cimriservice.data.merchantitem.MerchantItem} @return: MerchantItem listesi ya da hata durumunda None """ self.logger.info("api call...") #sample http://glacier.cimri.com:8080/cimri-service/merchants/2158/items packet=self.call(Template("merchants/$id/items").substitute(id=id),args=args) if packet is None: return None #parse and return items return MerchantItem.list_from_json(packet,["merchantItem"])
def test_new(request): #get merchants api=ControllerAPI(request) merchants=api.getmerchants() #create? if "action" in request.REQUEST and request.REQUEST["action"]=="update": #get parameters auto=int(request.REQUEST["auto"]) label=request.REQUEST["label"] module=request.REQUEST["module"] merchantid=request.REQUEST["merchant"] items=request.REQUEST["items"] #autogenerate samples? if auto==1: #find merchant name mname="*" if merchantid!="*": for merchant in merchants: if merchantid==merchant["id"]: merchantname=merchant["name"] #create data=TestCase() data.owner=request.session["user"].id data.label=label data.module=module data.op="match" if module.endswith("Matcher") else "scrap" data.target={"merchant":{"id":merchantid,"name":merchantname}} data.create() #create task to generate samples for the training data tasks=[] task=Task() task.target="cimri.module.automation.controller.Controller" task.op="controller.schedule" task.threadtags="test: "+label tasks.append(task) task=Task() task.target="cimri.module.crawler.productxml.ProductXMLCrawler" task.op="sample" if merchantid!="*": task.meta["merchants.id"]=int(merchantid) task.meta["sample.size"]=40 tasks.append(task) #create samples based on the provided list of item IDs else: #get items input=eval(items.replace("\n","")) items=[] for it in input: item=MerchantItem() item.merchant={"merchantId":str(it[0]).strip()} item.merchantItemId=str(it[1]).strip() item.item={"itemId":str(it[2]).strip()} items.append(item) #create data=TestCase() data.owner=request.session["user"].id data.label=label data.module=module data.op="match" if module.endswith("Matcher") else "scrap" data.target={} data.batch=[item.to_dict() for item in items] data.create() #create task to generate samples for the training data tasks=[] task=Task() task.target="cimri.module.automation.controller.Controller" task.op="controller.schedule" task.threadtags="test: "+label tasks.append(task) task=Task() task.target="cimri.module.crawler.productxml.ProductXMLCrawler" task.op="get" task.data=items task.meta={"workers":8} tasks.append(task) #schedule api=ControllerAPI(request) res=api.schedule(tasks) #get task id tid=res[1] #template context context=_get_context(request,section="common",content="content_test_created",test=data,tid=tid) else: #template context context=_get_context(request,section="common",content="content_test_new",merchants=merchants) #render return HttpResponse( get_template('template_content.html').render(Context(context)) )