示例#1
0
def search_for(query):
    args = {'q': query, 'page_limit': '9', 'page': '1', "apikey": "88c6ww77pac55ybxsn5dmhqp"}
    rt_api = "http://api.rottentomatoes.com/api/public/v1.0/movies.json"
    myScraper = PyAl.Request(rt_api, args)
    theResult = myScraper.request.json

    return theResult['movies']
示例#2
0
def doSearch():
    q = sys.argv[1:]
    q = ' '.join(q)
    if len(q) < 5:
        return

    requestList = [
        "Operation=ItemSearch", "SearchIndex=KindleStore", "Sort=relevancerank"
    ]
    # requestList.append(urllib.urlencode({"Keywords": q}))
    # kw = q.replace(" ", ",")
    # requestList.append("Keywords=%s" % kw)

    requestDict = encodeRequestList(requestList, "ItemIds", keywords=q)

    searchRequest = PyAl.Request("http://webservices.amazon.co.uk/onca/xml",
                                 requestDict)
    soup = searchRequest.souper()

    resultsFeedback = PyAl.Feedback()
    if soup.find("error"):
        e = soup.error.message.string
        resultsFeedback.add(PyAl.Item(title="Bad Request", subtitle=e))

    else:
        asins = soup.find_all("asin")

        for asin in asins:
            aResult = getData(asin.string)
            resultItem = PyAl.Item()
            resultItem.fromDictionary(aResult)
            resultsFeedback.add(resultItem)

    print resultsFeedback
示例#3
0
def cacheIcon(url):
    iconRequest = PyAl.Request(url)

    covercache = PyAl.volatile("covercache")
    if not os.path.exists(covercache):
        os.makedirs(covercache)

    (_, filename) = os.path.split(url)
    iconPath = os.path.join(covercache, filename)
    with open(iconPath, "wb") as f:
        f.write(iconRequest.request.content)

    return iconPath
示例#4
0
def getData(asin):
    requestList = [
        "Operation=ItemLookup",
        "ItemId=%s" % asin,
    ]
    requestDict = encodeRequestList(requestList, "Medium")
    itemRequest = PyAl.Request("http://webservices.amazon.com/onca/xml",
                               requestDict)
    soup = itemRequest.souper()
    try:
        imageURL = soup.find("smallimage").url.string
        imagePath = cacheIcon(imageURL)
    except Exception:
        imagePath = "icon.png"
    try:
        link = soup.find("detailpageurl").string
    except Exception:
        link = "http://www.amazon.com/dp/%s" % asin
    try:
        title = soup.find("title").string
    except Exception:
        title = "Title Missing"
    try:
        author = soup.find("author").string
    except Exception:
        author = "Author Missing"
    try:
        price = soup.find("listprice").formattedprice.string
    except Exception:
        price = "Price Missing"

    returnDict = {
        "uid": asin,
        "arg": link,
        "title": title,
        "subtitle": u"%s\u2014%s" % (author, price),
        "icon": imagePath
    }

    return returnDict