def main(argv): if (len(argv) <= 0): Util.printErr("You have not specified any dirpath.") Util.printErr( "Write something like this: formatPhone.py dirpath [scanParentOnly? True|False]" ) return if (len(argv) > 1): scanParentOnly = argv[1] else: scanParentOnly = False dirToScan = argv[0] (f, d) = Util.listFiles(dirToScan, scanParentOnly) Util.printProcess('Reading JSONs') jsons = Util.readJSONFiles(dirToScan, f) print(len(jsons), 'files read.') fileOut = input('Save CSV filename: ') Util.printProcess('Converting to single CSV...') startTime = time.time() indexMap = Phone.createPhoneIndexMap() Phone.mapToCSV(jsons, indexMap, fileOut + '.csv') print('Success! {:f} secs'.format(time.time() - startTime))
def main(argv): if (len(argv) <= 0): Util.printErr("You have not specified any dirpath.") Util.printErr("Write something like this: formatPhone.py dirpath [scanParentOnly? True|False]") return if (len(argv) > 1): scanParentOnly = argv[1] else: scanParentOnly = False dirToScan = argv[0] (f, d) = Util.listFiles(dirToScan, scanParentOnly) Util.printProcess('Reading JSONs') jsons = Util.readJSONFiles(dirToScan, f) print(len(jsons), 'files read.') fileOut = input('Save CSV filename: ') Util.printProcess('Converting to single CSV...') startTime = time.time() indexMap = Phone.createPhoneIndexMap() Phone.mapToCSV(jsons, indexMap, fileOut + '.csv') print('Success! {:f} secs'.format(time.time() - startTime))
def menu(): print('1. Messages 2. Contacts') print('3. Phone 4. Media') print('b. Back 0. Exit') choice = '' while (choice != 0): choice = input('Enter Choice : ') if (choice == '1'): Messages.menu() elif (choice == '2'): Contacts.menu() elif (choice == '3'): Phone.menu() elif (choice == '4'): Media.menu()
def queryDBProducts(): products = [] client = MongoClient() db = client.productsDB # Drop the products collection if it exists. cursor = db.products.find() for JSONproduct in cursor: print("retrieved from database:", JSONproduct) prodNo = JSONproduct["prodNo"] price = float(JSONproduct["price"]) desc = JSONproduct["desc"] if (JSONproduct["type"] == "I"): speed = float(JSONproduct["speed"]) p = Internet(prodNo, price, desc, speed) products.append(p) elif (JSONproduct["type"] == "C"): packages = JSONproduct["packages"] p = Cable(prodNo, price, desc, packages) products.append(p) elif (JSONproduct["type"] == "P"): telNo = JSONproduct["telNo"] p = Phone(prodNo, price, desc, telNo) products.append(p) client.close() return products
def __init__(self, file_name, phone_file, ref_file): self.Prod_list = [] if file_name != "empty": with open(file_name, "r") as csv_file: csv_file.readline() for r in csv_file: listing = r.rstrip().split(",") self.Prod_list.append( Product(listing[1], listing[2], listing[3], listing[4], listing[0])) if ref_file != "empty": with open(ref_file, "r") as csv_file: csv_file.readline() for r in csv_file: listing = r.rstrip().split(",") self.Prod_list.append( Refrigerator(listing[1], listing[2], listing[3], listing[4], listing[0], listing[5], listing[6])) if phone_file != "empty": with open(phone_file, "r") as csv_file: csv_file.readline() for r in csv_file: listing = r.rstrip().split(",") self.Prod_list.append( Phone(listing[1], listing[2], listing[3], listing[4], listing[0], listing[5], listing[6]))
def getProducts(): products = [] os.chdir(ProductFactory.DATA_FILE_PATH) print('reading from: ' + ProductFactory.DATA_FILE_PATH) with open('input_file_BadData.txt', 'r') as f: while True: line = f.readline() #print(line) if not line: break s = line.split("|") prodNo = str(s[1]) match = re.search('^\d{4}[A-Z]\d{3}$', prodNo) #print("line={}, match={}".format(line.rstrip(),prodNo)) if not match: print("ignoring:" + line.rstrip()) continue price = float(s[2]) desc = s[3] if (s[0] == "I"): speed = float(s[4]) p = Internet(prodNo, price, desc, speed) products.append(p) elif (s[0] == "C"): packages = (s[4].rstrip()).split(",") p = Cable(prodNo, price, desc, packages) products.append(p) elif (s[0] == "P"): telNo = str(s[4]) p = Phone(prodNo, price, desc, telNo) products.append(p) f.closed return products
def menu(): print('1. Messages 2. Contacts') print('3. Phone 4. Media') print('b. Back 0. Exit') choice = '' while(choice!=0): choice = input('Enter Choice : ') if( choice == '1' ): Messages.menu() elif( choice == '2'): Contacts.menu() elif( choice == '3'): Phone.menu() elif( choice == '4'): Media.menu()
def getProducts(): products = [] os.chdir(ProductFactory.DATA_FILE_PATH) print('reading from: ' + ProductFactory.DATA_FILE_PATH) with open('input_file.txt', 'r') as f: while True: line = f.readline() #print(line) if not line: break s = line.split("|") prodNo = str(s[1]) price = float(s[2]) desc = s[3] if (s[0] == "I"): speed = float(s[4]) p = Internet(prodNo, price, desc, speed) products.append(p) elif (s[0] == "C"): packages = (s[4].rstrip()).split(",") p = Cable(prodNo, price, desc, packages) products.append(p) elif (s[0] == "P"): telNo = str(s[4]) p = Phone(prodNo, price, desc, telNo) products.append(p) f.closed return products
def getProducts(): #products = [Product('1004X001', 50.00), Product('1004X001', 75.50) ] products = [ Internet('1001I001', 60.00, 'Premium Internet', 100), Cable('1001C001', 80.00, 'Digital Cable', ['Sports', 'Family']), Phone('1001P001', 25.50, 'Standard Phone', '555-555-5555') ] return products
def add_contact(): """Add new contact""" print("\n------New Contact------\n") name = input("Name: ") last_name = input("Last name: ") age = validate_int("Age: ") print("-----------") phone_number = validate_int("Phone number: ") phone_name = input("Name of the phone number: ") print("-----------") email = input("Email: ") phone = Phone(phone_name, phone_number) contact = Contact(name, last_name, age, phone, email) cont_list.add(contact)
def update_contact(hidden=False): """Update a contact""" list_contacts(hidden) sel = validate_int("Insert the number of the contact you want to update: ") if sel in range(1, len(cont_list.contacts)): cont = cont_list.contacts[sel - 1] print("\n------Contact options------\n") print("1. Hide contact") print("2. Add new number") print("3. Update data") op = (int)(input("\nSelect the option you want: ")) if op == 1: cont.set_hidden(True) cont_list.save() elif op == 2: print("-----------") phone_number = validate_int("Phone number: ") phone_name = input("Name of the phone number: ") print("-----------") phone = Phone(phone_name, phone_number) cont.add_phone(phone) elif op == 3: print("If you don't want to change a value, just press enter") name = input("Name: ") name = cont.name if name.strip() == '' else name last_name = input("Last name: ") last_name = cont.last_name if last_name.strip() == '' else last_name age = input("Age: ") age = cont.age if age.strip() == '' else validate_int("Age: ") print("\n-----Phones-----\n") cont.print_phones() sel = input("Insert the number of the phone you want to change, if not press enter: ") if sel != '': try: ph = cont.phones[(int)(sel) - 1] phone_name = input("Name: ") ph.name = ph.name if phone_name.strip() == '' else phone_name phone_number = input("Number: ") ph.number = ph.number if phone_number.strip() == '' else phone_number cont.phones[(int)(sel) - 1] = ph except IndexError: pass email = input("Email: ") email = cont.email if email.strip() == '' else email cont.update_contact(name, last_name, cont.phones, age, email) cont_list.save()
def get_phone_number_details(self): number = self.phoneNumberTextField.text() self.text = Phone.get_addresses(number) msg = QMessageBox() msg.setWindowTitle("Hits From Twilio") msg.setInformativeText("Hit Copy to Exit As Well") msg.setText(self.text) saveFiles = QPushButton("Save As") copyText = QPushButton("Copy") saveFiles.clicked.connect(self.save_files) copyText.clicked.connect(self.copy_text) msg.addButton(saveFiles, QMessageBox.YesRole) msg.addButton(copyText, QMessageBox.YesRole) val = msg.exec_()
def getCartAndProducts(): carts = [] products = [] name = None os.chdir(ProductFactory.DATA_FILE_PATH) print('reading from: ' + ProductFactory.DATA_FILE_PATH) with open('input_file_BONUS.txt', 'r') as f: while True: line = f.readline() if not line: break s = line.split("|") if (len(s)!=6): print( "Error: invalid input file line s={}".format(s)) continue; newName = s[5].rstrip() if ((name != None) and (newName != name)): carts.append( [ name, products] ) products = [] name = newName prodNo = str(s[1]) price = float(s[2]) desc = s[3] if (s[0] == "I"): speed = float(s[4]) p = Internet( prodNo, price, desc, speed) products.append(p) elif (s[0] == "C"): packages = (s[4].rstrip()).split(",") p = Cable( prodNo, price, desc, packages) products.append(p) elif (s[0] == "P"): telNo = str(s[4]) p = Phone( prodNo, price, desc, telNo) products.append(p) f.closed if (len(products) != 0): carts.append( [ name, products] ) return carts
def __init__(self): self.super(taskManager).__init__() self.isInside = False self.startTime = 0 if not environment.usePhoneCursor: self.rotationTarget = RotationTarget.RotationTarget(environment)#use the classical rotation targetCore class self.targetCore = None self.phone = None self.targetShadow = None #geometry self.level = 0 #when started is set to level 1 self.cursorNode = None self.points = 0 self.id_e_r = 0 self.id_e_t = 0 self.phoneTargetHull = None self.lastEndPos = None self.lastEndRot = None self.leftRight = False #environment.getWindow().on_key_press(self.handle_key) environment.setup(graph) if environment.usePhoneCursor: self.phone = Phone.Phone(environment) if config.showFramingBorder: self.phone.setErrorMargin(W_trans[self.level]) else: self.phone.setErrorMargin(0) self.targetCore = self.phone.geometry else: self.targetCore = loader.create_geometry_from_file( "modified_sphere", "data/objects/modified_sphere.obj", avango.gua.LoaderFlags.NORMALIZE_SCALE ) self.targetCore.Material.value.set_uniform("Color", avango.gua.Vec4(0.8, 0.0, 0.8, 1))#avango.gua.Vec4(0.2, 0.3, 0.2, 1) self.targetCore.Material.value.set_uniform("Emissivity", 0.5) self.targetCore.Material.value.EnableBackfaceCulling.value = False environment.everyObject.Children.value.append(self.targetCore) if environment.taskDOFTranslate > 0:#show targets # init targetCore position #set position of targetCore self.targetCore.Transform.value = (avango.gua.make_trans_mat((self.leftRight*2-1) * environment.A_trans[self.level] / 2, 0, 0) * avango.gua.make_scale_mat(self.targetCore.Transform.value.get_scale()))#keep scale if environment.usePhoneCursor: if config.showFramingBorder: self.phoneTargetHull = Phone.Phone(environment) self.phoneTargetHull.setTranslate(avango.gua.make_trans_mat(-environment.A_trans[self.level] / 2, 0, 0)) self.phoneTargetHull.setErrorMargin(0) environment.everyObject.Children.value.append(self.phoneTargetHull.geometry) #configure targetCore shadow if environment.usePhoneCursor: self.targetShadow = loader.create_geometry_from_file( "phone", "/opt/3d_models/targets/phone/phoneAntennaOutlines.obj", avango.gua.LoaderFlags.NORMALIZE_SCALE ) Phone.setErrorMargin(self.targetShadow, W_trans[self.level]) else: self.targetShadow = loader.create_geometry_from_file( "modified_sphere", "data/objects/modified_sphere.obj", avango.gua.LoaderFlags.NORMALIZE_SCALE ) #may need to apply size here self.targetShadow.Material.value.set_uniform("Color", avango.gua.Vec4(0.5, 0.5, 0.5, 0.1)) self.targetShadow.Material.value.EnableBackfaceCulling.value = False environment.everyObject.Children.value.append(self.targetShadow) #set position self.targetShadow.Transform.value = (avango.gua.make_trans_mat((self.leftRight*2-1) * -environment.A_trans[self.level] / 2, 0, 0) * avango.gua.make_scale_mat(self.targetShadow.Transform.value.get_scale())) # loadMeshes self.cursorContainer = Cursor.Cursor().create(environment) self.cursorNode = self.cursorContainer.getNode() if config.taskDOFRotate > 0: if config.usePhoneCursor: if self.phone is None: self.phone = Phone.Phone(environment) self.phone.setErrorMargin(0) else: self.rotationTarget.setupDisks(self.cursorNode) self.rotationTarget.setDisksTransMats(targetDiameter[0]) self.rotationTarget.setRotation(avango.gua.make_rot_mat(environment.A_rot[0], 0, 1, 0)) #self.rotationTarget.setDisksTransMats(targetDiameter[0]) # listen to button button_sensor = avango.daemon.nodes.DeviceSensor(DeviceService=avango.daemon.DeviceService()) button_sensor.Station.value = "gua-device-keyboard" self.button.connect_from(button_sensor.Button0) # listen to tracked position of pointers pointer_device_sensor = avango.daemon.nodes.DeviceSensor(DeviceService=avango.daemon.DeviceService()) pointer_device_sensor.TransmitterOffset.value = environment.offsetTracking # connect pencil->inputMatA pointer_device_sensor.Station.value = "pointer2" self.inputMatB.connect_from(pointer_device_sensor.Matrix) # timer timer = avango.nodes.TimeSensor() self.timer.connect_from(timer.Time) environment.launch(globals())
import Phone Phone.G3() Phone.Isdn()
import sys; import logging; import Phone; #logging message in python logger=logging.getLogger("Logger"); logger.setLevel(logging.DEBUG); try: print("IPhone"); phone5s=Phone.IPhone("IPhone 5S",21000) phone5s.print(); phone6s=Phone.IPhone("IPhone 6S",42000) phone6s.print(); print("-------------------------"); print("Samsung"); samsung=Phone.Samsung("Galaxy S",47000); samsung.print(); print("-------------------------"); #Use Inheritance child=Phone.Child(); child.childMethod(); child.setAttr(123); child.getAttr(); child.parentMethod(); print("-------------------------");
import Owner as o import Phone as p owner1 = o.Owner('John') owner1.set_email('*****@*****.**') phone1 = p.Phone(12345678, owner1)
import Phone Phone.musicplay() Phone.msg() Phone.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Jun 23 19:39:53 2019 @author: cawang """ import Phone # import Phone package. Phone/ Phone.Pots() # call pots() inside Phone. Phone.Isdn() Phone.G3()
import Phone Phone.Posting()
#!/usr/bin/python # Now, import the Phone Package import Phone Phone.Pots() Phone.lsdn() Phone.G33()
#!/usr/bin/python import Phone as mypkg import Phone print dir(Phone) mypkg.Pot1() Phone.Pot1() Phone.Pot2() Phone.Isdn1() Phone.Isdn2() Phone.G3()
def nextSettingStep(self): self.leftRight = not self.leftRight if not self.runningTest:#if not running start self.runningTest = True #if self.counter > 0 and self.level < environment.config.getLevelsCount()-1: # self.counter += 1 else: self.counter += 1 if self.counter % environment.levelSize == 0 and self.counter > 0: if environment.config.playLevelUpSound: environment.playSound("levelUp") self.level += 1 self.runningTest = False if self.runningTest: #environment.setBackgroundColor(avango.gua.Color(0.5, 0.5, 0.5)) self.targetCore.Material.value.set_uniform("Color", avango.gua.Vec4(0.8, 0.0, 0.8, 1)) else: self.targetCore.Material.value.set_uniform("Color", avango.gua.Vec4(0.8, 0.8, 0.8, 1)) #environment.setBackgroundColor(avango.gua.Color(0, 0, 0.5)) if self.level >= environment.config.getLevelsCount(): self.endedTests = True print("Your Score: " + str(self.points)) else: if config.taskDOFTranslate > 0: # move targetCore self.targetCore.Transform.value = (avango.gua.make_trans_mat((self.leftRight*2-1) * environment.A_trans[self.level] / 2, 0, 0) * avango.gua.make_scale_mat(W_trans[self.level])) self.targetShadow.Transform.value = (avango.gua.make_trans_mat((self.leftRight*2-1) * -environment.A_trans[self.level] / 2, 0, 0) * avango.gua.make_rot_mat(self.targetShadow.Transform.value.get_rotate_scale_corrected())#keep rot * avango.gua.make_scale_mat(self.targetShadow.Transform.value.get_scale())#keep scale ) if config.usePhoneCursor: #self.phoneTargetHull.geometry.Transform.value = (avango.gua.make_trans_mat(self.leftRight * environment.A_trans[self.level] / 2, 0, 0) #* avango.gua.make_scale_mat(W_trans[self.level])) if config.showFramingBorder: self.phoneTargetHull.setTranslate(avango.gua.make_trans_mat((self.leftRight*2-1) * environment.A_trans[self.level] / 2, 0, 0)) Phone.setErrorMargin(self.phoneTargetHull.geometry, W_trans[self.level]) Phone.setErrorMargin(self.targetCore, 0) Phone.setErrorMargin(self.targetShadow, W_trans[self.level]) #apply rotation to targetCore if config.taskDOFRotate > 0: if environment.randomTargets: if config.taskDOFRotate > 0: if config.taskDOFRotate == 3: rotation = self.getRandomRotation3D() self.rotationTarget.setRotation(rotation) else: rotation = self.getRandomRotation2D() self.rotationTarget.setRotation(rotation) else: if self.leftRight: # toggle beetwen distance = environment.A_rot[self.level] if config.taskDOFRotate == 3: rotateAroundX = 1 else: rotateAroundX = 0 else: rotateAroundX = 0 distance = 0 #apply directly to targetCore if a rotation task if config.usePhoneCursor: if self.phoneTargetHull is not None: self.phoneTargetHull.setRotation(avango.gua.make_rot_mat(distance, rotateAroundX, 1, 0)) self.phone.setRotation(avango.gua.make_rot_mat(distance, rotateAroundX, 1, 0)) if config.showFramingBorder: self.phone.setErrorMargin(W_trans[self.level]) else: self.phone.setErrorMargin(0) else: self.rotationTarget.setRotation(avango.gua.make_rot_mat(distance, rotateAroundX, 1, 0)) self.rotationTarget.setDisksTransMats(targetDiameter[self.level]) if environment.animationPreview: if self.targetCore is None: self.cursorContainer.animateTo( None, self.rotationTarget.getRotate() ) else: self.cursorContainer.animateTo( self.targetCore.Transform.value.get_translate(), self.rotationTarget.getRotate() )
import Phone import Phone Phone.STD() Phone.Local()
#现在,在Phone目录下创建file __init__.py: #Phone/__init__.py #当你导入Phone时,为了能够使用所有函数,你需要在__init__.py里使用显式的导入语句,如下: #from Pots import Pots #from Isdn import Isdn #from G3 import G3 #当你把这些代码添加到__init__.py之后,导入Phone包的时候这些类就全都是可用的了。 # ##!/usr/bin/python ## -*- coding: UTF-8 -*- # ## 导入 Phone 包 #import Phone # #Phone.Pots() #Phone.Isdn() #Phone.G3() # #为了举例,我们只在每个文件里放置了一个函数,但其实你可以放置许多函数。你也可以在这些文件里定义Python的类,然后为这些类建一个包。 import Phone Phone.Pots() Phone.Isdn() Phone.G3() #以上实例输出结果: #I'm Pots Phone #I'm 3G Phone #I'm ISDN Phone
#!/usr/bin/env python3 import Phone # 15.8 Pacotes Phone.Pots() Phone.isdn() Phone.g3() # Caso queira verificar todas as funcoes disponiveis # p = dir(Phone) # # print(p)
import Phone Phone.Pots() Phone.isdn() Phone.G3()
# Uncomment the following line to fix the code: global Money Money = Money + 1 print "locals() = " print locals() print "globals() = " print globals() print "Money before calling addMoney() = %d" %(Money) addMoney() print "Money after calling addMoney() = " + str(Money) print "dir(time) = " print dir(time) Phone.myPots() Phone.myISDN() Phone.myG3() # ================ File I/O print "\n=================== File I/O ===================" inStr = input ("Enter your input: ") print "You've entered: " + str(inStr) currentDir = os.getcwd() print "-- Current directory is: ", currentDir try: os.chdir("data") except:
import Phone as p import Owner as o dict = {} while True: number = int(input('What is your desired phone number? ')) if number in dict: print('This number is not available, please try again.') continue name = input('What is your name? ') owner = o.Owner(name) email = input('What is your email? ') owner.set_email(email) phone = p.Phone(number, owner) dict[phone.get_number()] = phone print('The number %d has been assigned to %s' % (phone.get_number(), owner.get_name())) check = input('Type q to quit the program: ') if check.lower() == 'q': break
def add_phone(self, phone_number, person_id): new_phone = Phone.Phone() new_phone.phone_number = phone_number new_phone.person_id = person_id Phone.Phone().add_phone(new_phone)