|
| 1 | +# pylint: disable=missing-module-docstring,missing-function-docstring |
| 2 | + |
| 3 | +from datetime import date, datetime, timedelta |
| 4 | +from asyncio import sleep, run |
| 5 | +from os import system |
| 6 | +from threading import Thread |
| 7 | +from typing import TypedDict |
| 8 | +import math |
| 9 | + |
| 10 | +TimeRemaining = TypedDict( |
| 11 | + "TimeRemaining", |
| 12 | + { |
| 13 | + "days": int, |
| 14 | + "hours": int, |
| 15 | + "minutes": int, |
| 16 | + "seconds": int, |
| 17 | + }, |
| 18 | +) |
| 19 | + |
| 20 | + |
| 21 | +def get_time_remaining(*, _from: date, _to: date) -> TimeRemaining: |
| 22 | + time_remaining: TimeRemaining = {"days": 0, "hours": 0, "minutes": 0, "seconds": 0} |
| 23 | + |
| 24 | + diff_dates: timedelta = _to - _from |
| 25 | + total_seconds: int = diff_dates.seconds |
| 26 | + |
| 27 | + time_remaining["days"] = diff_dates.days |
| 28 | + |
| 29 | + time_remaining["hours"] = math.floor(total_seconds / 3600) |
| 30 | + total_seconds -= time_remaining["hours"] * 3600 |
| 31 | + |
| 32 | + time_remaining["minutes"] = math.floor(total_seconds / 60) |
| 33 | + total_seconds -= time_remaining["minutes"] * 60 |
| 34 | + |
| 35 | + time_remaining["seconds"] = total_seconds |
| 36 | + |
| 37 | + return time_remaining |
| 38 | + |
| 39 | + |
| 40 | +async def main() -> None: |
| 41 | + start_date: date = datetime.now() |
| 42 | + end_date: date = datetime(year=2024, month=11, day=28, hour=0, minute=59, second=0) |
| 43 | + |
| 44 | + remaining_time: TimeRemaining = get_time_remaining(_from=start_date, _to=end_date) |
| 45 | + |
| 46 | + system(command="clear") |
| 47 | + |
| 48 | + print( |
| 49 | + f"> Time remaining for {end_date}: " |
| 50 | + f"[ {remaining_time['days']:{0}6} days | " |
| 51 | + f"{remaining_time['hours']:{0}2} hours | " |
| 52 | + f"{remaining_time['minutes']:{0}2} minutes | " |
| 53 | + f"{remaining_time['seconds']:{0}2} seconds ]." |
| 54 | + ) |
| 55 | + |
| 56 | + while ( |
| 57 | + remaining_time["days"] |
| 58 | + or remaining_time["hours"] |
| 59 | + or remaining_time["minutes"] |
| 60 | + or remaining_time["seconds"] |
| 61 | + ): |
| 62 | + start_date: date = datetime.now() |
| 63 | + |
| 64 | + await sleep(delay=1) |
| 65 | + remaining_time = get_time_remaining(_from=start_date, _to=end_date) |
| 66 | + |
| 67 | + system(command="clear") |
| 68 | + |
| 69 | + print( |
| 70 | + f"> Time remaining for {end_date}: " |
| 71 | + f"[ {remaining_time['days']:{0}6} days | " |
| 72 | + f"{remaining_time['hours']:{0}2} hours | " |
| 73 | + f"{remaining_time['minutes']:{0}2} minutes | " |
| 74 | + f"{remaining_time['seconds']:{0}2} seconds ]." |
| 75 | + ) |
| 76 | + |
| 77 | + print("\n> The day has come!") |
| 78 | + |
| 79 | + |
| 80 | +Thread( |
| 81 | + target=run, |
| 82 | + kwargs={ |
| 83 | + "main": main(), |
| 84 | + }, |
| 85 | +).start() |
0 commit comments