Add mentor query
This commit is contained in:
parent
65b79bb3a4
commit
7e94a15a05
101
src/buguser.py
101
src/buguser.py
@ -27,19 +27,11 @@ Best regards,
|
|||||||
|
|
||||||
url = "https://infinity-users.projet-horizon.fr/index.php"
|
url = "https://infinity-users.projet-horizon.fr/index.php"
|
||||||
|
|
||||||
|
@click.group()
|
||||||
|
def main():
|
||||||
|
pass
|
||||||
|
|
||||||
@click.command()
|
def get_data():
|
||||||
@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)
|
|
||||||
|
|
||||||
with requests.session() as s:
|
with requests.session() as s:
|
||||||
response = s.post(url, data={"authpw": "astrorizon"})
|
response = s.post(url, data={"authpw": "astrorizon"})
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
@ -86,37 +78,64 @@ def main(to_bug):
|
|||||||
|
|
||||||
# Print the parsed data
|
# Print the parsed data
|
||||||
mapped_login = {user["login"]: user for user in users_tbl}
|
mapped_login = {user["login"]: user for user in users_tbl}
|
||||||
|
return mapped_login
|
||||||
|
|
||||||
|
@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)
|
||||||
|
|
||||||
# Get the current unix login of the user using python os
|
mapped_login = get_data()
|
||||||
current_login = os.getlogin()
|
|
||||||
|
|
||||||
if not current_login in mapped_login:
|
u = mapped_login[user]
|
||||||
print(f"User {current_login} not found")
|
|
||||||
raise SystemExit(1)
|
|
||||||
|
|
||||||
from_user = mapped_login[current_login]
|
print(u["mentor"])
|
||||||
if not to_bug in mapped_login:
|
print(mapped_login[u["mentor"]]["name"])
|
||||||
print(f"User {to_bug} not found")
|
|
||||||
raise SystemExit(1)
|
|
||||||
|
|
||||||
to_user = mapped_login[to_bug]
|
@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.
|
||||||
|
|
||||||
email_body = email_template.format(
|
Args:
|
||||||
name=to_user["name"], complain_name=from_user["name"]
|
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)
|
||||||
|
|
||||||
# Create a multipart message
|
mapped_login = get_data()
|
||||||
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"))
|
|
||||||
|
|
||||||
|
# Get the current unix login of the user using python os
|
||||||
|
current_login = os.getlogin()
|
||||||
|
|
||||||
text = msg.as_string()
|
if not current_login in mapped_login:
|
||||||
print(textwrap.dedent(f"""
|
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:
|
Here is the draft of the email that is going to be sent:
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
{text}
|
{text}
|
||||||
@ -125,14 +144,14 @@ 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 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:
|
if input("Do you want to send the email? ") != current_login:
|
||||||
print("Email not sent")
|
print("Email not sent")
|
||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
|
|
||||||
print("Sending email...")
|
print("Sending email...")
|
||||||
server = smtplib.SMTP('smtp.iap.fr', 587)
|
server = smtplib.SMTP('smtp.iap.fr', 587)
|
||||||
server.sendmail(from_user["email"], [to_user["email"], from_user["email"]], text)
|
server.sendmail(from_user["email"], [to_user["email"], from_user["email"]], text)
|
||||||
server.quit()
|
server.quit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user