示例#1
0
    def test_content(self):
        d = wiki.content("Obama")
        self.assertIsInstance(d, unicode)

        d = wiki.content("adfsklfdlksf")
        self.assertEqual(d, "No page matches, try another item.")

        d = wiki.content("mercury")
        self.assertIsInstance(d, list)
        self.assertEqual(len(d), 5)
示例#2
0
    def test_content(self):
        d = wiki.content("Obama")
        try:  # python2
            self.assertIsInstance(d, unicode)
        except NameError:  # python3
            self.assertIsInstance(d, str)

        d = wiki.content("adfsklfdlksf")
        self.assertEqual(d, "No page matches, try another item.")

        d = wiki.content("mercury")
        self.assertIsInstance(d, list)
        self.assertEqual(len(d), 5)
示例#3
0
    def do_wiki(self, s):
        """Jarvis will get wiki details for you"""

        # if no input or False values after 'wiki' command, return.
        if not s:
            return
        k = s.split(' ', 1)
        # check for index at 1.
        try:
            k[1]
        except IndexError:
            self.error()
            return
        data = None
        if k[0] == "search":
            data = wiki.search(" ".join(k[1:]))
        elif k[0] == "summary":
            data = wiki.summary(" ".join(k[1:]))
        elif k[0] == "content":
            data = wiki.content(" ".join(k[1:]))

        if isinstance(data, list):
            print("\nDid you mean one of these pages?\n")
            for d in range(len(data)):
                print(str(d + 1) + ": " + data[d])
        else:
            print("\n" + data)
示例#4
0
    def do_wiki(self, s):
        """Jarvis will get wiki details for you"""
        k = s.split(' ', 1)
        if k[0] == "search":
            data = wiki.search(" ".join(k[1:]))
        elif k[0] == "summary":
            data = wiki.summary(" ".join(k[1:]))
        elif k[0] == "content":
            data = wiki.content(" ".join(k[1:]))

        if isinstance(data, list):
            print "\nDid you mean one of these pages?\n"
            for d in range(len(data)):
                print(str(d + 1) + ": " + data[d])
        else:
            print("\n" + data)
示例#5
0
    def do_wiki(self, s):
        """Jarvis will get wiki details for you"""
        #ERROR if only uses wiki or wiki search without keyword
        k = s.split(' ', 1)
        data = None
        if k[0] == "search":
            data = wiki.search(" ".join(k[1:]))
        elif k[0] == "summary":
            data = wiki.summary(" ".join(k[1:]))
        elif k[0] == "content":
            data = wiki.content(" ".join(k[1:]))

        if isinstance(data, list):
            print("\nDid you mean one of these pages?\n")
            for d in range(len(data)):
                print(str(d + 1) + ": " + data[d])
                # Jarvis don't let to choose over these results
        else:
            print("\n" + data)