git-importer/lib/users.py

36 lines
933 B
Python
Raw Normal View History

2022-10-21 15:16:34 +02:00
class Users:
def parse(self, xml, userid):
self.userid = userid
2022-10-24 18:12:44 +02:00
self.realname = xml.find("realname").text
self.email = xml.find("email").text
2022-10-21 15:16:34 +02:00
return self
def __str__(self):
2022-10-24 18:12:44 +02:00
return f"User {self.userid}: {self.realname} {self.email}"
2022-10-21 15:16:34 +02:00
def __repr__(self):
return f"[{self.__str__()}]"
def import_into_db(self, db):
cur = db.cursor()
cur.execute(
2022-10-24 18:12:44 +02:00
"""INSERT INTO users (userid, realname, email)
VALUES (%s,%s,%s) RETURNING id""",
2022-10-21 15:16:34 +02:00
(
self.userid,
self.realname,
self.email,
),
)
cur.close()
2022-10-24 18:12:44 +02:00
def user_lookup(db, userid):
2022-10-21 15:16:34 +02:00
cur= db.cursor()
cur.execute("SELECT * FROM users where userid=%s", (userid,))
row = cur.fetchone()
if not row:
cur.close()
return None
return row