Exemple #1
0
 def test_quiet(self):
     """
         Test the quiet mode
     """
     argument = parse_argv([FOO, '-q'])
     self.assertTrue(argument.quiet_mode)
     self.assertFalse(parse_argv([FOO]).quiet_mode)
Exemple #2
0
 def test_outdated(self):
     """
         Test the outdated
     """
     argument = parse_argv([FOO, '--outdated'])
     self.assertTrue(argument.outdated)
     argument = parse_argv([FOO])
     self.assertFalse(argument.outdated)
Exemple #3
0
 def test_file_root(self):
     """
         Test file root
     """
     argument = parse_argv([FOO, '--file-root', '/home'])
     self.assertEqual(argument.file_root, '/home')
     argument = parse_argv([FOO])
     self.assertEqual(argument.file_root, DEFAULT_FILE_ROOT)
Exemple #4
0
    def test_no_latest(self):
        """
            Test --no-latest
        """
        argument = parse_argv([FOO, '--no-latest'])
        self.assertTrue(argument.no_latest)

        argument = parse_argv([FOO])
        self.assertFalse(argument.no_latest)
Exemple #5
0
    def test_help(self, mocked_print):
        """
            Test help options
        """
        argument = parse_argv([FOO, '--help'])
        self.assertTrue(argument.print_help)
        argument = parse_argv([FOO])
        self.assertFalse(argument.print_help)

        print_help()
        self.assertTrue(mocked_print.call_count > 1)
Exemple #6
0
    def test_proxy(self):
        """
            Test --proxy
        """
        argument = parse_argv([FOO, '--proxy'])
        self.assertEqual(argument.url_proxy, None)

        argument = parse_argv([FOO])
        self.assertEqual(argument.url_proxy, None)

        argument = parse_argv([FOO, '--proxy', 'http://www.baidu.com?s={url}'])
        self.assertEqual(argument.url_proxy, 'http://www.baidu.com?s={url}')

        argument = parse_argv([FOO, '--proxy', 'http://www.baidu.com?s={url'])
        self.assertIsNone(argument.url_proxy)
Exemple #7
0
    def test_chapters(self):
        """
            Test chapters
        """
        argument = parse_argv([FOO, '-s', '02'])
        self.assertEqual('02', argument.chapter)

        argument = parse_argv([FOO, '-s'])
        self.assertEqual(DEFAULT_CHAPTER, argument.chapter)

        argument = parse_argv([FOO, '-s', '03', '-a'])
        self.assertIsNone(argument.chapter)
        self.assertTrue(argument.all_chapters)

        argument = parse_argv([FOO, '-a', '-s', '03'])
        self.assertIsNone(argument.chapter)
        self.assertTrue(argument.all_chapters)

        argument = parse_argv([FOO, '--all', '-s', '03'])
        self.assertIsNone(argument.chapter)
        self.assertTrue(argument.all_chapters)

        argument = parse_argv([FOO, '--all'])
        self.assertIsNone(argument.chapter)
        self.assertTrue(argument.all_chapters)
Exemple #8
0
def main():
    """
        Entrance
    """
    args = argument.parse_argv(sys.argv)

    if args.print_help:
        argument.print_help()
        return
    # 搜索条件
    chapter = args.chapter
    # 是否爬取所有页面
    all_search = args.all_chapters

    if all_search:
        # 01-09
        for i in range(1, 10):
            chapter = '0' + str(i)
            search_and_save(chapter, args)
        # 10-99
        for i in range(10, 100):
            search_and_save(str(i), args)
    else:
        search_and_save(str(chapter), args)