示例#1
0
def validbookID(
        id):  #checks book id > 0 and int and exists (rows in datafile - 1)
    try:
        id = int(
            id)  #converts input to int (if string then catches error w/ msg)
        if 0 < id < len(database.readFile(database.filename)):
            return True
        else:
            return False
    except Exception as e:
        return False
def updateFileIn(bookid, bookname):  #bookid,bookname,date):
    list = database.readFile(filename)
    list.sort(reverse=True)  ##view most recent first
    for i in range(len(list) - 1, 0, -1):
        if str(bookid) == str(list[i][0]) and bookname == list[i][1]:
            list[i].append(datetoday)
            break
    list.sort(reverse=True)
    file = open(filename + ".txt", "w")
    for line in list:
        linetowrite = '	'.join(line)
        file.write(linetowrite + "\n")
    file.close()
示例#3
0
def bookSearch(bookname):
    filelist = database.readFile(
        database.filename)  #loads file from database.txt
    searchedlist = []
    result = ""  #list that will have valid books added

    for j in range(0, len(filelist)):  #iterates through all rows in the file
        if filelist[j][
                1] == bookname:  #and appends the valid rows to searchedlist
            searchedlist.append(filelist[j])
    searchedlist.insert(0, database.addHeaders(
        database.filename))  #adds headers at the start of list
    result = (database.printTable(searchedlist)
              )  #so that the printList func can be used
    return result
def getPopList():
    loglist = database.readFile(filename)
    poplist = [['Title', 'Count']]
    del loglist[0]  ##removes headers before sorted by popularity
    for i in range(0, len(loglist)):
        count = 0
        for j in range(0, len(poplist)):
            if loglist[i][1] == poplist[j][0]:
                poplist[j][1] = int(poplist[j][1]) + 1
                break
            else:
                count += 1
            if count == len(poplist):
                poplist.append([loglist[i][1], '1'])
                break
    del poplist[0]
    poplist.sort(key=getCount, reverse=True)
    poplist.insert(0, ['Title', 'Count'])
    result = poplist
    return result
示例#5
0
def bookReturn(bookid):
    try:
        list = database.readFile(database.filename)
        bookid = int(bookid)
        if 0 < bookid < len(list):  #not using a function for validation
            for line in list:
                if line[0] == str(bookid):
                    booktitle = line[1]
                    if line[4] == str(-1):
                        return ("That book is currently not taken out")
                    else:
                        database.updateFile(bookid, -1)
                        booklist.updateFileIn(bookid, booktitle)
                        return ("Returned book with ID \'%s\'" % (bookid))
        else:
            return ("\'" + str(bookid) + "\' isn't a valid book ID"
                    )  ##non-existing int id

    except Exception as e:
        return ("\'" + str(bookid) + "\' isn't a valid book ID")  ##non int id
示例#6
0
def getScores():
    highscore_data = readFile("highscore.txt")
    scores = json.loads(highscore_data)
    return scores
示例#7
0
def bookTitle(id):
    booklist = []
    booklist = database.readFile(database.filename)
    for line in booklist:
        if line[0] == str(id):
            return line[1]
示例#8
0
def bookStatus(id):
    booklist = []
    booklist = database.readFile(database.filename)
    for line in booklist:
        if line[0] == str(id):
            return int(line[4])
示例#9
0
# agar sinonim tidak menggunakan memmory yang berlebih hasil sinonim di generate dengan yield
def getSinonimKata(pertanyaan):
    global tempDict
    listkata = pertanyaan.split()
    listsinonim = []
    for kata in listkata:
        listsinonim.append(database.getSinonim(tempDict, kata))
    for element in itertools.product(*listsinonim):
        yield (" ".join(element))


if __name__ == "__main__":

    if(len(sys.argv) == 3):
        mode = sys.argv[1]
        questionList = database.readFile('modifiedQuestion.txt')
        question = sys.argv[2]
        temp = getSinonimKata(question)
        if(mode.lower() == 'bm'):
            for word in temp:
                if (searchWithBM(questionList,word) != None):
                    print(searchWithBM(questionList,word)[1])
                    break
        elif(mode.lower() == 'kmp'):
            for word in temp:
                if (searchWithKMP(questionList,word) != None):
                    print(searchWithKMP(questionList,word)[1])
                    break
        elif(mode.lower() == 'regex'):
            for word in temp:
                if (searchWithRegEx(questionList,word) != None):
示例#10
0
async def on_ready():
    print('Ready.')
    database.readFile()