Пример #1
0
    def _open_file(self, filename):

        ctr = 0
        try:
            with open(filename, mode='r') as csv_file:
                csv_reader = csv.DictReader(csv_file)

                for line in csv_reader:
                    record = CovidRecord(
                        line.get("pruid"), line.get("prname"),
                        line.get("prnameFR"),
                        process_as_date(line.get("date"), False),
                        line.get("numconf"), line.get("numprob"),
                        line.get("numdeaths"), line.get("numtotal"),
                        line.get("numtoday"), line.get("ratetotal"))
                    self.covidRecord.append(record)
                    # simple counter to read 'n' number of records
                    # ctr += 1
                    # if ctr >= 10:
                    #     break

            return self.covidRecord
        except IOError:
            print("File is unavailable or missing ")
            sys.exit()
Пример #2
0
    def create_new_record(self):
        print("Please enter the following information to create new record.")
        pruid = self.get_user_input("pruid: ")
        prname = input("prname: ")
        prname_fr = input("prname_fr: ")
        date = input("date(mm/dd/yyyy): ")
        numconf = self.get_user_input("numconf: ")
        numprob = self.get_user_input("numprob: ")
        numdeaths = self.get_user_input("numdeaths: ")
        numtotal = self.get_user_input("numtotal: ")
        numtoday = self.get_user_input("numtoday: ")
        ratetotal = input("ratetotal: ")

        new_record = CovidRecord(
            pruid,
            prname,
            prname_fr,
            process_as_date(date),
            numconf,
            numprob,
            numdeaths,
            numtotal,
            numtoday,
            ratetotal
        )

        self.covidRecord.append(new_record)
        print("Record created successfully")
Пример #3
0
    def information_by_date(self):
        date = process_as_date(input("\nPlease enter a date (Jan 1, 2020 to Jan 9, 2021)(mm/dd/yyyy): "), False)
        t = PrettyTable(
            ["pruid", "prname", "prname_fr", "numconf", "numprob", "numdeaths", "numtotal", "numtoday",
             "ratetotal"])

        for rec in self.covidRecord:
            if rec.date == date:
                t.add_row(
                    [rec.pruid, rec.prname, rec.prname_fr, rec.numconf, rec.numprob, rec.numdeaths, rec.numtotal,
                     rec.numtoday, rec.ratetotal])
        print(t)
Пример #4
0
    def information_by_date_and_province(self):
        province = input("\nPlease enter province name or \"Canada\" for the whole country: ")
        date = process_as_date(input("\nPlease enter a date (Jan 2020 to Jan 2021)(mm/yyyy): "), True)
        t = PrettyTable(
            ["date", "pruid", "prname", "prname_fr", "numconf", "numprob", "numdeaths", "numtotal", "numtoday",
             "ratetotal"])

        for rec in self.covidRecord:
            if rec.date.month == date.month and rec.prname.lower() == province.lower():
                t.add_row(
                    [rec.date.strftime("%b %d %Y"), rec.pruid, rec.prname, rec.prname_fr, rec.numconf, rec.numprob,
                     rec.numdeaths, rec.numtotal, rec.numtoday, rec.ratetotal])
        print(t)
Пример #5
0
    def edit_record(self):
        x = self.get_user_input("Please enter a row number you want to edit: ") - 1
        t = PrettyTable(
            ["pruid", "prname", "prname_fr", "date", "numconf", "numprob", "numdeaths", "numtotal",
             "numtoday",
             "ratetotal"])
        t.add_row(
            [self.covidRecord[x].pruid, self.covidRecord[x].prname, self.covidRecord[x].prname_fr,
             self.covidRecord[x].date.strftime("%b %d %Y"), self.covidRecord[x].numconf,
             self.covidRecord[x].numprob,
             self.covidRecord[x].numdeaths, self.covidRecord[x].numtotal, self.covidRecord[x].numtoday,
             self.covidRecord[x].ratetotal])

        print(t)

        pruid = self.get_user_input("pruid: ")
        prname = input("prname: ")
        prname_fr = input("prname_fr: ")
        date = input("date: ")
        numconf = self.get_user_input("numconf: ")
        numprob = self.get_user_input("numprob: ")
        numdeaths = self.get_user_input("numdeaths: ")
        numtotal = self.get_user_input("numtotal: ")
        numtoday = self.get_user_input("numtoday: ")
        ratetotal = input("ratetotal: ")

        new_record = CovidRecord(
            pruid,
            prname,
            prname_fr,
            process_as_date(date),
            numconf,
            numprob,
            numdeaths,
            numtotal,
            numtoday,
            ratetotal
        )

        self.covidRecord[x] = new_record