Exemplo n.º 1
0
 def testXkcd(self):
     links = parser.findLinks(
         "http://xkcd.com/500/",
         "http://xkcd.com/501/")
     self.assertEqual(parser.getNext(
         "http://xkcd.com/25/", links[0][0], links[0][1])
         ,"http://xkcd.com/26/")
Exemplo n.º 2
0
 def testQuestionableContent(self):
     links = parser.findLinks(
         "http://www.questionablecontent.net/view.php?comic=1428",
         "http://www.questionablecontent.net/view.php?comic=1429")
     self.assertEqual(parser.getNext(
         "http://www.questionablecontent.net/view.php?comic=1430", links[0][0], links[0][1]),
         "http://www.questionablecontent.net/view.php?comic=1431")
Exemplo n.º 3
0
def initNextBasedComic(name, home_url, url_episode_1, url_episode_2, url_episode_3, title_episode_2="", episode_title_xpath=""):
    """Creates a new next-harvesting-based webcomic on the database.
    
    It needs the comic name, URL for the first three episodes and title for the third
    (to deduce the title xpath)
    
    It can search for the title xpath by receving the second episode's title, or receive
    the xpath directly. If no xpath is supplied or searched, episodes will have
    auto-generated titles. 
    
    Returns the newly created comic"""
    
    # Comic setup (finding the next button and, if needed, title xpath)
    c = Comic()
    c.name = name
    c.home_url = home_url
    c.strategy = "N"
    links = parser.findLinks(url_episode_2, url_episode_3)
    if links:
        (c.next_button_xpath, c.next_button_expected_html) = links[0]
    else:
        raise ValueError("Can't find link from " + url_episode_2 + " to " + url_episode_3)
    if not episode_title_xpath:
        if title_episode_2:
            episode_title_xpath = parser.findXpathFor(url_episode_2, title_episode_2)
            if not episode_title_xpath:
                raise ValueError("Can't find element containing title '" + title_episode_2 + "' at " + url_episode_2)
    
    # Initial episodes setup
    (e1, e2) = (Episode(), Episode())
    (e1.order, e2.order) = (1, 2)
    (e1.url, e2.url) = (url_episode_1, url_episode_2)
    if episode_title_xpath:
        c.episode_title_xpath = episode_title_xpath
        (e1.title, e2.title) = (parser.getTextForXpath(url_episode_1, episode_title_xpath),
                                parser.getTextForXpath(url_episode_2, episode_title_xpath))
    
    # Persist the comic, then the episodes
    # (the object association is lost if you do it before saving)
    c.save()
    (e1.comic, e2.comic) = (c, c)
    e1.save()
    e2.save()

    return c
Exemplo n.º 4
0
 def setUp(self):
     (self.xpath, self.expected_html) = \
         parser.findLinks(TESTCOMIC[2], TESTCOMIC[3])[0]
Exemplo n.º 5
0
 def testNoLink(self):
     """findLinks should return an empty list if no links are found from source to target"""
     links = parser.findLinks(TESTCOMIC[1], TESTCOMIC[3])
     self.assertFalse(links) # no links from episode 1 to episode 3
Exemplo n.º 6
0
 def testMultipleLink(self):
     """findLinks should return a multi-item list if there is more than one link between the pages"""
     links = parser.findLinks(TESTCOMIC[2], TESTCOMIC[1])
     self.assertEqual(len(links), 2) # there are a "previous" and a "first" link from 2 to 1
     self.assertEqual(links[0][1], "First")
     self.assertEqual(links[1][1], "Previous")
Exemplo n.º 7
0
 def testSingleLink(self):
     """findLinks should be able to correctly identify a single "next" link between a source and a target page"""
     links = parser.findLinks(TESTCOMIC[1], TESTCOMIC[2])
     self.assertEqual(len(links), 1) # we just have the "next" link from episode 1 to episode 2
     self.assertEqual(links[0][1], "Next")