示例#1
0
###############################################################
# do not modify the code in here ##############################
from helper.JsonReadWriter import JsonReadWriter
from helper.TableDisplay import TableDisplay
from helper.NavigationDisplay import NavigationDisplay

DATA_PATH_JSON = "data/patients.json"

# load data
jsonRW = JsonReadWriter(DATA_PATH_JSON)
data = jsonRW.load()

DATA_FIELDS = data[0].keys()

# create display instance
tableDisplay = TableDisplay(DATA_FIELDS)
navDisplay = NavigationDisplay()
# do not delete the code in here ##############################
###############################################################
# 1. Open the data file patients.json in the data folder. Observe the keys of each data item
# 2. Create a Patient class, defining a constructor and initialising the instance variables.
# In the constructor, you need to use the EXACT field names as you saw in step 1.
# 3. Observe the functionalities available in the NavigationDisplay class's displaymainMenu method
# 4. Use input to get user action and cast it to integer.
# 5. Use if statements to handle multiple functionalities. For example, if user inputs 1, you should write code
# to handle adding new data.
# 6. To display the table with data, use tableDisplay.display(data)
# 7. To save data to JSON file, use jsonRW.save(data)
# 8. To add new entry to the data variable, append it with the Dictionary form of the Patient class instance
# 9. This is a fairly open-ended coding challenge. Time to put that Creative mind to good use. Happy coding!
示例#2
0
from helper.CsvReadWriter import CsvReadWriter
from helper.JsonReadWriter import JsonReadWriter
from helper.NavigationDisplay import NavigationDisplay
from helper.TableDisplay import TableDisplay
from helper.Utility import clearScreen
import random
import time

###################################
SYMBOLS = ["'", "/", "\\", "?", "."]
DATA_PATH_CSV_QUESTIONS = "data/questions.csv"
DATA_PATH_JSON_SCOREBOARD = "data/scoreBoard.json"

jsonRW = JsonReadWriter(DATA_PATH_JSON_SCOREBOARD)
scoreBoardData = jsonRW.load()

csvRW = CsvReadWriter(DATA_PATH_CSV_QUESTIONS)
questionsData = csvRW.loadAsDictionary()

SCOREBOARD_FIELDS = scoreBoardData[0].keys()
tableDisplay = TableDisplay(SCOREBOARD_FIELDS)

scoreBoardData.sort(key=lambda x: x["score"], reverse=True)
highestScore = scoreBoardData[0]["score"]

navDisplay = NavigationDisplay()
####################################


def showMessage(message):
    print(message)
示例#3
0
from helper.JsonReadWriter import JsonReadWriter
from helper.NavigationDisplay import NavigationDisplay
from helper.TableDisplay import TableDisplay
from helper.Utility import clearScreen
from Birthdate import Birthdate
from datetime import date, datetime
from config import DATE_FORMAT
import time

##############################

jsonRW = JsonReadWriter("data/birthdays.json")
data = jsonRW.load()

DATA_FIELDS = list(data[0].keys())

tableDisplay = TableDisplay(data[0].keys())
navDisplay = NavigationDisplay()

##############################


def showMessage(message):
    print(message)
    input("Press any key to continue: ")


def generateDataID():
    listOfIDs = [int(item["ID"]) for item in data]
    maxID = max(listOfIDs)
    return maxID + 1
# 1. From the folder helper, there's a file named JsonReadWriter.py
#   from that folder, import the class JsonReadWriter
# 2. Import the Python's built in library called `pprint`
# 3. Instantiate the JsonReadWriter class by passing in the path
#   to the data file. The data is in `data/json/students.json`
# 4. Load the Json data and store in a variable, using the JsonReadWriter's `load()`
#   method. Print the result if necessary.
# 5. Instantiate the pprint class by calling `pprint.PrettyPrinter(indent=4)`
# 6. Now, use the pprint instance you created to display the data nicely to screen, by
#   calling its `pprint(data)` instance method.
# 7. Display the third student's names, class, and mobile number to the screen nicely.

from helper.JsonReadWriter import JsonReadWriter
import pprint

jsonRW = JsonReadWriter("data/json/students.json")
data = jsonRW.load()
# print(data)

pp = pprint.PrettyPrinter(indent=4)
pp.pprint(data)

# thrid student's name, class, mobile number
student = data[2]
print()
print("Name: ", student["firstName"] + " " + student["lastName"])
print("Class: ", student["class"])
print("Mobile: ", student["contact"]["mobile"])