Add mentor query
This commit is contained in:
parent
65b79bb3a4
commit
7e94a15a05
109
src/buguser.py
109
src/buguser.py
@ -27,19 +27,11 @@ Best regards,
|
||||
|
||||
url = "https://infinity-users.projet-horizon.fr/index.php"
|
||||
|
||||
@click.group()
|
||||
def main():
|
||||
pass
|
||||
|
||||
@click.command()
|
||||
@click.argument("to_bug")# help="The login of the user to bug")
|
||||
def main(to_bug):
|
||||
"""Bug a user on the Infinity platform.
|
||||
|
||||
Args:
|
||||
to_bug (str): The login of the user to bug.
|
||||
"""
|
||||
if to_bug is None:
|
||||
print("Please provide the login of the user to bug")
|
||||
raise SystemExit(1)
|
||||
|
||||
def get_data():
|
||||
with requests.session() as s:
|
||||
response = s.post(url, data={"authpw": "astrorizon"})
|
||||
if response.status_code != 200:
|
||||
@ -86,37 +78,64 @@ def main(to_bug):
|
||||
|
||||
# Print the parsed data
|
||||
mapped_login = {user["login"]: user for user in users_tbl}
|
||||
|
||||
return mapped_login
|
||||
|
||||
# Get the current unix login of the user using python os
|
||||
current_login = os.getlogin()
|
||||
@main.command()
|
||||
@click.argument("user")
|
||||
def sponsor(user):
|
||||
if user is None:
|
||||
print("Please provide the login of the user to bug")
|
||||
raise SystemExit(1)
|
||||
|
||||
if not current_login in mapped_login:
|
||||
print(f"User {current_login} not found")
|
||||
raise SystemExit(1)
|
||||
|
||||
from_user = mapped_login[current_login]
|
||||
if not to_bug in mapped_login:
|
||||
print(f"User {to_bug} not found")
|
||||
raise SystemExit(1)
|
||||
|
||||
to_user = mapped_login[to_bug]
|
||||
mapped_login = get_data()
|
||||
|
||||
u = mapped_login[user]
|
||||
|
||||
email_body = email_template.format(
|
||||
name=to_user["name"], complain_name=from_user["name"]
|
||||
)
|
||||
print(u["mentor"])
|
||||
print(mapped_login[u["mentor"]]["name"])
|
||||
|
||||
# Create a multipart message
|
||||
msg = MIMEMultipart()
|
||||
msg["From"] = from_user["email"]
|
||||
msg["To"] = to_user["email"]
|
||||
msg["CC"] = from_user["email"]
|
||||
msg["Subject"] = "Your usage of Infinity nodes"
|
||||
msg.attach(MIMEText(email_body, "plain"))
|
||||
@main.command()
|
||||
@click.argument("to_bug")# help="The login of the user to bug")
|
||||
def go(to_bug):
|
||||
"""Bug a user on the Infinity platform.
|
||||
|
||||
Args:
|
||||
to_bug (str): The login of the user to bug.
|
||||
"""
|
||||
if to_bug is None:
|
||||
print("Please provide the login of the user to bug")
|
||||
raise SystemExit(1)
|
||||
|
||||
mapped_login = get_data()
|
||||
|
||||
# Get the current unix login of the user using python os
|
||||
current_login = os.getlogin()
|
||||
|
||||
text = msg.as_string()
|
||||
print(textwrap.dedent(f"""
|
||||
if not current_login in mapped_login:
|
||||
print(f"User {current_login} not found")
|
||||
raise SystemExit(1)
|
||||
|
||||
from_user = mapped_login[current_login]
|
||||
if not to_bug in mapped_login:
|
||||
print(f"User {to_bug} not found")
|
||||
raise SystemExit(1)
|
||||
|
||||
to_user = mapped_login[to_bug]
|
||||
|
||||
email_body = email_template.format(
|
||||
name=to_user["name"], complain_name=from_user["name"]
|
||||
)
|
||||
|
||||
# Create a multipart message
|
||||
msg = MIMEMultipart()
|
||||
msg["From"] = from_user["email"]
|
||||
msg["To"] = to_user["email"]
|
||||
msg["CC"] = from_user["email"]
|
||||
msg["Subject"] = "Your usage of Infinity nodes"
|
||||
msg.attach(MIMEText(email_body, "plain"))
|
||||
|
||||
text = msg.as_string()
|
||||
print(textwrap.dedent(f"""
|
||||
Here is the draft of the email that is going to be sent:
|
||||
-----------------------------------------------------
|
||||
{text}
|
||||
@ -124,15 +143,15 @@ Here is the draft of the email that is going to be sent:
|
||||
|
||||
If you agree with it, please enter your login name to confirm the sending of the email.
|
||||
"""))
|
||||
|
||||
if input("Do you want to send the email? ") != current_login:
|
||||
print("Email not sent")
|
||||
raise SystemExit(0)
|
||||
|
||||
print("Sending email...")
|
||||
server = smtplib.SMTP('smtp.iap.fr', 587)
|
||||
server.sendmail(from_user["email"], [to_user["email"], from_user["email"]], text)
|
||||
server.quit()
|
||||
if input("Do you want to send the email? ") != current_login:
|
||||
print("Email not sent")
|
||||
raise SystemExit(0)
|
||||
|
||||
print("Sending email...")
|
||||
server = smtplib.SMTP('smtp.iap.fr', 587)
|
||||
server.sendmail(from_user["email"], [to_user["email"], from_user["email"]], text)
|
||||
server.quit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user