Exemple #1
0
def shorten():
    if not ratelimits.check(request.remote_addr):
        return {"success": "false", "error": "You are being ratelimited."}

    if request.method != "POST":
        return {"success": "false", "error": "This route is POST only."}

    content = request.get_json()
    if not "url" in content:
        return {
            "success": False,
            "error": "The parameter 'url' does not exist.",
            "code": 1
        }

    if utils.checkIfProperURL(content.get("url")) is None:
        return {
            "success": False,
            "error": "That is not a proper url.",
            "code": 1
        }

    # url = utils.returnProperURL(content.get("url"))
    # TODO: Make the url config thing better lol
    try:
        id = utils.createID()
        db.addURL(id, content.get("url"), int(time.time()))
        return {"success": True, "id": id, "url": config.get("url")}
    except Exception:
        return {
            "success":
            False,
            "error":
            "Error has occurred while shortening. Please contact an administrator."
        }
def getAllProductsOfType(productType, logfn):
    url = f"https://www.southlondongallery.org/product-tag/{productType}/"
    logfn(url)
    soup = getHTML(url)

    tiles = soup.find_all(class_="tease-product")
    return [
        Product(createID(), tile.a["href"], tile.a.div.img["src"])
        for tile in tiles
    ]
Exemple #3
0
def getAllProductsOfType(productType, logfn):
    products = []

    base = "https://nottinghamcontemporary.shop"
    url = f"{base}/{productType}"
    logfn(url)

    soup = getHTML(url)

    items = soup.find_all(class_="Item--product")
    for item in items:
        products.append(
            Product(createID(), f"{base}{item.a['href']}", f"https:{extractImageUrlFromStyle(item.a.div.div.div['style'])}"))

    return products
def getPageOfProducts(pageNum, logfn):
    time.sleep(0.5)
    products = []
    base = "https://ica-bookstore.myshopify.com"

    url = f"{base}/collections/frontpage?page={pageNum}"
    logfn(url)
    soup = getHTML(url)

    items = soup.find_all(class_="grid-view-item")
    for item in items:
        products.append(
            Product(createID(), f"{base}{item.a['href']}",
                    f"https:{item.div.img['src']}"))

    return products
def getPageOfProducts(productType, pageNum, logfn):
    time.sleep(0.5)
    products = []
    base = "https://shop.tate.org.uk"

    url = f"{base}/{productType}/view-all-{productType}?start={(pageNum - 1) * 100}&sz=100"
    logfn(url)
    soup = getHTML(url)

    tiles = soup.find_all(class_="product-tile")
    for tile in tiles:
        products.append(
            Product(createID(), f"{base}{tile.div.a['href']}",
                    tile.div.img["src"]))

    return products
def getPageOfProducts(productType, pageNum, logfn):
    time.sleep(0.5)
    products = []

    base = "https://www.nationalgallery.co.uk"
    url = f"{base}/products/{productType}?orderBy=&VIEW_SIZE=100&VIEW_INDEX={pageNum}"

    logfn(url)
    soup = getHTML(url)

    items = soup.find_all(class_="productwrap")
    for item in items:
        products.append(
            Product(createID(), f"{base}{item.a['href']}", f"{base}{item.a.div.img['src']}"))

    return products
Exemple #7
0
def getPageOfProducts(pageNum, logfn):
    time.sleep(0.5)
    products = []
    base = "https://designmuseumshop.com"

    url = f"{base}/collections/all?page={pageNum}"
    logfn(url)
    soup = getHTML(url)

    items = soup.find(id="product-loop").find_all(class_="product-index-inner")
    for item in items:
        products.append(
            Product(createID(), f"{base}{item.a['href']}",
                    f"https:{item.a.img['src']}"))

    return products
def getPageOfProducts(productType, pageNum, logfn):
    time.sleep(0.5)
    products = []

    base = "https://shop.royalacademy.org.uk"
    url = f"{base}/{productType}?p={pageNum}"

    logfn(url)
    soup = getHTML(url)

    items = soup.find_all(class_="product-item-photo")
    for item in items:
        products.append(
            Product(createID(), item["href"], item.span.span.img["data-src"]))

    return products
Exemple #9
0
def getPageOfProducts(productType, pageNum, logfn):
    time.sleep(0.5)
    products = []

    base = "https://shop.southbankcentre.co.uk"
    url = f"{base}/{productType}?page={pageNum}"

    logfn(url)
    soup = getHTML(url)

    items = soup.find_all("a", class_="grid__image")
    for item in items:
        products.append(
            Product(createID(), f"{base}{item['href']}",
                    f"https:{item.img['src']}"))

    return products
def getPageOfProducts(pageNum, logfn):
    time.sleep(0.5)
    products = []
    base = "https://shop.manchesterartgallery.org"

    url = f"{base}/collections/all?page={pageNum}"
    logfn(url)
    soup = getHTML(url)

    items = soup.find_all(class_="product-card")
    for item in items:
        products.append(
            Product(
                createID(), f"{base}{item.a['href']}",
                f"https:{item.div.div.div.img['data-src']}".replace(
                    r"{width}", "200")))

    return products
Exemple #11
0
def getPageOfProducts(productType, page, logfn):
    time.sleep(0.5)
    products = []

    base = "https://shop.camdenartscentre.org"
    url = f"{base}/collections/{productType}?page={page}"
    logfn(url)

    soup = getHTML(url)
    tiles = soup.find_all(class_="product-card")

    for tile in tiles:
        img = tile.find(class_="grid-view-item__image")
        widths = img["data-widths"]  # e.g. '[180, 360, 540, 720]'
        width = widths[1:-1].split(",")[0]  # e.g. '180'
        img_url = f"https:{img['data-src'].replace('{width}', width)}"

        products.append(Product(createID(), f'{base}{tile.a["href"]}', img_url))

    return products