Возможно ли преобразовать это приложение Python CLI в приложение Django?
Я создал приложение на языке python, которое принимает от пользователя данные о часах и минутах, а затем выводит на экран уведомление, когда система достигает времени, равного суммарному количеству часов и минут.
Я хотел бы превратить это в веб-приложение с помощью Django, возможно ли это?
import time
import os
from threading import Thread
def userTimeSet():
while True:
try:
hours = int(input("Number of hours? "))
minutes = int(input("\nNumber of minutes? "))
if hours > 0 and minutes > 0:
interval_sec = (hours*3600)+(minutes*60)
print(f"hours and minutes to seconds checking: {interval_sec}")
elif hours > 0 and minutes == 0:
interval_sec = (hours*3600)
print(f"hours to seconds checking: {interval_sec}")
elif hours == 0 and minutes > 0:
interval_sec = (minutes*60)
print(f"minutes to seconds checking: {interval_sec}")
else: print("invalid.")
futureTime = timeConfirmation(hours, minutes)
# create and start the daemon thread
print('Starting background task...')
daemon = Thread(target=timeCheck, args=(futureTime, interval_sec,), daemon=True, name='Background')
daemon.start()
print('Main thread is carrying on...')
time.sleep(interval_sec)
print('Main thread done running.')
break
except ValueError:
print("Enter a number.")
def timeConfirmation(hours, minutes):
print(f"{hours}:{minutes} (hours:minutes)")
currentDateTime = time.ctime()
print(f"\n Current Date and Time: {currentDateTime}")
timeInSeconds = (hours * 3600) + (minutes * 60)
futureTime = time.time() + timeInSeconds
print(f"\n Timer Ends at: {time.ctime(futureTime)}")
return futureTime
def timeCheck(futureTime, interval_sec):
while True:
time.sleep(interval_sec)
currentTime = time.time()
if time.ctime(currentTime) == time.ctime(futureTime):
alarmNotification()
print(f"Checking time. {time.ctime(currentTime)}")
def alarmNotification():
os.system("""
osascript -e 'display notification "{}" with title "{}" sound name "{}"'
""".format(f"Current time is: {time.ctime()}", "Its Break Time Boi", "Boop"))
userTimeSet()