The objective of this interface is the ability to get data from an Admidio installation and use them in python. Currently Users, groups and events are integrated
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. import pprint
  2. import hashlib
  3. class Member():
  4. """Member class for admidio, here all member data will be stored."""
  5. def __init__(self, db, user_id, username, password, userfields, admidio):
  6. self.__c = db.cursor()
  7. self.user_id = user_id
  8. self.username = username
  9. self.password = password
  10. self.userdata = dict()
  11. self.admidio = admidio
  12. sql = f"""SELECT usd_usf_id, usd_value
  13. FROM {self.admidio.prefix}_user_data
  14. WHERE usd_usr_id = {self.user_id!s}"""
  15. self.__c.execute(sql)
  16. for row in self.__c.fetchall():
  17. # makes dict with {usf_name_intern:usd_value}
  18. self.userdata[userfields[row[0]]] = row[1]
  19. def __eq__(self, other):
  20. if isinstance(other, Member):
  21. return self.hash() == other.hash()
  22. def hash(self):
  23. if self.password:
  24. return hashlib.md5((str(self.user_id)
  25. + self.username
  26. + self.password
  27. + str(self.userdata)
  28. ).encode('utf-8')).hexdigest()
  29. else:
  30. return hashlib.md5((str(self.user_id)
  31. + self.username
  32. + str(self.userdata)
  33. ).encode('utf-8')).hexdigest()
  34. def __str__(self):
  35. return (f"""Userid: {self.user_id}, Username: {self.username}, """
  36. f"""Userdata: {pprint.pformat(self.userdata)}""")
  37. """@property
  38. def email(self):
  39. return self.userdata['EMAIL']
  40. @property
  41. def firstName(self):
  42. return self.userdata['FIRST_NAME']
  43. @property
  44. def lastName(self):
  45. return self.userdata['LAST_NAME']
  46. @property
  47. def username(self):
  48. self.username
  49. @property
  50. def password(self):
  51. return self.password"""