Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from abc import ABC, abstractmethod
- class Handler: # Check: how to decide which methods should be abstract?
- def __init__(self):
- self.content = None
- @abstractmethod
- def read(self):
- pass
- @abstractmethod
- def store(self,es,fname,path):
- pass
- def getContent(self): # Check: why this is not abstract?
- return self.content
- class JSONHandler(Handler):
- def __init__(self, filename, path=''):
- super().__init__() # Check: why do we call parent's initializer?
- self.jsonFile = path+filename # Check: specialization - behaviour/property that the child adds to the parent
- def read(self): # Check: why do we provide implementation here?
- fo = open(self.jsonFile,'r')
- c = fo.read()
- self.content = json.loads(c) # Check: deserialize json content
- fo.close()
- def store(self,es,fname,path):
- addad = Address('The Netherlands', 'Rotterdam', '2323AX', 'Zwartehondstraat', '24a')
- adic = json.dumps(addad.__dict__, indent=3)
- fo = open(r'booksset1.json', 'a')
- fo.write(adic)
- fo.close()
- class Library:
- def __init__(self, srchwrd):
- self.Name = "Library of Rotterdam"
- self.searchword = srchwrd
- def CountBooks(self):
- bo = open("booksset1.json", 'r')
- bo2 = bo.read()
- data = json.loads(bo2)
- for u in data:
- print('Name: ' + u[self.searchword])
- bo.close()
- class Person:
- def __init__(self, nmbr, gndr, nmst, gvnnm, srnm, strtddrss, zpcd, ct, mladdrss, usrnm, tlphnnmbr):
- self.Number = nmbr
- self.Gender = gndr
- self.NameSet = nmst
- self.GivenName = gvnnm
- self.Surname = srnm
- self.StreetAddress = strtddrss
- self.ZipCode = zpcd
- self.City = ct
- self.EmailAddress = mladdrss
- self.Username = usrnm
- self.TelephoneNumber = tlphnnmbr
- def __str__(self):
- return self.Number + "," + self.Gender + ","+self.NameSet + "," + self.GivenName + ","+self.Surname + "," + self.StreetAddress + ","+self.ZipCode + "," + self.City + ","+self.EmailAddress + "," + self.Username + ","+self.TelephoneNumber
- class Customer(Person):
- # Check: why do we need this static member? # Check: why static method? Why is this a static member!!11!!!1! (change it)
- def __init__(self, nmbr, gndr, nmst, gvnnm, srnm, strtddrss, zpcd, ct, mladdrss, usrnm, tlphnnmbr, cstmrID):
- super().__init__(nmbr, gndr, nmst, gvnnm, srnm, strtddrss, zpcd, ct, mladdrss, usrnm, tlphnnmbr)
- self.CostomerID = cstmrID
- def __str__(self):
- return 'id = '+ str(self.CostomerID)+':'+super().__str__()
- def store(self):
- AddCstmr = json.dumps(self.__dict__, indent = 3)
- Fo = open(r'PeopleAsCustomer.json', 'a')
- Fo.write(AddCstmr)
- Fo.close()
- class Address:
- def __init__(self, cnt , cty , pcode, str , num):
- self.country = cnt
- self. city = cty
- self.postcode = pcode
- self.street = str
- self.number = num
- def __str__(self):
- sep = ' - '
- return '[ Address :'+self.country+sep+self.city+sep+self.postcode+sep+self.street+sep+self.number+' ] '
- if __name__ == '__main__':
- #x = Customer("1", "male", "ijiji", "aef", "aeauhjhkhfaef", "hyjfygfgjghjg", "2rawefd", "eafedffae", "eadfae", "aedf", "adefad","2")
- #z = Customer.store(x)
- r = Library("author")
- y = Library.CountBooks(r)
- print(y)
- # h = JSONHandler('booksset1.json')
- #userManager = UserManager(h)
- #userManager.loadUsers()
- #usersInfo = userManager.getUsers()
- #for u in usersInfo:
- # print(u)
- #ad1 = Address('The Netherlands','Rotterdam','2323AX','Zwartehondstraat','24a')
- #for u in usersInfo: # here we add address to each user
- # u.address = ad1
- #userManager.storeUsers('usersWithAddresses.json','')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement