utils.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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