def listread(l): temp = "" n = 0 for a in unfreeze(l): if n < len(unfreeze(l)) - 1: temp = temp + a + " " else: temp = temp + a n += 1 l = temp return l
def start(self, vectors): # Declare initial facts self.reset(vectors=vectors) fresh_facts = True while self.tasks or fresh_facts: self.run() fresh_facts = False try: # Run all tasks and gather results for task in self.tasks: for lineage in task: info = Info.from_lineage(lineage) self.declare(info) fresh_facts = True except KeyboardInterrupt: # The user aborted the task break self.tasks = list() # Print a dirty report for fact in self.facts.values(): if isinstance(fact, Info): yield unfreeze(fact.as_dict())
def print_date(self, date): if date == "": print("NO DATE") return if type(unfreeze(date)) is list: d = datetime.date(datetime.now()) if date[2] == "" and date[1] == "": if int(date[0]) < d.day: date = date[0] + " " + str(d.month + 1) + " " + str(d.year) else: date = date[0] + " " + str(d.month) + " " + str(d.year) elif date[2] == "" and date[1] != "": if int(date[1]) < d.month: date = date[0] + " " + date[1] + " " + str(d.year + 1) elif int(date[1]) == d.month: if int(date[0]) < d.day: date = date[0] + " " + date[1] + " " + str(d.year + 1) else: date = date[0] + " " + date[1] + " " + str(d.year) else: date = listread(date) date = datetime.strptime(date, '%d %m %Y') date = datetime.date(date) #date = datetime.date(date) if date > datetime.date(datetime.now()): updatefacts(2, str(date)) updatefacts(5, "What time?") elif date == datetime.date(datetime.now()): updatevar(1, str(date)) updatevar(0, "True")
def print_astation(self, astation): if type(unfreeze(astation)) is list: astation = listread(astation) if astation in name: i = name.index(astation) print(astation + "'s code is " + code[i]) updatefacts(1, astation) updatefacts(5, "Where are you leaving from?") else: print("Could not find " + astation)
def print_when(self, when): if type(unfreeze(when)) is list: when = listread(when) if when == "Arrival" or when == "Arrive": updatefacts(4, "arr") updatefacts( 5, "Okay thanks! Please hold on while we process your request") elif when == "Departure" or when == "Depart": updatefacts(4, "dep") updatefacts( 5, "Okay thanks! Please hold on while we process your request") print(when)
def print_time(self, time): if time == "": print("no time") return if type(unfreeze(time)) is list: time = listread(time) time = datetime.strptime(time, '%H%M') time = datetime.time(time) if var[0] == "True,": if time > datetime.time(datetime.now()): updatefacts(2, var[1]) updatefacts( 5, "Would you like to arrive or depart at this time?") #print(date) else: print("You must pick a time in the future") updatefacts(3, str(time)) updatefacts(5, "Would you like to arrive or depart at this time?") print(time)
def print_dstation(self, dstation): if type(unfreeze(dstation)) is list: dstation = listread(dstation) if dstation == "": print("empty") elif dstation == "reset": updatefacts(0, "null") updatefacts(1, "null") updatefacts(2, "null") updatefacts(3, "null") updatefacts(4, "null") updatefacts( 5, "Sorry! I didnt quite catch that. Can you say that again?") if dstation in name: i = name.index(dstation) print(dstation + "'s code is " + code[i]) updatefacts(0, dstation) updatefacts(5, "What date would you like to go?") var[2] = "True" else: print("Could not find " + dstation)
def as_dict(self): """Return a dictionary containing this `Fact` data.""" return {k: unfreeze(v) for k, v in self.items() if not self.is_special(k)}
def validate(self, data): self.validator.validate(unfreeze(data))
def test_unfreeze_frozenset(): actual = unfreeze(frozenset({1, 2, 3})) expected = {1, 2, 3} assert actual == expected assert isinstance(actual, type(expected))
def test_unfreeze_frozenlist(): actual = unfreeze(frozenlist([1, 2, 3])) expected = [1, 2, 3] assert actual == expected assert isinstance(actual, type(expected))
def test_unfreeze_frozendict(): actual = unfreeze(frozendict({"a": 1, "b": 2})) expected = {"a": 1, "b": 2} assert actual == expected assert isinstance(actual, type(expected))
def launch_task(self, task): runner = plugin_runner(task["command"]) lineage = unfreeze(task["lineages"]) stdin = unfreeze(task["stdin"]) self.tasks.append(runner(lineage, stdin))