Beispiel #1
0
def printXml():
    dao = Dao()
    properties = PropertiesReader()
    userList = dao.getUsers()
    root = ET.Element("xml")

    recordUpdated = ET.SubElement(root, "agenda")

    for user in userList:
        person = ET.SubElement(recordUpdated, "person")
        personId = ET.SubElement(person, "id").text = str(user.id)
        personName = ET.SubElement(person, "name").text = user.name
        personAge = ET.SubElement(person, "age").text = user.age
        personPhoneNumber = ET.SubElement(
            person, "phone_number").text = user.phoneNumber
        birthDate = datetime.strptime(user.birthday, "%Y-%m-%d")
        personBirthDate = ET.SubElement(person, "birthday")
        personBirthday = ET.SubElement(personBirthDate,
                                       "day").text = str(birthDate.day)
        personBirthMonth = ET.SubElement(personBirthDate,
                                         "month").text = str(birthDate.month)
        personBirthYear = ET.SubElement(personBirthDate,
                                        "year").text = str(birthDate.year)

    tree = ET.ElementTree(root)
    filename = properties.dictionary["XML_FILENAME"]
    directory = os.path.dirname(filename)
    noDir = directory == ""
    if not noDir:
        if not os.path.exists(directory):
            os.makedirs(directory)

    tree.write(filename)
    print "XML printed as:", filename
def printXml():
    dao = Dao()
    properties = PropertiesReader()
    userList = dao.getUsers()
    root = ET.Element("xml")

    recordUpdated = ET.SubElement(root, "agenda")

    for user in userList:
        person = ET.SubElement(recordUpdated, "person")
        personId = ET.SubElement(person, "id").text = str(user.id)
        personName = ET.SubElement(person, "name").text = user.name
        personAge = ET.SubElement(person, "age").text = user.age
        personPhoneNumber = ET.SubElement(person,"phone_number").text = user.phoneNumber
        birthDate = datetime.strptime(user.birthday, "%Y-%m-%d")
        personBirthDate = ET.SubElement(person, "birthday")
        personBirthday = ET.SubElement(personBirthDate, "day").text = str(birthDate.day)
        personBirthMonth = ET.SubElement(personBirthDate, "month").text = str(birthDate.month)
        personBirthYear = ET.SubElement(personBirthDate, "year").text = str(birthDate.year)

    tree = ET.ElementTree(root)
    filename = properties.dictionary["XML_FILENAME"]
    directory = os.path.dirname(filename)
    noDir = directory == ""
    if not noDir:
        if not os.path.exists(directory):
            os.makedirs(directory)

    tree.write(filename)
    print "XML printed as:", filename
def doSomething():
    dao = Dao()
    userId = raw_input("Enter the employee id to update: ")
    user = findUserById(dao,userId)
    if (user is None):
        print "User was not found"
    else:
        dao.printUser(userId)
        updateUser(dao,user)
Beispiel #4
0
def doSomething():
    dao = Dao()
    userId = raw_input("Enter the employee id to update: ")
    user = findUserById(dao, userId)
    if (user is None):
        print "User was not found"
    else:
        dao.printUser(userId)
        updateUser(dao, user)
def doSomething():
    dao = Dao()
    try:
        f = open("input.csv")
        lines = f.readlines()
        userList = []
        for line in lines:
            properties = line.split(",")
            newUser = User()
            setattr(newUser, "id", properties[0].strip())
            setattr(newUser, "name", properties[1].strip())
            setattr(newUser, "age", properties[2].strip())
            setattr(newUser, "phoneNumber", properties[3].strip())
            setattr(newUser, "birthday", properties[4].rstrip("\n"))
            userList.append(newUser)

        if (userList):
            dao.insertUsers(userList)
        else:
            print "file is empty"
    except IOError:
        print "File not Found"
Beispiel #6
0
def doSomething():
    dao = Dao()
    try:
        f = open("input.csv")
        lines = f.readlines()
        userList = []
        for line in lines:
            properties = line.split(",")
            newUser = User()
            setattr(newUser, "id", properties[0].strip())
            setattr(newUser, "name", properties[1].strip())
            setattr(newUser, "age", properties[2].strip())
            setattr(newUser, "phoneNumber", properties[3].strip())
            setattr(newUser, "birthday", properties[4].rstrip("\n"))
            userList.append(newUser)

        if (userList):
            dao.insertUsers(userList)
        else:
            print "file is empty"
    except IOError:
        print "File not Found"