Beispiel #1
0
def searchidlist(key, selected=0):
    """

    :param key:
    :param se:
    :param selected:
    :return:
    """
    se = SearchEngine(config_path=CONFIG_PATH, config_encoding='utf-8')
    flag, id_scores = se.search(key, selected)
    doc_id = [i for i, s in id_scores]
    page = []
    for i in range(1, (len(doc_id) // 10 + 2)):
        page.append(i)
    return flag, page, doc_id
Beispiel #2
0
    def __init__(self):
        tokenizer = Tokenizer()
        
        if os.path.exists('manga.dat'): 
            file = open('manga.dat', 'r')
            data = pickle.load(file)
            file.close()
        else:
            data = Miner().mine()
            file = open('manga.dat', 'wb')
            pickle.dump(data, file)
            file.close()

        if os.path.exists('manga.idx'):
            file = open('manga.idx', 'r')
            index = pickle.load(file)
            file.close()
        else:
            indexer = Indexer(tokenizer)
            index = indexer.buildIndex(data)
            file = open('manga.idx', 'wb')
            pickle.dump(index, file)
            file.close()
        
        self.searchEngine = SearchEngine(data, index, tokenizer)
        self.irc_client = IRCClient()
        
        thread.start_new_thread(self.irc_client.start, ())
        thread.start_new_thread(self.refreshList, ())
Beispiel #3
0
def searchidlist(key, selected=0):
    """
    Get page number and document ids

    Parameters:
        key (string): searching keywords
        selected (int): ranking strategy (0 for BM25, 1 for popularity, 2 for time)

    Returns:
        flag (int): found = 1, not found = 0
        page (list<int>): list of page numbers
        doc_id (list<string>): list of document ids
    """
    se = SearchEngine(config_path=CONFIG_PATH, config_encoding='utf-8')
    flag, id_scores = se.search(key, selected)
    doc_id = [i for i, s in id_scores]
    page = []
    for i in range(1, (len(doc_id) // 10 + 2)):
        page.append(i)
    return flag, page, doc_id
Beispiel #4
0
class Gui(object):
    """
    Initialize the search engine and irc client.
    Also starts a background thread which updates manga
    lists. 
    """
    def __init__(self):
        tokenizer = Tokenizer()
        
        if os.path.exists('manga.dat'): 
            file = open('manga.dat', 'r')
            data = pickle.load(file)
            file.close()
        else:
            data = Miner().mine()
            file = open('manga.dat', 'wb')
            pickle.dump(data, file)
            file.close()

        if os.path.exists('manga.idx'):
            file = open('manga.idx', 'r')
            index = pickle.load(file)
            file.close()
        else:
            indexer = Indexer(tokenizer)
            index = indexer.buildIndex(data)
            file = open('manga.idx', 'wb')
            pickle.dump(index, file)
            file.close()
        
        self.searchEngine = SearchEngine(data, index, tokenizer)
        self.irc_client = IRCClient()
        
        thread.start_new_thread(self.irc_client.start, ())
        thread.start_new_thread(self.refreshList, ())

    """Define gui layouts and start Tk mainloop()"""
    def run(self):
        root = Tk()
        root.geometry("800x600")
    
        frame = Frame(root, width=800, height=600)
        frame.master.title('Lurk Manga Downloader')
        frame.pack()
    
        #######################################################################
    
        topFrame = Frame(frame)
        topFrame.pack(side=TOP, fill=X)
    
        self.searchLabel = Label(topFrame, text="Search: ")
        self.searchLabel.pack(side=LEFT)
    
        self.searchEntry = Entry(topFrame)
        self.searchEntry.pack(side=LEFT)
    
        self.searchButton = Button(topFrame, text="search")
        self.searchButton.pack(side=LEFT)
    
        self.searchEntry.bind("<Return>", self.searchCallback)
        self.searchButton.bind("<Button-1>", self.searchCallback)
    
        #######################################################################
    
        bottomFrame = Frame(frame)
        bottomFrame.pack(side=TOP)
    
        #######################################################################
    
        bottomRightFrame = Frame(bottomFrame)
        bottomRightFrame.pack(side=RIGHT, fill=Y)
    
        self.nickLabel = Label(bottomRightFrame, text="Nickname: ")
        self.nickLabel.pack(side=TOP)
    
        self.nickEntry = Entry(bottomRightFrame)
        self.nickEntry.pack(side=TOP)
    
        self.passLabel = Label(bottomRightFrame, text="Password: "******"Connect")
        self.connectButton.pack(side=TOP)
        self.connectButton.bind("<Button-1>", self.connectCallback)
    
        self.downloadButton = Button(bottomRightFrame, text="Download")
        self.downloadButton.pack(side=TOP)
        self.downloadButton.bind("<Button-1>", self.downloadCallback)
    
        #######################################################################
    
        self.scrollbar = Scrollbar(bottomFrame)
        self.scrollbar.pack(side=RIGHT, fill=Y)
    
        self.listbox = Listbox(bottomFrame, yscrollcommand=self.scrollbar.set, 
                               width=800, height=600, selectmode=EXTENDED)
        self.mangaList = self.searchEngine.search()
        for manga in self.mangaList:
            self.listbox.insert(END, manga.title)
        self.listbox.pack(side=LEFT, fill=BOTH)
    
        self.scrollbar.config(command=self.listbox.yview)
        
        root.mainloop()

    """search callback"""
    def searchCallback(self, event):
        filterText = self.searchEntry.get()
        self.listbox.delete(0, END)
        
        self.mangaList = self.searchEngine.search(filterText)
        for manga in self.mangaList:
            self.listbox.insert(END, manga.title)

    """connect callback"""
    def connectCallback(self, event):
        nickname = self.nickEntry.get()
        password = self.passEntry.get()
    
        self.irc_client.connect(nickname, password)

    """download callback"""
    def downloadCallback(self, event):
        selection = self.listbox.curselection()

        for indexString in selection:
            index = int(indexString)
            self.irc_client.download(self.mangaList[index])
    
    """mine data from gotlurk and refresh manga list"""
    def refreshList(self):
        data= Miner().mine()
        
        tokenizer = Tokenizer()
        indexer = Indexer(tokenizer)
        index = indexer.buildIndex(data)
        
        # save data and index
        file = open('manga.dat', 'wb')
        pickle.dump(data, file)
        file.close()
        
        file = open('manga.idx', 'wb')
        pickle.dump(index, file)
        file.close()
        
        self.searchEngine.setDataAndIndex(data, index)