38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
|
class Users:
|
||
|
def parse(self, xml, userid):
|
||
|
self.userid = userid
|
||
|
self.login = xml.get("login")
|
||
|
self.realname = xml.find("login").get("realname")
|
||
|
self.email = xml.find("login").get("email")
|
||
|
|
||
|
return self
|
||
|
|
||
|
def __str__(self):
|
||
|
return f"User {self.userid} {self.login}: {self.realname} {self.email}"
|
||
|
|
||
|
def __repr__(self):
|
||
|
return f"[{self.__str__()}]"
|
||
|
|
||
|
def import_into_db(self, db):
|
||
|
cur = db.cursor()
|
||
|
cur.execute(
|
||
|
"""INSERT INTO users (userid, login, realname, email)
|
||
|
VALUES (%s,%s,%s,%s) RETURNING id""",
|
||
|
(
|
||
|
self.userid,
|
||
|
self.login,
|
||
|
self.realname,
|
||
|
self.email,
|
||
|
),
|
||
|
)
|
||
|
cur.close()
|
||
|
|
||
|
def user_lookup(self, db, userid):
|
||
|
cur= db.cursor()
|
||
|
cur.execute("SELECT * FROM users where userid=%s", (userid,))
|
||
|
row = cur.fetchone()
|
||
|
if not row:
|
||
|
cur.close()
|
||
|
return None
|
||
|
return row
|
||
|
|