def parseDeals(self): assert self.json items = self.json['urlset']['url'] for item in items: url = item['loc'] item = item['data']['display'] d = { 'title': item['title'], 'price': item['price'], 'value': item['value'], 'cate': item['category'], 'subcate': item['subcategory'], 'url': url, 'time': item["startTime"], } if self.timestamp > int(d['time']): continue if ensureAscii(item['city']) not in ['北京', '全国']: continue deal = Deal().create_item(d) if len(deal.title) * len(deal.cate) * len(deal.subcate) == 0: continue self.deals.append(deal)
def _trim(self): for key in ["title", "cate", "subcate"]: value = getattr(self, key, "") setattr(self, key, spaces2nbsp(ensureAscii(value))) for key in ["value", "price", "time"]: value = getattr(self, key, 0) try: setattr(self, key, int(float(value))) except: pass
def parseDeals(self): assert self.json items = self.json["response"]["deals"]["data"] for item in items: item = item["deal"] d = { "title": ensureAscii(item["deal_title"]), "price": item["price"], "value": item["value"], "cate": ensureAscii(item["deal_cate"]), "subcate": ensureAscii(item["deal_subcate"]), "url": ensureAscii(item["deal_url"]), "time": item["start_time"], } if self.timestamp > int(d["time"]): continue deal = Deal().create_item(d) self.deals.append(deal)