-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
37 lines (28 loc) · 1.01 KB
/
common.py
File metadata and controls
37 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import csv
from pathlib import Path
def import_users_by_email(file: str) -> list[str]:
emails = []
if Path(f"{ file }").is_file():
with open(file) as input:
rows = csv.DictReader(input)
for row in rows:
emails.append(row["email"])
else:
exit("Error: Input file doesn't exist")
return emails
class User:
email: str
username: str
password: str
def __init__(self, email: str) -> None:
self.email = email
self.username = self.generate_username(email)
self.password = self.generate_password(self.username)
@staticmethod
def generate_username(email: str) -> str:
# ab2-username@domain.ac.uk -> ab2username
return email.split("@")[0].lower().replace("-", "").replace(".", "")
@staticmethod
def generate_password(username: str) -> str:
# ab2username -> Ab2usernamE11+$++
return f"{ username[0].upper() }{ username[1:-1].lower() }{ username[-1].upper() }{ len(username) }+$++"