Esempio n. 1
0
    def get(self):
        query = self.request.get("q")
        device = Device(name = "Nokia", user_agent = "Some_UserAgent")
        device.put()
        productInfo = ProductInfo(device = device, mobile_browser = "Qix40", device_os = "Symbian")
        productInfo.put()

        template_values = { "device": device, "productInfo": productInfo }
        path = os.path.join(os.path.dirname(__file__), "templates/device.html")
        page = template.render(path, template_values)
        self.response.out.write(page)
Esempio n. 2
0
    def select_info_by_phrase(self, phrase):
        """
        Query scraped info by phrase
        :param phrase: phrase for search
        :return: scraped info {phrase, title, price, page_size}
        """
        self.create_connection()
        try:
            cur = self.conn.cursor()
        except Error as e:
            print(e)
            print("Can't get db cursor.")

        sql = f"SELECT phrase,title,price,page_size FROM {_TABLE_NAME} WHERE phrase='{phrase}'"
        cur.execute(sql)

        rows = cur.fetchall()

        if len(rows) == 0:
            cur.close()
            self.close_connection()
            return None

        scrapeInfo = ScrapInfo(rows[0][0],
                               ProductInfo(rows[0][1], rows[0][2], rows[0][3]))

        cur.close()
        self.close_connection()
        return scrapeInfo
Esempio n. 3
0
    def get(self, product_id):

        # an Engine, which the Session will use for connection
        # resources
        some_engine = create_engine('postgresql://localhost:5432/junglescout')

        # create a configured "Session" class
        Session = sessionmaker(bind=some_engine)
        session = Session()

        entity = session.query(ProductInfo).get(product_id)

        if not entity:
            product_info_dict = get_product_info(product_id)
            entity = ProductInfo(id=product_id,
                                 categories=product_info_dict["Categories"],
                                 weight=product_info_dict["Weight"],
                                 dimensions=product_info_dict["Dimensions"],
                                 ranks=product_info_dict["Ranks"],
                                 lastFetched=datetime.datetime.now())
            session.add(entity)
            session.commit()

        return json.dumps(entity.to_dict()), 201
Esempio n. 4
0
def add_source_info(id):
    product = (Product.query.join(
        Category,
        Product.category == Category.id).filter(Product.id == id).first())
    if request.method == "POST":
        product_info = ProductInfo(
            source=request.form.get("name"),
            product=id,
            source_type=request.form.get("type"),
            price=request.form.get("price"),
            url=request.form.get("url"),
        )
        db.session.add(product_info)
        db.session.commit()
        flash("Successfully saved information")
    return render_template("add-shop.html", product=product)
Esempio n. 5
0
 def get_product_info(self, product_id) -> ProductInfo:
     r = self.request('get', 'products/{}'.format(product_id))
     return ProductInfo.from_dict(r.json())
Esempio n. 6
0
 def get_products_info(self) -> List[ProductInfo]:
     r = self.request('get', 'products')
     return ProductInfo.from_list(r.json())
- Allow the user to check to view the results.
"""

from fastapi import FastAPI, Query
from models import SearchTerms, ProductInfo, _SERVER_A_URL, _SERVER_B_URL
from typing import List
import requests
import aiohttp
import asyncio
from mydb import MyDB

mydb = MyDB()

app = FastAPI()

prodInfo = ProductInfo("test title", 41.6, 192.6)


@app.get("/")
def read_root():
    return {"Success": "This is server A on my test project using FastAPI."}

"""
Send asynchronous request to server B to scrap search_terms.
"""
def send_async_req(search_terms):
    req_sent = 0
    for term in search_terms:
        url = f"{_SERVER_B_URL}/amazon/{term}/scrap"
        requests.get(url)
        req_sent = req_sent + 1