utils.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. def find_username_id(username, file_path="username_id"):
  2. """Find the ID for a given username from the username_id file."""
  3. try:
  4. with open(file_path, "r", encoding="utf-8") as file:
  5. for line in file:
  6. if line.strip():
  7. user, user_id = line.strip().split(":")
  8. if user == username:
  9. return user_id
  10. print(f"Username '{username}' not found.")
  11. return None
  12. except FileNotFoundError:
  13. print(f"File not found: {file_path}")
  14. return None
  15. except Exception as e:
  16. print(f"An error occurred: {e}")
  17. return None
  18. def generate_evoluz_link(username_id, task_id, base_url):
  19. """Generate Evoluz link."""
  20. team_id = f"teamID={username_id}"
  21. update_team_id = f"updateTeamId={task_id}"
  22. return f"{base_url}{team_id}&{update_team_id}"
  23. def find_task_type(branch_name):
  24. """Extract branch type and task ID from branch name."""
  25. try:
  26. parts = branch_name.split("/")
  27. if len(parts) >= 2:
  28. branch_type = parts[0]
  29. task_id = parts[1].split("_")[0]
  30. return {"task_type": branch_type, "task_id": task_id}
  31. else:
  32. print(f"Invalid branch name format: {branch_name}")
  33. return None
  34. except Exception as e:
  35. print(f"Error extracting task type: {e}")
  36. return None
  37. def find_squad(username):
  38. """Find the squad for a given username from the username_squad file."""
  39. file_path = "username_squad"
  40. try:
  41. with open(file_path, "r", encoding="utf-8") as file:
  42. for line in file:
  43. if line.strip():
  44. user, squad = line.strip().split(":")
  45. if user.lower() == username.lower():
  46. return squad.lower()
  47. print(f"Username '{username}' not found in squad file.")
  48. return None
  49. except FileNotFoundError:
  50. print(f"Squad file not found: {file_path}")
  51. return None
  52. except Exception as e:
  53. print(f"An error occurred while finding squad: {e}")
  54. return None