LoLARunner.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import subprocess
  2. import json
  3. class LoLARunner:
  4. def __init__(self):
  5. self.places = None
  6. # load the place names
  7. def load_places(self, places):
  8. places = places.replace(";", "").split(",")
  9. self.places = [p.strip() for p in places]
  10. def run_lola(self, filename):
  11. # loop through each place
  12. for p in self.places:
  13. #change this command as needed
  14. # place arguments as entries in the list
  15. cmd = ['lola', '--quiet', '--check=none', filename]
  16. # for debugging
  17. # print("Running cmd: " + str(cmd))
  18. # run the command
  19. subprocess.run(" ".join(cmd), shell=True)
  20. # open the JSON file and check the result
  21. with open("output.json") as f:
  22. j = json.load(f)
  23. result = j['analysis']['result']
  24. print("Result for " + p + ": " + str(result))
  25. if __name__ == "__main__":
  26. # CHANGE THESE VARIABLES FOR YOUR SOLUTION
  27. # YOU CAN COPY THE PLACE NAMES FROM THE LOLA FILE
  28. places = """PLACE_ONE,
  29. PLACE_TWO,
  30. PLACE_THREE"""
  31. filename = "solution.lola"
  32. lr = LoLARunner()
  33. lr.load_places(places)
  34. lr.run_lola(filename)