webscraper/scripts/get_path.py
paprykdev 8ca8225122
Some checks are pending
Docker Image CI / build (push) Waiting to run
refactor: clean up get_path function and remove unnecessary print statement
2024-11-15 23:44:59 +01:00

30 lines
821 B
Python

import os
from run_command import run_command
def get_path():
pwd = run_command("pwd")
splitted = pwd.split("/")
splitted[-1] = splitted[-1].replace("\n", "")
if splitted.count("webscraper") > 1 and "webscraper" in splitted:
for i in range(len(splitted) - 1, -1, -1):
potential_path = "/".join(splitted[: i + 1])
if "webscraper" in potential_path:
script_path = f"{potential_path}/scripts"
if os.path.isdir(script_path):
return potential_path
else:
return "This is not a valid webscraper project."
else:
path = "/".join(splitted[: splitted.index("webscraper") + 1])
return path
def run_main():
print(get_path())
if __name__ == "__main__":
run_main()