def get(Resource): now = datetime.datetime.now() template = render_template( 'imports.html', resource={ 'title': 'Imports - reale value', 'icon_path': ''.join([Config.STATIC_URL, '/logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'description': 'List procesing oferts from catalog', 'year': now.year, 'dt_table': [ 'ID', 'Title', 'ID entry point', 'Name', 'Manufacturer', 'Cretaion date', ] }, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' return resp
def get(self): today = datetime.date.today() s = Services() meta_category_id = random.randrange(1, 20, 1) now = datetime.datetime.now() result = s.get_list_product_by_meta_category_id( meta_category_id, today) wyn = result.paginate(1, 32) template = render_template( 'index.html', resource={ 'title': 'Price - reale value', 'icon_path': ''.join([Config.STATIC_URL, '/logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'description': 'Friendly prices search engine', 'year': now.year, 'category': get('http://127.0.0.1:7001/definitions_meta_category/{}'. format(meta_category_id)).get('name'), # noqa E501 }, entities=wyn.items, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' return resp
def _get_tagging_info(self): addr = 'http://127.0.0.1:7001/tager_result/{}'.format( self.imp_catalog_page_id) result = get(addr) if result: product = result.get('product') category = result.get('category') self.name = product.get('name') self.brand = product.get('brand') self.category = [cat.get('category') for cat in category]
def get_product_for_view(self, brand, name, scan_date): cp = CatalogPage() pi = ProductImgDbu() result_list = [] catalog_page_id_lst = [] product_dsc = [] product_img = [] for ent in cp.get_product_view(brand, name, scan_date): product_info = get('http://127.0.0.1:7001/catalog_product/{}'.format(ent.imp_catalog_page_id)) if not product_info: product_info = get('http://127.0.0.1:7001/catalog_product/{}/{}'.format(ent.imp_catalog_page_id, scan_date)) # noqa E501 else: product_dsc.append(product_info.get('description')) product_category = get('http://127.0.0.1:7001/product_category/{}'.format(ent.product_shop_id)) line = { 'id': ent.id, 'name': ent.name, 'brand': ent.brand, 'product_url': ent.product_url, 'shop_id': ent.shop_id, 'product_shop_id': ent.product_shop_id, 'imp_catalog_page_id': ent.imp_catalog_page_id, 'shop_name': get('http://127.0.0.1:7001/shop/{}'.format(ent.shop_id)).get('name'), 'product_title': product_info.get('title'), # noqa E501 'price': ent.price, 'currency': ent.currency, 'path_thumbs': ent.path_thumbs, 'category': product_category, } catalog_page_id_lst.append(ent.imp_catalog_page_id) result_list.append(line) for images in pi.get_by_imp_catalog_page_id(ent.imp_catalog_page_id): product_img.append(images) return { 'result_list': result_list, 'product_dsc': product_dsc, 'product_img': product_img, }
def get(self, category, page_id): s = Services() today = datetime.date.today() meta_category_id = get( 'http://127.0.0.1:7001/definitions_meta_category/{}'.format( category)).get('id') result = s.get_list_product_by_meta_category_id( meta_category_id, today) count = result.count() log.debug('Result %r', result) wyn = result.paginate(page_id, 32) template = render_template( 'she_category.html', resource={ 'title': '2py.eu', 'icon_path': ''.join([Config.STATIC_URL, 'logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'category': category, 'page': page_id, 'count': count, 'max_page': int(count / 32) if count % 32 == 0 else int(count / 32) + 1 }, entities=wyn.items, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' return resp
def get(self): now = datetime.datetime.now() """ config = { 'title': 'Tags by counting', 'dt_header': [ 'Tag Id', 'Tag name', 'Count' ], 'date': ct.get_category_for_menu() } """ template = render_template( 'dt.html', resource={ 'title': 'Tags by counting', 'icon_path': ''.join([Config.STATIC_URL, '/logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'description': 'Tags by counting', 'year': now.year, 'dt_table': [ 'Tag Id', 'Tag name', 'Meaning', 'Count', ], 'dt_config': { 'ajax': 'dt_tags', } }, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' return resp
def get_product_info(self): addr = 'http://127.0.0.1:7001/catalog_product/{}/{}'.format( self.imp_catalog_page_id, self.scan_date) result = get(addr) self.price = result.get('price') self.currency = result.get('currency') self.product_url = result.get('url') self.entry_point_id = result.get('entry_point_id') self.images.append({ 'path_big': None, 'path_thumbs': result.get('img'), 'img_source': 'imp_catalog_page', 'orginal_images_id': self.imp_catalog_page_id })
def get(self, brand, name): s = Services() today = datetime.date.today() result = s.get_product_for_view(brand, name, today) log.info('Result %r ', result) template = render_template( 'product_views.html', resource={ 'title': '2py.eu', 'product_title': name, 'product_brand': brand, 'icon_path': ''.join([Config.STATIC_URL, 'logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'category': '', # entry_point.url, }, entities=result, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' return resp
def _get_product_images(self): addr = 'http://127.0.0.1:7001/catalog_imagse/{}'.format( self.imp_catalog_page_id) result = get(addr) if result: for img in result: self.images.append({ 'path_big': img.get('big'), 'path_thumbs': img.get('thumbs'), 'img_source': 'imp_product_page', 'orginal_images_id': self.imp_catalog_page_id })
def add_category_synonym(value): from price.modules.tager.services import Services from price.modules.imp_price.services import Services as ImpServices from price.tasks import add_category_assignment s = Services() imps = ImpServices() s.add_category_synonym(value) list_imp_catalog_page_id = get( 'http://127.0.0.1:7001/catalog_page_search/category/{}'.format(value)) for imp_catalog_page_id in list_imp_catalog_page_id: tp = imps.get_tagging_product(imp_catalog_page_id) if tp: log.info('Order category_assignment ImpID: {} Title: {}'.format( imp_catalog_page_id, tp.get('catalog_title'))) add_category_assignment.delay(tp) for imp_catalog_page_id in list_imp_catalog_page_id: tp = imps.get_tagging_product(imp_catalog_page_id) if tp: log.info('Order tagging_product ImpID: {} Title: {}'.format( imp_catalog_page_id, tp.get('catalog_title'))) tagging_product(imp_catalog_page_id, tp.get('catalog_title'))
def get_shop_id(self, entr_point_id): addr = 'http://127.0.0.1:7001/entry_point/{}'.format(entr_point_id) result = get(addr) log.debug('Shop: %r', result) if result: self.shop_id = result.get('shop_id')
def get(self, entry_point_id, page=1): # now = datetime.datetime.now() pdbu = ProductDbUtils() epdbu = EntryPointsDbUtils() entry_point = epdbu.get_entry_point_by_id(entry_point_id) result = None count = 1 o = pdbu.bq_get_unique_oferts(entry_point_id=entry_point_id, create_date=date.today()) count = o.count() wyn = o.paginate(page, 32) result = datetime.datetime.now() if wyn: entit = [{ 'product_id': None, 'title': getattr(i, 'title'), 'image': i.image, 'count': i.count, 'price': i.price, 'currency': 'zł', 'hash': '', 'brand': i.main_brand, 'product_url': i.url, } for i in wyn.items] else: entit = [] entities = entit entities = entit template = render_template( 'entry_point.html', resource={ 'title': '2py.eu', 'description': 'Selected entry point: {}'.format(entry_point.url), 'icon_path': ''.join([Config.STATIC_URL, 'logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'scan_date': result, 'menu': menu, 'category': entry_point.url, 'page': page, 'count': count, 'max_page': int(count / 32) if count % 32 == 0 else int(count / 32) + 1 }, entities=entities, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' return resp
def get(self, product): count = 0 page = 1 result = None entities = [] wyn = product u = UrlUtils() pdu = ProductDbUtils() o = pdu.get_product_by_product_def_id(wyn) tit = pdu.get_product_title_by_id(wyn) now = datetime.datetime.now() entities = [ { 'product_id': i.product_id, 'ofert_id': i.ofert_id, 'title': i.title, 'url': i.url, 'domain': u.get_domain(i.url), 'image': i.image, 'max_price': i.price, # i.max_price, 'avg_price': None, # i.avg_price, 'min_price': None, # i.min_price, 'count_visit': None, # i.count_visit, 'recent_visits_data': now, # i.recent_visits_data, 'currency': i.currency, 'hash': i.control_sum, 'manufacturer': i.brand_name.capitalize(), # i.manufacturer 'tags': i.tags.split(';'), } for i in o ] template = render_template( 'product.html', resource={ 'title': '2py.eu', 'description': '{}'.format(' '.join( [tit[1].capitalize(), tit[3].capitalize()])), 'brand_image': tit[2], 'icon_path': ''.join([Config.STATIC_URL, '/logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'scan_date': result, 'menu': menu, 'category': 'Dupa', 'page': page, 'count': count, 'max_page': int(count / 32) if count % 32 == 0 else int(count / 32) + 1 }, entities=entities, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' log.info('To jest wynik %r', menu) return resp
def get(self): result = None entities = [] _sql = """ WITH stat AS ( SELECT ep.id, ep.shop_id, ep.url, o.creation_date::date AS c_date, COUNT(o.id) as ile FROM price_ofert AS o JOIN price_entry_point AS ep ON ep.id = o.entry_point_id JOIN price_shop AS s ON s.id = ep.shop_id WHERE o.creation_date::date > CURRENT_DATE - 4 GROUP BY ep.id, ep.url, ep.shop_id, o.creation_date::date ) SELECT pep.id as ep_id, pep.url as entry_point, ps.url, COALESCE(s3.ile, 0) AS i3, COALESCE(s2.ile, 0) AS i2, COALESCE(s1.ile, 0) AS i1, COALESCE(s0.ile, 0) AS i0, CASE WHEN COALESCE(s0.ile, 0) > COALESCE(s1.ile, 0) THEN '↑' WHEN COALESCE(s0.ile, 0) < COALESCE(s1.ile, 0) THEN '↓' ELSE '=' END as dynamic FROM price_shop AS ps JOIN price_entry_point AS pep ON pep.shop_id = ps.id LEFT JOIN stat As s0 ON s0.id = pep.id AND s0.c_date = CURRENT_DATE LEFT JOIN stat As s1 ON s1.id = pep.id AND s1.c_date = CURRENT_DATE - 1 LEFT JOIN stat As s2 ON s2.id = pep.id AND s2.c_date = CURRENT_DATE - 2 LEFT JOIN stat As s3 ON s3.id = pep.id AND s3.c_date = CURRENT_DATE - 3 WHERE ps.active = True AND ps.deleted = False ORDER BY ps.url """ result = db.engine.execute(_sql) fields = result.keys() entities = [ { field: getattr(i, field) # noqa E122 for field in fields # noqa E122 } for i in result ] template = render_template( 'shops.html', resource={ 'title': '2py.eu', 'description': 'Shops list', 'icon_path': ''.join([Config.STATIC_URL, '/logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'menu': menu, 'fields': fields, 'fields_name': [ 'Entry point ID', 'URL', 'Shop url', 'T - 3 days', 'T - 2 days', 'T - 1 day', 'Today', 'Dynamic', ] }, entities=entities, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' log.info('To jest wynik %r', menu) return resp
def get(self, category, page=1): pdu = ProductDbUtils() ct = db_utils.CategoryDbUtils() category_id = ct.get_category_id_by_slug(category) count = 0 """ result = db.session.query(func.max(Ofert.creation_date)).first() if result[0]: o = db.session.query( Ofert.title, Ofert.image, Ofert.price, Ofert.currency, Image.control_sum, ).join(Image, Image.image == Ofert.image).filter( Ofert.creation_date >= result[0].date() ).order_by( Ofert.price.desc() ) count = o.count() wyn = o.paginate(page, 32) else: count = 0 wyn = {} """ o = pdu.get_product_for_catgeory_view(category_id) count = o.count() wyn = o.paginate(page, 32) result = datetime.datetime.now() if wyn: entit = [{ 'product_id': i.product_id, 'title': getattr(i, 'title'), 'image': i.image, 'count': i.count, 'min_price': i.min_price, 'max_price': i.max_price, 'currency': 'zł', 'hash': '', 'brand': i.brand } for i in wyn.items] else: entit = [] entities = entit template = render_template( 'category.html', resource={ 'title': '2py.eu', 'description': 'Wybrano kategorię: {}'.format(category), 'icon_path': ''.join([Config.STATIC_URL, 'logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'scan_date': result, 'menu': menu, 'category': category, 'page': page, 'count': count, 'max_page': int(count / 32) if count % 32 == 0 else int(count / 32) + 1 }, entities=entities, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' return resp
def get(self, tag): tdb = TagDbUtils() count = 0 page = 1 result = None entities = [] # wyn=tag u = UrlUtils() pdu = db_utils.TagDbUtils() o = pdu.get_product_by_tag(tag) meaning = tdb.get_meaning_by_tag(tag) now = datetime.datetime.now() meaning = meaning[0] if meaning[0] else 'Not set' entities = [ { 'product_id': i.product_id, 'ofert_id': i.ofert_id, 'title': i.title, 'url': i.url, 'domain': u.get_domain(i.url), 'image': i.image, 'max_price': i.price, # i.max_price, 'avg_price': None, # i.avg_price, 'min_price': None, # i.min_price, 'count_visit': None, # i.count_visit, 'recent_visits_data': now, # i.recent_visits_data, 'currency': i.currency, 'hash': i.control_sum, 'manufacturer': i.brand_name.capitalize(), # i.manufacturer 'tags': i.all_tags.split(';'), 'main_tags': i.tags.split(';'), 'category': i.category, 'subcategory': i.subcategory, 'colortags': i.colortags, } for i in o ] means_list = [{ 'label': mens.meaning } for mens in pdu.get_list_meaning()] # log.info('Resultset %r', means_list) template = render_template( 'tag.html', resource={ 'title': '2py.eu', 'description': 'Selected tag: "{}", meaning: "{}"'.format(tag, meaning), 'icon_path': ''.join([Config.STATIC_URL, '/logo.png']), 'real_url': Config.REAL_URL, 'static_url': Config.STATIC_URL, 'scan_date': result, 'menu': menu, 'category': tag, 'page': page, 'count': count, 'max_page': int(count / 32) if count % 32 == 0 else int(count / 32) + 1, 'meaning': means_list, 'tag': tag, }, entities=entities, new_menu=get('http://127.0.0.1:7001/menu'), menu=get('http://127.0.0.1:7001/price_menu'), ) resp = make_response(template) resp.mimetype = 'text/html' log.info('To jest wynik %r', menu) return resp