def main(): list_of_students = [] operation_history = [] menu_option = [UI.add, UI.list_students, UI.filter, UI.undo] UI.clear_screen() Services.generate_entries(list_of_students, 10) while True: UI.print_options() option = input("Enter an option: ") UI.clear_screen() try: option = int(option) if option < 0: print("You have entered a negative value!\n") continue if option == 0: return menu_option[option - 1](list_of_students, operation_history) except (ValueError, IndexError): print("Enter an integer between 0 and 4!\n") except Exception as e: print(e)
def test_address_not_existent(self): test_services = Services(True) test_services.drivers.data.append(Driver("Ion", 10, 10)) self.assertRaises( Exception, lambda: test_services.get_closest_drivers_for_address("test"))
def update(id): update_service = Services.find_one({"_id": ObjectId(id)}) if request.method == "GET": # print(update_service) return render_template("update-service.html", update_service=update_service) elif request.method == "POST": form = request.form service_name = form["input_name"] service_age = form["input_age"] service_gender = form["input_gender"] service_height = form["input_height"] service_address = form["input_address"] service_available = form["input_available"] # print(form["input_name"]) new_value = { "$set": { "name": service_name, "age": service_age, "address": service_address, "gender": service_gender, "height": service_height, "available": service_available, } } Services.update_one(update_service, new_value) return redirect("/all-service/detail/{0}".format(id))
def delete(id): del_servce = Services.find_one({"_id": ObjectId(id)}) if del_servce is not None: Services.delete_one(del_servce) return redirect('/all-service') else: print("Not found")
def update(id): update_person = Services.find_one({"_id": ObjectId(id)}) if request.method == "GET": # Get information return render_template("update.html", update=update_person) elif request.method == "POST": form = request.form services_name = form["input_Name"] services_age = form["input_Age"] services_gender = form["input_Gender"] services_height = form["input_Height"] services_address = form["input_Address"] services_available = form["input_Available"] new_value = { "$set": { "name": services_name, "age": services_age, "gender": services_gender, "height": services_height, "address": services_address, "available": services_available, } } Services.update_one(update_person, new_value) return redirect("/all-service/detail/{}".format(id))
def get(self): self.response.headers["Content-Type"] = "text/html" user_id = self.request.GET.get("user_id") otheruserprofile = True follow_text = "Follow" if user_id != None: myuser_key = ndb.Key("MyUser", user_id) myuser = myuser_key.get() tweets = Tweet.query(Tweet.user_id == myuser.key.id()).fetch(50) if user_id == str(Services().get_login_user().key.id()): otheruserprofile = False if user_id in Services().get_login_user().user_following: follow_text = "Unfollow" template_values = { "myuser": myuser, "tweets": tweets, "follow": follow_text, "otheruserprofile": otheruserprofile } template = JINJA_ENVIRONMENT.get_template("editprofile.html") self.response.write(template.render(template_values))
def __init__(self, db): """ :param db: Database connection """ Services.__init__(self) self.db = db self.proj = {} self.match_query = {}
def test_preload(self): services = Services() repo = services.repository services.preload_list() self.assertEqual(repo.get_students_count(), 10) self.assertEqual(repo.get_disciplines_count(), 10) self.assertEqual(repo.get_grades_count(), 10)
def __init__(self, db): """ :param db: Database connection """ Services.__init__(self) self.db = db self.proj = {} self.filter_query = {'status': 1, 'temporary': False} self.trial_watch_query = {'status': 1, 'temporary': False, 'trial_watch': True}
def post(self): self.response.headers["Content-Type"] = "text/html" file = self.request.get("textfile") openFile = open(file) readLine = openFile.readline() while readLine: text_word = (readLine.strip('\n\r')).lower() sorted_key = Services().sorted_key(word=text_word) list_word = Anagram.query() list_word = list_word.filter( Anagram.anagram_key == sorted_key, Anagram.user_id == Services().get_current_user_id()) list_word = list_word.fetch() valid_permutation = Services().validpermutations(text=sorted_key) if len(valid_permutation) > 0: if len(list_word) > 0: anagram = list_word[0] if text_word not in anagram.inputed_words: inputed_words = anagram.inputed_words inputed_words.append(text_word) anagram.inputed_words = inputed_words anagram.inputed_words_count = anagram.inputed_words_count + 1 anagram.put() else: new_anagram = Anagram( anagram_key=sorted_key, anagram_words=Services().possiblepermutations( text=sorted_key), inputed_words=[text_word], inputed_words_count=1, word_length=len(text_word), user_id=Services().get_current_user_id()) new_anagram.put() readLine = openFile.readline() openFile.close() message = "Upload completed" template_values = {'message': message} template = JINJA_ENVIRONMENT.get_template("importdata.html") self.response.write(template.render(template_values))
def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.createapp_xpath = '// *[ @ id = "link-create"]' self.start_xpath = '//*[@id="intro-dialog-cont"]/div[2]/button' self.newpage_xpath = '//*[@id="add-page"]' self.entername_xpath = '//*[@id="create-dialog"]/form/p/input' self.text = "TEST" self.createbutton_xpath = '/html/body/div[20]/div[3]/button[1]' self.clicknewpage_xpath = '//*[@id="accordion"]/h3[4]/a'
def post(self): self.response.headers["Content-Type"] = "text/html" share_text = self.request.get("share_text") share_image = self.request.get("share_image") if share_text != None or share_text != "": share_type = self.request.get("share_type") if share_type == "Update": edit_tweet_id = self.request.get("edit_tweet_id") edit_tweet = Services().get_tweet(tweet_id=edit_tweet_id) edit_tweet.share_text = share_text edit_tweet.put() else: myuser = Services().get_login_user() tweet = Tweet(share_text=share_text, user_id=myuser.key.id(), user_name=myuser.user_name, time=datetime.datetime.now()) tweet.put() myuser.tweet_ids.append(tweet.key.id()) myuser.put() self.redirect("/")
def __init__(self, db): """ :param db: Database connection """ Services.__init__(self) self.db = db self.proj = {} self.filter_query = {'status': 1, 'temporary': False} self.trial_watch_query = { 'status': 1, 'temporary': False, 'trial_watch': True }
def toRDF(self): """ Print a message into RDF in XML format """ #rdf graph store = Graph() #namespaces from namespaces import SWAML, RDFS, FOAF store.bind('swaml', SWAML) store.bind('foaf', FOAF) store.bind('rdfs', RDFS) #message node message = URIRef(self.getUri()) store.add((message, RDF.type, SWAML["Message"])) try: #sender sender = BNode() store.add((message, SWAML["sender"], sender)) store.add((sender, RDF.type, FOAF["Person"])) name = self.getFromName() if (len(name) > 0): store.add((sender, FOAF["name"], Literal(name))) mail = self.getFromMail() store.add((sender, FOAF["mbox_sha1sum"], Literal(Services().getShaMail(mail)))) foafResource = Services().getFoaf(mail) if (foafResource != None): store.add((sender, RDFS["seeAlso"], URIRef(foafResource))) #mail details store.add((message, SWAML['id'], Literal(self.getSwamlId()))) store.add((message, SWAML['to'], Literal(self.getTo()))) store.add((message, SWAML['subject'], Literal(self.getSubject()))) store.add((message, SWAML['date'], Literal(self.getDate()))) store.add( (message, SWAML['inReplyTo'], Literal(self.getInReplyTo()))) #store.add((message, SWAML['body'], Literal(self.getBody()))) store.add((message, SWAML['body'], Literal(u'FIXME'))) except UnicodeDecodeError, detail: print 'Error proccesing message ' + str( self.getId()) + ': ' + str(detail)
def test_assignment(self): stud = StudentsRepo() assig = AssignmentRepo() grade = GradeRepo() serv = Services(stud, assig, grade) auxlist = serv.assignments.Get_list() serv.add_new_assignment("Stay",12) self.assertTrue(auxlist[0].get_description() == "Stay" and auxlist[0].get_deadline() == 12) serv.add_new_assignment("Walk",9) self.assertTrue(auxlist[1].get_description() == "Walk" and auxlist[1].get_deadline() == 9) serv.remove_the_assignment("Walk",None) self.assertTrue(auxlist[1] == None) serv.find_update_assignment("1",0,"Eat",8) self.assertTrue(auxlist[0].get_description() == "Eat" and auxlist[0].get_deadline() == 12)
class UI: def __init__(self): self.services = Services() def print_menu(self): print("Welcome to Taxi Manager! Enter 0 for help...") print("1. Show all the known addresses") print("2. Show all the known drivers") print("3. Show clossest drivers from an address") print("4. Show clossest drivers") print("5. Exit") def get_address(self): return input("Address name: ") def start(self): self.print_menu() while True: try: command = input("> ") print() if command == "0": self.print_menu() continue if command == "1": print(self.services.build_addresses()) continue if command == "2": print(self.services.build_drivers()) continue if command == "3": address = self.get_address() print( self.services.get_closest_drivers_for_address(address)) continue if command == "4": print(self.services.get_closest_drivers()) continue if command == "5": return print("Invalid command") except Exception as error: print("Error: " + str(error))
def test_student(self): stud= StudentsRepo() assig= AssignmentRepo() grade= GradeRepo() serv=Services(stud,assig,grade) auxlist = serv.students.Get_list() serv.add_new_student("Filip",912) self.assertTrue(auxlist[0].get_name() == "Filip" and auxlist[0].get_group() == 912) serv.add_new_student("Adi",913) #TEST FOR THE ADD FUNCTION self.assertTrue(auxlist[1].get_name() == "Adi" and auxlist[1].get_group() == 913) serv.remove_the_students(913,None) # TEST FOR THE REMOVE FUNCTION self.assertTrue(auxlist[1] == None) serv.find_update_person(0,"Adi",914,"3") self.assertTrue(auxlist[0].get_name() == "Adi" and auxlist[0].get_group() == 914)
def post(self): self.response.headers["Content-Type"] = "text/html" if self.request.get("addword") == "Add Word": user_word = self.request.get("word").lower() if Services().get_current_user() == None or user_word == None or user_word == "" : self.redirect("/addword") return current_user_id = Services().get_current_user_id() sorted_key = Services().sorted_key(word =user_word) list_word = Anagram.query() list_word = list_word.filter(Anagram.anagram_key == sorted_key,Anagram.user_id == current_user_id) list_word = list_word.fetch() valid_permutation = Services().validpermutations(text=sorted_key) if len(valid_permutation) == 0: self.redirect("/addword") return if len(list_word) > 0: anagram = list_word[0] if user_word in anagram.inputed_words: self.redirect("/addword") return inputed_words = anagram.inputed_words inputed_words.append(user_word) anagram.inputed_words = inputed_words anagram.inputed_words_count = anagram.inputed_words_count + 1 anagram.put() else: new_anagram = Anagram(anagram_key=sorted_key, anagram_words = Services().possiblepermutations(text=sorted_key), inputed_words = [user_word], inputed_words_count = 1, word_length = len(user_word), user_id = current_user_id) new_anagram.put() self.redirect("/")
def __init__(self, name, mail): """Subscriber constructor""" self.__class__.id += 1 self.setName(name) self.setMail(mail) self.setFoaf(Services().getFoaf(mail)) self.mails = []
def __init__(self, token): self.device = Device(token) self.analysis = Analysis(analysis, token) self.account = Account(token) self.services = Services(token) # Token here corresponds to Third Party API_KEY self.extra = Extra(token)
def gen_services(options): return Services(seed=int(options.seed), number=int(options.num_services), time=list(map(int, options.ss.split(','))), duration_min=list(map(int, options.sd.split(','))), duration_km=list(map(int, options.skm.split(','))), num_passangers=list(map(int, options.sp.split(','))))
def get_service(): if session["logged"] == True: all_services = Services.find() return render_template('services.html', Services=all_services) else: return redirect('/login')
def index(): s = Services('http://www.ipma.pt') placeRef = flask.request.args.get('placeRef') if placeRef: w = s.get_place_weather(1) if w is None: flask.abort(404) # not found else: selectedPlace = PlaceWeather("some-description", w) else: selectedPlace = None places = Services.placeMap.values() rvalue = flask.render_template('index.jinja', places=places, selectedPlace=selectedPlace) return rvalue
class Common(): def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.createapp_xpath = '// *[ @ id = "link-create"]' self.start_xpath = '//*[@id="intro-dialog-cont"]/div[2]/button' self.newpage_xpath = '//*[@id="add-page"]' self.entername_xpath = '//*[@id="create-dialog"]/form/p/input' self.text = "TEST" self.createbutton_xpath = '/html/body/div[20]/div[3]/button[1]' self.clicknewpage_xpath = '//*[@id="accordion"]/h3[4]/a' def createapp_page(self): """ This method is used to create app Create a new page and give a new name to it :return: """ self.services.wait_for_element(self.createapp_xpath) self.driver.find_element_by_xpath(self.createapp_xpath).click() self.driver.implicitly_wait(5) self.driver.find_element_by_xpath(self.start_xpath).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.newpage_xpath).click() name = self.driver.find_element_by_xpath(self.entername_xpath) name.click() self.driver.implicitly_wait(50) name.send_keys(self.text) time.sleep(5) self.driver.find_element_by_xpath( '/html/body/div[20]/div[3]/button[1]').click() self.driver.find_element_by_xpath(self.clicknewpage_xpath).click() def drag_and_drop(self): source_element = self.driver.find_element_by_xpath( '//*[@id="accordion"]/div[4]/ul/li[3]') time.sleep(5) dest_element = self.driver.find_element_by_xpath('//*[@id="tabs-2"]') ActionChains(self.driver).drag_and_drop(source_element, dest_element).perform() time.sleep(5)
def all_service(): if "logged" in session: if session["logged"] == True: persons = Services.find() return render_template('all-services.html', all_persons=persons) else: return redirect('/login') else: return redirect('/login')
def allservice(): if "logged" in session: if session["logged"] == True: persons = Services.find() return render_template("all-service.html", all_persons=persons) else: return redirect("/login") else: return redirect("/login")
def run(self): """Check services for all servers configs data""" if self.validateServicesList(): self.oServices = Services() #Create Services object for info in services.services_list: self.oServices.check(info) # show debug self.showDebugResult() # save logs self.saveLogFile()
def get(self): self.response.headers["Content-Type"] = "text/html" inputed_word = self.request.GET.get("input_word") sorted_key = Services().sorted_key(word=inputed_word) list_sorted_keys = [] anagram_query = Anagram.query( Anagram.user_id == Services().get_current_user_id()) possible_combination_key = Services().possibleAllCountPermutations( text=sorted_key) anagram_models = [] for word in possible_combination_key: query = anagram_query.filter(Anagram.anagram_key == word).fetch( projection=[Anagram.inputed_words]) if len(query) > 0: for anagram in query: anagram_models.extend(anagram.inputed_words) dictionary_words = {} for word in anagram_models: if len(word) in dictionary_words: dict_words = dictionary_words[len(word)] dict_words.append(word) dictionary_words[len(word)] = dict_words else: dictionary_words[len(word)] = [word] template_values = { "inputword": inputed_word, "dictionary_words": dictionary_words } template = JINJA_ENVIRONMENT.get_template("subanagram.html") self.response.write(template.render(template_values))
def get(self): self.response.headers["Content-Type"] = "text/html" user = Services().get_current_user() word_model = Anagram.query() anagram_model = None if user: url = users.create_logout_url(self.request.uri) myuser_key = ndb.Key("MyUser", Services().get_current_user_id()) myuser = myuser_key.get() if myuser == None: myuser = MyUser(id=user.user_id()) myuser.put() anagram_query = Anagram.query(Anagram.user_id == Services().get_current_user_id()) inputed_word = self.request.get("input_word").lower() if len(inputed_word) > 0: if self.request.GET.get("search") == "Search Word": anagram_query = anagram_query.filter(Anagram.inputed_words.IN([inputed_word])) anagram_model = anagram_query.fetch() else: url = users.create_login_url(self.request.uri) template_values = { "url": url, "user": user, "anagram_model":anagram_model } template = JINJA_ENVIRONMENT.get_template("main.html") self.response.write(template.render(template_values))
def update(id): edit_service = Services.find_one({"_id": ObjectId(id)}) if request.method == "GET": return render_template("update_service.html", edit_service=edit_service) elif request.method == "POST": form = request.form name = form["name"] age = form["age"] gender = form["gender"] address = form["address"] new_value = { "$set": { "name": name, "age": age, "Address": address, "gender": gender } } Services.update_one(edit_service, new_value) return redirect('/all-service/details/{0}'.format(id))
def barberMenu(): option = "0" print("+{:-<50}+".format("")) print('\x1b[6;30;47m' + "|{:^50}|".format("Barbershop System") + '\x1b[0m') print("+{:-<50}+".format("")) print('\x1b[1;32;40m' + "|{:50}|".format("1. Barbers' list") + '\x1b[0m') print("+{:-<50}+".format("")) print('\x1b[1;33;40m' + "|{:50}|".format("2. Customers' list") + '\x1b[0m') print("+{:-<50}+".format("")) print('\x1b[1;34;40m' + "|{:50}|".format("3. Services' list") + '\x1b[0m') print("+{:-<50}+".format("")) print('\x1b[1;35;40m' + "|{:50}|".format("4. Make reservation") + '\x1b[0m') print("+{:-<50}+".format("")) print('\x1b[1;36;40m' + "|{:50}|".format("5. Reservations record") + '\x1b[0m') print("+{:-<50}+".format("")) time.sleep(2) option = input("Choose one option: ") print("+{:-<50}+".format("")) time.sleep(2) if option == "1": Barber.barberList("") elif option == "2": Customer.customerList("") elif option == "3": Services.serviceList("") elif option == "4": Reservation.makeReservation("") elif option == "5": Reservation.reservationScore("") else: print("+{:-<50}+".format("")) print('\x1b[0;37;41m' + "|{:^50}|".format("Option doesn't exist") + '\x1b[0m') print("+{:-<50}+".format("")) exit
def __init__(self, templatelookup, test, filedir): self.templatelookup = templatelookup self.test = test # Allocate objects for all of the control panel's main features. self.traffic = NetworkTraffic(filedir, templatelookup) self.network = NetworkConfiguration(templatelookup, test) self.mesh = MeshConfiguration(templatelookup, test) self.services = Services(templatelookup, test) self.gateways = Gateways(templatelookup, test) # Location of the network.sqlite database, which holds the configuration # of every network interface in the node. if test: # self.netconfdb = '/home/drwho/network.sqlite' self.netconfdb = 'var/db/controlpanel/network.sqlite' logging.debug("Location of NetworkConfiguration.netconfdb: %s", self.netconfdb) else: self.netconfdb = '/var/db/controlpanel/network.sqlite'
class Main: bDebug = False bLog = False oServices = '' oErrorHandler = '' oHelpers = '' def __init__(self): self.oErrorHandler = ErrorHandler() self.oHelpers = Helpers() def run(self): """Check services for all servers configs data""" if self.validateServicesList(): self.oServices = Services() #Create Services object for info in services.services_list: self.oServices.check(info) # show debug self.showDebugResult() # save logs self.saveLogFile() def validateServicesList(self): """Validate if the services list not empty""" bResult=True if len(services.services_list) == 0: print self.oErrorHandler.displayError('cod-003', 'warning') bResult=False return bResult def showDebugResult(self): """ Show debug, first show Error, then Ok results""" if self.bDebug == True: for x in self.oServices.listDebugResultError: print x for x in self.oServices.listDebugResultOk: print x def saveLogFile(self): """Save result in log file""" if self.bLog: try: fileLog = open('logs/log_'+self.oHelpers.getTimeToFileName(), 'w') fileLog.seek(0) fileLog.write("Fecha y Hora: "+self.oHelpers.getTimeToText()+"\r\n \r\n"); for result in self.oServices.listTextResultError: fileLog.write(result) for result in self.oServices.listTextResultOk: fileLog.write(result) fileLog.close() except IOError: print self.oErrorHandler.displayError('cod-005') def showHelp(self): """ Read the help file to show help's script""" try: sHelp = open('docs/help', 'r').read() print sHelp except: print self.oErrorHandler.displayError('cod-004')