Exemplo n.º 1
0
    def __init__(self, url, name=None, price=None, _id=None):

        self.url = url
        store = Store.find_by_url(url)  # store where the item lives

        # price won't be a passing parameter anymore, it will be a query
        # we access python properties instead having to raise methods
        self.tag_name = store.tag_name

        # e.g. Item("Wool Blend Peacoat",
        # "http://www.johnlewis.com/kin-by-john-lewis-wool-blend-peacoat-navy/p3033177",
        # Store("John Lewis",
        #       "http://www.johnlewis.com/",
        #       "span",
        #       {"itemprop":"price","class":"now-price"}))
        self.pricequery = store.pricequery

        # the query result, a string price, will be stored to self.price
        # initially it will be None, subsequently it will download price from database
        self.price = None if price is None else price

        # when an Item is created, it won't automatically load price or name
        # one need to call the method to web scrape price and name

        # e.g. Item("Wool Blend Peacoat",
        # "http://www.johnlewis.com/kin-by-john-lewis-wool-blend-peacoat-navy/p3033177",
        # Store("John Lewis",
        #       "http://www.johnlewis.com/",
        #       "span",
        #       {"itemprop":"name"}))
        self.namequery = store.namequery
        # the query result, a string price, will be stored to self.price
        self.name = self.load_name() if name is None else name

        self._id = uuid.uuid4().hex if _id is None else _id
Exemplo n.º 2
0
 def __init__(self, name, url, price=None, _id=None):
     self.name = name
     self.url = url
     store = Store.find_by_url(url)
     self.tag_name = store.tag_name
     self.query = store.query
     self.price = None if price is None else price
     self._id = uuid.uuid4().hex if _id is None else _id
Exemplo n.º 3
0
 def __init__(self, name, url, _id=None):
     self.name = name
     self.url = url
     store = Store.find_by_url(url)
     tag_name = store.tag_name
     query = store.query
     self.price = self.load_price(tag_name, query)
     self._id = uuid.uuid4().hex if _id is None else _id
Exemplo n.º 4
0
 def __init__(self, url, name, category, price=None):
     self.url = url
     self.name = name
     self.category = category
     self.price = None if price is None else price
     store = Store.find_by_url(url)
     self.tag_name = store.tag_name
     self.query = store.query
Exemplo n.º 5
0
 def __init__(self, name, url, price= None,_id=None):
     self.name = name
     self.url = url
     store = Store.find_by_url(url)
     self.tag_name = store.tag_name
     self.query = store.query
     self.price = None if price is None else price
     self._id = uuid.uuid4().hex if _id is None else _id
Exemplo n.º 6
0
 def __init__(self, name, url, price=None,_id=None):
     self.name = name
     self.url = url
     store = Store.find_by_url(url)
     self.tag_name = store.tag_name
     self.query = store.query
     self.price = None if price is None else price   # self.load_price(tag_name, query)
     self._id = uuid.uuid4().hex if _id is None else _id
     print "INIT item" + "price:" + str(self.price)
Exemplo n.º 7
0
 def __init__(self, name, url, price=None, img_src=None, _id=None):
     self.name = name
     self.url = url
     store = Store.find_by_url(url)
     self.price_tag = store.price_tag
     self.price_query = store.price_query
     self.price = None if price is None else price
     self.img_src = self.get_img_src(store.img_query, store.img_src_tag) if img_src is None else img_src
     self._id = uuid.uuid4().hex if _id is None else _id
Exemplo n.º 8
0
 def __init__(self, name, url, price=None, _id=None):
     self.name = name
     store = Store.find_by_url(url)
     self.url = url
     # store hold the name of the element that represent price
     self.tag_name = store.tag_name
     # store will hold the specific query with attributes that match the tag
     self.query = store.query
     self.price = None if price is None else price
     self._id = uuid.uuid4().hex if _id is None else _id
Exemplo n.º 9
0
 def __init__(self, name, url, price=None, _id=None):
     self.name = name
     self.url = url
     try:
         self.store = Store.find_by_url(self.url)
     except StoreNotFoundError:
         self.store = None
     self.tag_name = self.store.tag_name if self.store is not None else None
     self.query = self.store.query if self.store is not None else None
     self.price = None if price is None else price
     self._id = uuid.uuid4().hex if _id is None else _id
Exemplo n.º 10
0
    def __init__(self, name, url, price=None, _id=None):
        # Sample Constructor
        # Item("John Lewis Curve Dining Chair, White",
        #     "http://www.johnlewis.com/house-by-john-lewis-curve-dining-chair-white/p231441579",
        #     Store("John Lewis", "http://www.johnlewis.com", "span", {"itemprop": "price", "class": "now-price"}))

        self.name = name
        self.url = url
        store = Store.find_by_url(url)
        self.tag_name = store.tag_name
        self.query = store.query
        self._id = uuid.uuid4().hex if _id is None else _id
        self.price = None if price is None else price
Exemplo n.º 11
0
    def __init__(self, name, url, price=None, img_src=None, _id=None):
        self.url = url
        self.name = name
        store = Store.find_by_url(url)

        self.price_tag_name = store.crawler.price_tag_name
        self.price_query = store.crawler.price_query
        self.price = price

        self.image_tag_name = store.crawler.image_tag_name
        self.image_query = store.crawler.image_query
        self.img_src = img_src

        self._id = uuid.uuid4().hex if _id is None else _id
Exemplo n.º 12
0
 def __init__(self,
              user_email,
              price_limit,
              item_id,
              active=True,
              store=None,
              last_checked=None,
              _id=None):
     self.user_email = user_email
     self.price_limit = float(price_limit)
     self.item = Item.get_by_id(item_id)
     self.last_checked = datetime.datetime.utcnow(
     ) if last_checked is None else last_checked
     self._id = uuid.uuid4().hex if _id is None else _id
     self.active = active
     store = Store.find_by_url(self.item.url)
     self.store = store.name
Exemplo n.º 13
0
def get_alert_page(alert_id):
    alert = Alert.find_by_id(alert_id)
    store = Store.find_by_url(alert.item.url)
    return render_template('alerts/alert.html', alert=alert, store=store)