Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. import json
  2. from abc import ABC, abstractmethod
  3.  
  4. class Handler: # Check: how to decide which methods should be abstract?
  5. def __init__(self):
  6. self.content = None
  7. @abstractmethod
  8. def read(self):
  9. pass
  10. @abstractmethod
  11. def store(self,es,fname,path):
  12. pass
  13. def getContent(self): # Check: why this is not abstract?
  14. return self.content
  15.  
  16. class JSONHandler(Handler):
  17. def __init__(self, filename, path=''):
  18. super().__init__() # Check: why do we call parent's initializer?
  19. self.jsonFile = path+filename # Check: specialization - behaviour/property that the child adds to the parent
  20.  
  21.  
  22. def read(self): # Check: why do we provide implementation here?
  23. fo = open(self.jsonFile,'r')
  24. c = fo.read()
  25. self.content = json.loads(c) # Check: deserialize json content
  26. fo.close()
  27.  
  28. def store(self,es,fname,path):
  29. addad = Address('The Netherlands', 'Rotterdam', '2323AX', 'Zwartehondstraat', '24a')
  30. adic = json.dumps(addad.__dict__, indent=3)
  31. fo = open(r'booksset1.json', 'a')
  32. fo.write(adic)
  33. fo.close()
  34.  
  35.  
  36. class Library:
  37. def __init__(self, srchwrd):
  38. self.Name = "Library of Rotterdam"
  39. self.searchword = srchwrd
  40. def CountBooks(self):
  41. bo = open("booksset1.json", 'r')
  42. bo2 = bo.read()
  43. data = json.loads(bo2)
  44. for u in data:
  45. print('Name: ' + u[self.searchword])
  46.  
  47. bo.close()
  48.  
  49.  
  50.  
  51. class Person:
  52. def __init__(self, nmbr, gndr, nmst, gvnnm, srnm, strtddrss, zpcd, ct, mladdrss, usrnm, tlphnnmbr):
  53. self.Number = nmbr
  54. self.Gender = gndr
  55. self.NameSet = nmst
  56. self.GivenName = gvnnm
  57. self.Surname = srnm
  58. self.StreetAddress = strtddrss
  59. self.ZipCode = zpcd
  60. self.City = ct
  61. self.EmailAddress = mladdrss
  62. self.Username = usrnm
  63. self.TelephoneNumber = tlphnnmbr
  64. def __str__(self):
  65. return self.Number + "," + self.Gender + ","+self.NameSet + "," + self.GivenName + ","+self.Surname + "," + self.StreetAddress + ","+self.ZipCode + "," + self.City + ","+self.EmailAddress + "," + self.Username + ","+self.TelephoneNumber
  66.  
  67. class Customer(Person):
  68. # Check: why do we need this static member? # Check: why static method? Why is this a static member!!11!!!1! (change it)
  69. def __init__(self, nmbr, gndr, nmst, gvnnm, srnm, strtddrss, zpcd, ct, mladdrss, usrnm, tlphnnmbr, cstmrID):
  70. super().__init__(nmbr, gndr, nmst, gvnnm, srnm, strtddrss, zpcd, ct, mladdrss, usrnm, tlphnnmbr)
  71. self.CostomerID = cstmrID
  72. def __str__(self):
  73. return 'id = '+ str(self.CostomerID)+':'+super().__str__()
  74. def store(self):
  75. AddCstmr = json.dumps(self.__dict__, indent = 3)
  76. Fo = open(r'PeopleAsCustomer.json', 'a')
  77. Fo.write(AddCstmr)
  78. Fo.close()
  79.  
  80.  
  81. class Address:
  82. def __init__(self, cnt , cty , pcode, str , num):
  83. self.country = cnt
  84. self. city = cty
  85. self.postcode = pcode
  86. self.street = str
  87. self.number = num
  88. def __str__(self):
  89. sep = ' - '
  90. return '[ Address :'+self.country+sep+self.city+sep+self.postcode+sep+self.street+sep+self.number+' ] '
  91.  
  92. if __name__ == '__main__':
  93. #x = Customer("1", "male", "ijiji", "aef", "aeauhjhkhfaef", "hyjfygfgjghjg", "2rawefd", "eafedffae", "eadfae", "aedf", "adefad","2")
  94. #z = Customer.store(x)
  95.  
  96. r = Library("author")
  97. y = Library.CountBooks(r)
  98. print(y)
  99.  
  100. # h = JSONHandler('booksset1.json')
  101. #userManager = UserManager(h)
  102. #userManager.loadUsers()
  103. #usersInfo = userManager.getUsers()
  104. #for u in usersInfo:
  105. # print(u)
  106. #ad1 = Address('The Netherlands','Rotterdam','2323AX','Zwartehondstraat','24a')
  107. #for u in usersInfo: # here we add address to each user
  108. # u.address = ad1
  109. #userManager.storeUsers('usersWithAddresses.json','')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement