Nov-08-2020, 01:26 AM
so the problem i am having is that im trying to get my text from a main .py file and with txt being at the end of this line here t = threading.Thread(target=reminder(txt))
it does not work properly it should just be target = reminder with that it works fine only if i get my text from this file basically what im asking is how can i get text = input(cmd: ) from my main file with out having circular import issues and get the threading working properly also so in short i need to avoid having the txt argument in the reminder function but still being able to pass the text from my main.py file through the function so it knows what it is looking for
it does not work properly it should just be target = reminder with that it works fine only if i get my text from this file basically what im asking is how can i get text = input(cmd: ) from my main file with out having circular import issues and get the threading working properly also so in short i need to avoid having the txt argument in the reminder function but still being able to pass the text from my main.py file through the function so it knows what it is looking for
import time import datetime import re import threading def find_time_in_text(txt): pattern = r"(\d+)(?::(\d+))?\s*([ap]\.m\.)" m = re.search(pattern, txt) if m: hour, minute, am_pm = m.groups() time_ = f"{hour}:{minute or 0} {am_pm}" return time_ else: print("Couldn't find a time in the right format") def reminder(txt): if "a.m." in txt or "p.m." in txt: get_time = find_time_in_text(txt) # Getting the time time_to_list = get_time.split() # this splits time to a list time_to_split = time_to_list[0] # This gets hour and minute split_time_ = time_to_split.split(":") # This splits hour and minutes hour = split_time_[0] minute = split_time_[1] am_pm_ = time_to_list[1] alarm_hour = int(hour) alarm_minutes = int(minute) am_pm = str(am_pm_) print(f"A reminder is set for: {alarm_hour}:{alarm_minutes} {am_pm}") if am_pm == 'p.m.': alarm_hour += 12 elif alarm_hour == 12 and am_pm == 'a.m.': alarm_hour -= 12 else: pass while True: if alarm_hour == datetime.datetime.now().hour and alarm_minutes == datetime.datetime.now().minute: print("\nIt's the time!") print("alarm") break if "minute" in txt or "minutes" in txt: for s in txt.split(): if s.isdigit(): number = int(s) reminder2 = number * 60 print(f"A reminder is set for {number} minutes from now.") time.sleep(reminder2) print("reminder!") return elif "second" in txt or "seconds" in txt: for s in txt.split(): if s.isdigit(): number = int(s) reminder2 = number print(f"A reminder is set for {number} seconds from now.") time.sleep(reminder2) print("reminder!") return else: return def thred(txt): threads = [] for _ in range(1): t = threading.Thread(target=reminder(txt)) t.start() threads.append(t) for thread in threads: thread.join(0)