Exemplo n.º 1
0
    def get(self):
        person = Person("Fe", date(1989, 2, 21))

        loader = template.Loader("templates")
        t = loader.load("person.html")
        html = t.generate(name=person.name, days=person.days())
        self.write(html)
Exemplo n.º 2
0
 def new_person(self):
     name = self.request.get("name")
     if not Person.validate_name(name):
         self.response.status = 409
         self.write(
             "Invalid name. A valid name must be unique, between 1 and 20 letters "
             "and must not contains punctuations (except the '_')")
     else:
         person = Person(name=name)
         person.put()
         self.write(";".join([person.key.urlsafe(), person.name]))
Exemplo n.º 3
0
def add_product():
    person = Person()
    person.get_person()
    random_person = person
    db_operations = DBOperations()
    id = db_operations.insert(random_person.random_person)
    result = db_operations.print_by_id(id)
    # pprint.pprint(result)
    person_schema = PersonSchema()
    mm = person_schema.dump(result)
    pprint.pprint(mm)
    r = make_response(mm)
    r.mimetype = "application/json"
    return r
Exemplo n.º 4
0
def entry_point(nation, gender, file):
    if nation is None and gender is None:
        person = Person()
        person.get_person()
        random_person = person
    elif nation is not None:
        person = PersonWithNationality()
        person.get_person(nation)
        random_person = person
    elif gender is not None:
        person = PersonWithGender()
        person.get_person(gender)
        random_person = person
    db_operations = DBOperations()
    db_operations.insert(random_person.random_person)
    PrintOption.do_print(file, random_person)
Exemplo n.º 5
0
    def load_data(self):
        swapi_conn = SWAPI()

        list_planet_dicts = swapi_conn.gather_planets()
        list_people_dicts = swapi_conn.gather_people()

        # satisfies requirement 1.
        [
            self.planet_obj_list.append(
                Planet(p['url'], p['name'], p['residents']))
            for p in list_planet_dicts
        ]
        [
            self.people_obj_list.append(
                Person(p['url'], p['name'], p['homeworld']))
            for p in list_people_dicts
        ]

        for planet_obj in self.planet_obj_list:
            temp_people_obj_list = list()

            for people_obj in self.people_obj_list:

                if people_obj.url_id in planet_obj.residents_list:

                    temp_people_obj_list.append(people_obj)

            self.joined_structure[planet_obj] = temp_people_obj_list
def __readCSV_person(path_file: str) -> List[Person]:
    try:
        lstPerson: List[Person] = []
        with open(path_file, 'r') as csvfile:
            dataCSV = csv.reader(csvfile, delimiter=',')

            # Ignora a primeira linha do arquivo, pois é o header
            next(dataCSV)

            # Percorre pelas linhas instanciando o objeto da classe Person armazenando dentro da lista
            for dataRow in dataCSV:
                lstPerson.append(
                    Person(
                        dataRow[2],  # id
                        dataRow[0],  # email
                        dataRow[1],  # gender
                        datetime.datetime.strptime(dataRow[3],
                                                   "%Y-%m-%d"),  # birthdate
                        int(dataRow[4]),  # height
                        int(dataRow[5]),  # weight
                    ))
    except FileNotFoundError as err:
        print(err)
        sys.exit(1)
    except IOError as err:
        print(err)
        sys.exit(1)
    except Exception as err:
        print(err)
        sys.exit(1)
    else:
        return lstPerson
Exemplo n.º 7
0
    def render_new_month(self, **kwargs):
        # new month info
        now = datetime.now()
        month = now.strftime("%B %Y")
        start_date = now.strftime("%d/%m/%y")
        people = Person.get_all()

        # prev month
        prev_month = Month.get_current_month()
        if prev_month and not prev_month.time_end:
            # convert people key to name
            prev_month.time_to_end = now
            prev_month.people_name = []
            for person_key in prev_month.people:
                for person in people:
                    if person.key == person_key:
                        prev_month.people_name.append(person.name)
            prev_month.people_name = ", ".join(prev_month.people_name)

        # render html
        self.render("newmonth.html",
                    month=month,
                    start_date=start_date,
                    page_title=self.PAGE_TITLE,
                    people=people,
                    prev_month=prev_month,
                    **kwargs)
Exemplo n.º 8
0
def parse_csv():
    with open(csvFilePath, newline='', encoding='utf-8') as csvFile:
        csvReader = csv.reader(csvFile, delimiter=',')
        for row in csvReader:
            if len(row) == 9:
                newPerson = Person(row[1], row[2], row[3], row[4], row[5], row[6], row[7].encode("utf-8"), row[8], [])
                personList.append(newPerson)
            else:
                print(row[0], row[1])
Exemplo n.º 9
0
 def get_people(self):
     self.start_connection(self.database)
     people = getattr(self, "cnx").cursor()
     people.execute(self.retrieve_all)
     people_list = list()
     for data in people:
         person = Person(data[0], data[1], data[2], data[3], data[4])
         people_list.append(person)
     self.stop_connection()
     return people_list
Exemplo n.º 10
0
 def get(self):
     if not is_login(self):
         self.response.set_cookie("redirect", "/admin")
         self.redirect("/admin/login")
     else:
         self.render(
             "admin.html",
             app_name=app_config["app-name"],
             account=AdminAccount.get(),
             people=Person.get_all(),
             months=Month.get_all(),
         )
Exemplo n.º 11
0
class PersonHandler(tornado.web.RequestHandler):
    PEOPLE = {
        "projetos":
        Person("Matéria Prima", date(1989, 2, 21),
               "https://pypi.org/static/images/logo-large.72ad8bf1.svg"),
        "daniel":
        Person("Daniel", date(1986, 11, 12),
               "https://pypi.org/static/images/logo-large.72ad8bf1.svg"),
        "maya":
        Person("Maya", date(2017, 5, 26)),
        "mae":
        Person("Claudia", date(1962, 3, 29)),
    }

    def get(self, name: str):
        person = self.PEOPLE[name]
        loader = template.Loader("templates")
        t = loader.load("person.html")
        html = t.generate(name=person.name,
                          days=person.days(),
                          people=self.PEOPLE)
        self.write(html)
Exemplo n.º 12
0
    def parse_init_people_file(self):
        """Reads input file and parse each line to a Person object which is inserted in People list"""
        people = list()
        input_file = open("input.csv", "r", 1)
        data = input_file.read().splitlines()

        for ln in data:
            data = ln.split(',')
            person = Person()
            setattr(person, "id", data[0])
            setattr(person, "name", data[1])
            setattr(person, "age", data[2])
            setattr(person, "phone_number", data[3])
            setattr(person, "birthday", data[4])
            people.append(person)
        input_file.close()
        return people
Exemplo n.º 13
0
def readCSV(input_filename: str) -> List[Person]:
    '''
        Read the content inside the filename passed as argument and transform 
        to the Person objects.
    '''

    try:
        lstPerson: List[Person] = []
        with open(os.path.join(_INPUT_FILES_PATH, input_filename),
                  'r') as csvfile:
            dataCSV = csv.reader(csvfile, delimiter=',')

            # Ignora a primeira linha do arquivo, pois é o header
            next(dataCSV)

            # Percorre pelas linhas instanciando o objeto da classe Person armazenando dentro da lista
            for dataRow in dataCSV:
                lstPerson.append(
                    Person(
                        dataRow[2],  # id
                        dataRow[0],  # email
                        dataRow[1],  # gender
                        datetime.datetime.strptime(dataRow[3],
                                                   "%Y-%m-%d"),  # birthdate
                        int(dataRow[4]),  # height
                        int(dataRow[5]),  # weight
                    ))
    except FileNotFoundError as err:
        print(err)
        sys.exit(1)
    except IOError as err:
        print(err)
        sys.exit(1)
    except Exception as err:
        print(err)
        sys.exit(1)
    else:
        return lstPerson
Exemplo n.º 14
0
 def __init__(self, name="", ssn="", username="", password="", admin=False):
     Person.__init__(self, name, ssn)
     self.__username = username
     self.__password = password
     self.__admin = admin
Exemplo n.º 15
0
 def __init__(self, unique_id, name="", ssn="", email="", gsm=""):
     Person.__init__(self, name, ssn)
     self.__email = email
     self.__gsm = gsm
     self.__customer_id = unique_id
Exemplo n.º 16
0
import sys

# Add parent directory to the path in order to import models
sys.path.append("..")

from models.Person import Person

print("start")
p = Person()
# p.create( {username}, {password}, {full name}, {email} )
p.create("hpotter", "magic123", "POTTER, Harry", "*****@*****.**")
print("finished")

Exemplo n.º 17
0
from models.Person import Person
from models.PDFOutput import PDFOutput
from models.TextOutput import TextOutput
from models.Context import Context
import sys
sys.stdout.flush()

if __name__ == "__main__":
    name = raw_input("Enter the name:")
    age = raw_input("Enter the age:")    
    mobile_number = raw_input("Enter the mobile number:")
    city = raw_input("Enter the mobile city:")
    export_type = raw_input("Enter the export type - pdf | text:")
    person = Person(name, age, city , mobile_number)
    
    if export_type == "text":
        output = TextOutput()
    elif export_type == "pdf":
        output = PDFOutput()
    else:
        print "Wrong choice"
        exit()
        
    context = Context(output)
    context.context_interface(person)
Exemplo n.º 18
0
 def __init__(self, first_name, last_name, salutation, position):
     Person.__init__(self, first_name, last_name, salutation)
     self.position = position
     self.department_id = ""
Exemplo n.º 19
0
 def Person(cls, id, name=None):
     return Person(cls, cls.session, id, name)