Example #1
0
 def search(self, key_word, atype, start, count):
     print "search key:%s" % key_word
     print "atype :%d " % atype
     if (atype == 0):
         stype = 'q'
     elif (atype == 1):
         stype = 'tag'
     else:
         print "atype  error"
         return []
     fp = open("search.json", "r")
     data = fp.read()
     js = json.loads(data)
     jsbooks = js['books']
     books = {}
     books['start'] = start
     books['total'] = js['total']
     books['book_arr'] = []
     books['count'] = js['count'] - start
     if (books['count'] <= 0):
         return books
     i = start
     j = start + 5
     while i < books['total'] and i < j:
         print jsbooks[i]
         mbook = book()
         mbook.load(jsbooks[i])
         books['book_arr'].append(mbook)
         i += 1
     return books
Example #2
0
 def search(self,key_word,atype,start,count):
     print "search key:%s" % key_word
     print "atype :%d " % atype
     if(atype==0):
         stype='q'
     elif(atype==1):
         stype='tag'
     else:
         print "atype  error"
         return []
     fp=open("search.json","r")
     data=fp.read()
     js=json.loads(data)
     jsbooks=js['books']
     books={}
     books['start']=start
     books['total']=js['total']
     books['book_arr']=[]
     books['count']=js['count']-start
     if(books['count']<=0):
         return books
     i=start
     j=start+5
     while i<books['total'] and i<j :
         print jsbooks[i]
         mbook=book()
         mbook.load(jsbooks[i])
         books['book_arr'].append(mbook)
         i+=1
     return books
def add_book():
    b = len(book_list)
    if b == 0:
        with open("booklist.pkl", "wb") as f:
            n = int(input("How many books to be Added"))
            for i in range(n):
                b = book()
                b.add()
                book_list.append(b)
            pickle.dump(book_list, f)
    else:
        with open("booklist.pkl", "ab") as f:
            n = int(input("How many books to be Added"))
            for i in range(n):
                b = book()
                b.add()
                book_list.append(b)
            pickle.dump(book_list, f)
Example #4
0
def menu(email):

    global connection, cursor

    mail(email)

    select = input(
        "Select what you want to do.\n1.Offer a ride.\n2.Search for rides.\n3.Book members or cancel bookings.\n4.Post ride requests.\n5.Search and delete ride requests.\n6.Quit"
    )

    if select == "1":

        offer(email, connection, cursor)

    elif select == "2":

        search(email, connection, cursor)

    elif select == "3":

        book(email, connection, cursor)

    elif select == "4":

        post(email, connection, cursor)

    elif select == "5":

        search_delete_requests(email, connection, cursor)

    elif select == "6":

        welcome_screen()
    else:

        print("Invalid input")

    menu(email)

    connection.commit()

    return
Example #5
0
def bag(self, current_space):
#Parse input, check if requested item is in bag, return usage from related meth.
    print
    u_input = raw_input("What item would you like to use?  ")
    while u_input != "close bag":
        if u_input == "bluebells":
            print health_booster(5)
        elif u_input == "honeysuckle":
            print health_booster(5)    
        elif u_input == "cactus flower":
            print health_booster(5)
        elif u_input == "book":
            print book('stuff') 
        else:
            print "nope"

        go = bag('stuff', current_space)

    print "You close the bag."
    exit(1)            
Example #6
0
def bookDelete(request, bookId):
    '''
    Delete the article instance:
        1. Render the article page if the method is GET
        2. Get the article to delete; redirect to 404 if not found
    '''
    if request.method == 'GET':
        return book(request)
    # POST
    book = get_object_or_404(Book, id=bookId)
    book.delete()
    messages.success(request, '文章已刪除')
    return redirect('book:book')
Example #7
0
    def insertBook(self, title, author):
        # Verificacao se o livro ja existe
        for b in self.shelf:
            if [b.Title, b.Author] == [title, author]:
                print 'Livro ja existente'
                return

        # Se o livro nao existe "cria-se" um identificador para ele 
        bid = self.identifier
        self.identifier += 1

        # Criacao do novo livro
        new_book = book(author, title, bid)
        self.shelf.append(new_book)

        # Criacao de um "backup" da base de dados
        f = open("database" + self.name + ".dump", "w")
        pickle.dump(self.shelf, f)
        f.close()
Example #8
0

  def webquery(self,isbn):
    import book
    from biblio.webquery.xisbn import XisbnQuery
    import biblio.webquery
    a = XisbnQuery()
    try:
      abook = a.query_bibdata_by_isbn(isbn)
      nn = abook.pop()
      self.id=nn.id
      self.isbn=nn.id
      self.title=nn.title
      self.authors=(str(nn.authors)).replace('[','').replace(']','')
      self.abstract=(nn.abstract)
      self.mtype=nn.type
      self.publisher=(nn.publisher)
      self.city=(nn.city)
      self.year=(nn.year)
    except:
      return 1

# Test harness
if __name__ == "__main__":
  abook = book()
  abook.webquery("0752272225")
  #abook.webquery("075227222")
  #print abook.print_book()
  print abook.__dict__
  del abook
Example #9
0
 def insert_book(self, title, author, year):
     self.library[self.num_books] = book(title, author, self.num_books, year)
     self.num_books += 1
Example #10
0
from connectfour import *
from minimax import *
from book import *

## TODO  HANDLE WHEN TWO STRIPES ARE THE SAME COLOR
##       MAKE METHOD FOR FINDING KEYS


transpose = []
count = 0
bk = book()
mybook = {}

def generate(node, max_depth, printer=False):
    global count
    
    if max_depth <= 0:
        return
    if node.gethash() in transpose:
        return
    if bk.inBook(node.line):
        return
    # if this position isnt useful, give up
    checker = Search(node)
    checker.clear_history()
    checker.allowed_time = 5
    checker.start_time = time.time()
    if abs(checker.minimax(node, 2, -999999, 999999)) > 5000:
        return
    transpose.append(node.gethash())
    # get the best move for this position
Example #11
0
 def __init__(self, parent=None):
     super(detailDialog, self).__init__(parent)
     self.book = book()
Example #12
0
 def __init__(self,parent=None):
     super(detailDialog,self).__init__(parent)
     self.book=book()