Пример #1
0
def checkoutBook(isbn, id, member_id, member, database_file, logfile, display,
                 arg):
    """
    this is a function the check out books first by checking if the book
    is eligible to be checked out and thus updating the database accordingy
    """
    library_db = db.readDatabase(database_file)
    valid_results = []
    isbn_exists = db.IdExists(id, library_db)

    if not isbn_exists:
        mbx.showerror("Error", "Book ID does not exist")

    elif not db.validISBN(id):
        mbx.showerror("Error", "Invalid Book ID")

    elif not db.validMemberID(member):
        mbx.showerror("Error", "Invalid Member ID")
    else:

        for i in range(len(library_db)):  #loops based on the how many records

            if library_db[i+1][isbn]==id and \
                library_db[i+1][member_id]=='0':
                #^^^checks if id exists and if book is not checked out

                library_db[
                    i +
                    1][member_id] = member  #updates member id to checkout book
                valid_results.append(list(
                    library_db[i + 1].values()))  #appends > list

        if __name__ != "__main__":  #only runs if the main program is running

            if valid_results == []:
                mbx.showerror("Error", "Book has already been checked out")
            else:
                mbx.showinfo("Success!",
                             "Book has been loaned to member:%s" % (member))
                display.delete(0, tk.END)  #emptys out the display box
                for i in valid_results:
                    display.insert(
                        tk.END, i)  # inserts search results on the display box

                for i in range(len(arg)):
                    arg[i].delete(0, tk.END)

                log_db = checkoutLog(id, library_db, logfile)
                db.writeDatabase(log_db, logfile)
                db.writeDatabase(library_db, database_file)

        else:
            print(valid_results)
Пример #2
0
def uploadAndInput(req, name, email, title, comment):
	data.clearDatabase()
	lastID = data.writeDatabase(name, email, title, comment)
	last = data.getEntryFromID(lastID)
	obj = ""
	fileitem = req.form['file']

	if fileitem.filename:
		# strip leading path from file name to avoid directory traversal attacks
		# also prepend DB ID so filenames are unique
		fname = str(last['_id'])+"_"+os.path.basename(fileitem.filename)
		obj = data.updateFilenameFromID(last['_id'],fname)
		# build absolute path to files directory
		dir_path = os.path.join(os.path.dirname(req.filename), 'files')
		open(os.path.join(dir_path, fname), 'wb').write(fileitem.file.read())
		#obj = analyze.histogram(last['_id'])
		obj = image.resize(last['_id'])
		obj = analyze.histogram(last['_id'], 4)
		message = "<HTML>"
		message += 'The file "%s" was uploaded, resized, and analyzed successfully' % fname
		message += '\n<img src="'+cfg.imageWebPath+fname+'">'
		message += '<br>debug of DB object: <br>'
		for x in obj:
			message +=(x+": "+str(obj[x])+"<br>")
		message += "<p>"
		message += "</HTML>"
	else:
		message = 'No file was uploaded'

	
	return message
Пример #3
0
def uploadNoInput(req):
	data.clearDatabase()
	lastID = data.writeDatabase("auto", "*****@*****.**", "auto", "auto")
	last = data.getEntryFromID(lastID)
	obj = ""
	fileitem = req.form['file']

	if fileitem.filename:
		# strip leading path from file name to avoid directory traversal attacks
		# also prepend DB ID so filenames are unique
		fname = str(last['_id'])+"_"+os.path.basename(fileitem.filename)
		obj = data.updateFilenameFromID(last['_id'],fname)
		# build absolute path to files directory
		dir_path = os.path.join(os.path.dirname(req.filename), 'files')
		open(os.path.join(dir_path, fname), 'wb').write(fileitem.file.read())
		#obj = analyze.histogram(last['_id'])
		obj = image.resize(last['_id'])
		obj = analyze.histogram(last['_id'], 4)
		message = "<HTML>"
		message += 'The file "%s" was uploaded, resized, and analyzed successfully' % fname
		#message += 'go <a href="#" onClick = "history.back()"> back </a>
		message += '\n<img src="'+cfg.imageWebPath+fname+'">'
		f = open("/srv/www/htdocs/lighting/app/control.html",'r')
		message += f.read()
		
		#message += '<br>debug of DB object: <br>'
		#for x in obj:
		#	message +=(x+": "+str(obj[x])+"<br>")
		#message += "<p>"
		#message += "</HTML>"
	else:
		message = 'No file was uploaded'
		
	return message
Пример #4
0
def postData(name, email, comment):
	#req.write("posting data: "+name+""+email+""+comment+" \n")
	#req.write("posting data...")
	lastID = data.writeDatabase(name, email, comment)
	#return ( name, email, comment)
	#last = data.getLastEntry()
	
	last = data.getEntryFromID(lastID)
	
	tempStr = "\n"
	for x in last:
		tempStr+=(x+": "+str(last[x])+"\n")
	return "Data Posted... "+tempStr
Пример #5
0
def getEmail():
	detach_dir = cfg.emailImagePath # directory where to save attachments
	user = cfg.emailUser 
	pwd = cfg.emailPass 

	# connecting to the gmail imap server
	m = imaplib.IMAP4_SSL("imap.gmail.com")
	m.login(user,pwd)
	m.select(cfg.emailLabel) # here you a can choose a mail box like INBOX instead
	# use m.list() to get all the mailboxes
	#print m.list()
	resp, items = m.search(None, "ALL") 
	# you could filter using the IMAP rules here (check http://www.example-code.com/csharp/imap-search-critera.asp)
	#resp, items = m.search(None, '(FROM "ucla.edu")')
	
	authorName = ""
	authorEmail = ""
	authorTitle = ""
	authorDescription = ""
	
	items = items[0].split()
	
	if(items):
		for emailid in items:
		    resp, data = m.fetch(emailid, "(RFC822)")
		    #"`(RFC822)`" means "get the whole stuff", but you can ask for headers only, etc
		    email_body = data[0][1] # getting the mail content
		    mail = email.message_from_string(email_body) # parsing the mail content to get a mail object

		    #Check if any attachments at all
		    if mail.get_content_maintype() != 'multipart':
		        continue
			
		   #print mail["From"] +":" + mail["Subject"]
		    
		    authorTitle = mail["Subject"]
		    authorName = mail["From"].split('<',2)[0]
		    #print authorName
		    authorEmail = mail["From"].split('<',2)[1].rstrip(">")
		   	#print authorEmail
		   	
		    for part in mail.walk():
		        # multipart are just containers, so we skip them
		        if part.get_content_maintype() == 'multipart':
		            continue
		        
		        if part.get_content_maintype() == 'text':
		        	message = part.get_payload()
		        	#print "body :"+ message
		        	authorDescription = message
		        	#print "Name :"+ authorName
		        	#print "eMail:"+ authorEmail
		        	#print "title:"+authorTitle
		        	#print "desc :"+ authorDescription
		        	continue
	
		        # is this part an attachment ?
		        if part.get('Content-Disposition') is None:
		            continue
	
		        filename = part.get_filename()
		        counter = 1
	
		        # if there is no filename, we create one with a counter to avoid duplicates
		        if not filename:
		            filename = 'part-%03d%s' % (counter, 'bin')
		            counter += 1
				
		        att_path = os.path.join(detach_dir, authorEmail+"_"+filename)
	
		        #Check if its already in the email directory
		        if not os.path.isfile(att_path) :
		            # new data, save info to database
		            lastID = db.writeDatabase(authorName, authorEmail,authorTitle, authorDescription)
		            last = db.getEntryFromID(lastID)
		        	
		            #write to normal image directory w/ UID prefix
		            imgPath = os.path.join(cfg.imageFilePath, str(last['_id'])+"_"+filename)
		            obj = db.updateFilenameFromID(last['_id'],str(last['_id'])+"_"+filename)
		            
		            eImgPath = os.path.join(cfg.emailImagePath, authorEmail+"_"+filename)
		            
		            # write to email image directory, so we don't re-insert same image later
		            fp = open(eImgPath, 'wb')
		            fp.write(part.get_payload(decode=True))
		            fp.close()
		            
		            fp = open(imgPath, 'wb')
		            fp.write(part.get_payload(decode=True))
		            fp.close()
		            
		            obj = img.resize(last['_id'])
		            obj = analyze.histogram(last['_id'], cfg.analysisMode)