Exemple #1
0
def search_author(name):
    """Looking for an author"""
    response = web.getXML("https://www.goodreads.com/api/author_url/%s?key=%s" %
                          (urllib.parse.quote(name), context.config["goodreadskey"]))
    if response is not None and len(response.getElementsByTagName("author")) and response.getElementsByTagName("author")[0].hasAttribute("id"):
        response = web.getXML("https://www.goodreads.com/author/show/%s.xml?key=%s" %
                              (urllib.parse.quote(response.getElementsByTagName("author")[0].getAttribute("id")), context.config["goodreadskey"]))
        if response is not None and len(response.getElementsByTagName("author")):
            return response.getElementsByTagName("author")[0]
    return None
Exemple #2
0
def get_book(title):
    """Retrieve a book from its title"""
    response = web.getXML("https://www.goodreads.com/book/title.xml?key=%s&title=%s" %
                          (context.config["goodreadskey"], urllib.parse.quote(title)))
    if response is not None and len(response.getElementsByTagName("book")):
        return response.getElementsByTagName("book")[0]
    else:
        return None
Exemple #3
0
def search_books(title):
    """Get a list of book matching given title"""
    response = web.getXML("https://www.goodreads.com/search.xml?key=%s&q=%s" %
                          (context.config["goodreadskey"], urllib.parse.quote(title)))
    if response is not None and len(response.getElementsByTagName("search")):
        return response.getElementsByTagName("search")[0].getElementsByTagName("results")[0].getElementsByTagName("work")
    else:
        return []
Exemple #4
0
def search_author(name):
    """Looking for an author"""
    response = web.getXML(
        "https://www.goodreads.com/api/author_url/%s?key=%s" %
        (urllib.parse.quote(name), context.config["goodreadskey"]))
    if response is not None and len(
            response.getElementsByTagName("author")
    ) and response.getElementsByTagName("author")[0].hasAttribute("id"):
        response = web.getXML(
            "https://www.goodreads.com/author/show/%s.xml?key=%s" %
            (urllib.parse.quote(
                response.getElementsByTagName("author")[0].getAttribute("id")),
             context.config["goodreadskey"]))
        if response is not None and len(
                response.getElementsByTagName("author")):
            return response.getElementsByTagName("author")[0]
    return None
Exemple #5
0
def station_status(station):
    """Gets available and free status of a given station"""
    response = web.getXML(URL_API % station)
    if response is not None:
        available = int(response.getElementsByTagName("available")[0].firstChild.nodeValue)
        free = int(response.getElementsByTagName("free")[0].firstChild.nodeValue)
        return (available, free)
    else:
        return (None, None)
Exemple #6
0
def get_book(title):
    """Retrieve a book from its title"""
    response = web.getXML(
        "https://www.goodreads.com/book/title.xml?key=%s&title=%s" %
        (context.config["goodreadskey"], urllib.parse.quote(title)))
    if response is not None and len(response.getElementsByTagName("book")):
        return response.getElementsByTagName("book")[0]
    else:
        return None
Exemple #7
0
def search_books(title):
    """Get a list of book matching given title"""
    response = web.getXML(
        "https://www.goodreads.com/search.xml?key=%s&q=%s" %
        (context.config["goodreadskey"], urllib.parse.quote(title)))
    if response is not None and len(response.getElementsByTagName("search")):
        return response.getElementsByTagName("search")[0].getElementsByTagName(
            "results")[0].getElementsByTagName("work")
    else:
        return []
Exemple #8
0
 def __init__(self, terms):
     self.wfares = web.getXML(URL_API % quote(terms),
                              timeout=12)
Exemple #9
0
 def __init__(self, terms):
     self.wfares = web.getXML(URL_API % quote(terms), timeout=12)