Skip to content

Instantly share code, notes, and snippets.

@NP-chaonay
Last active December 30, 2022 17:13
Show Gist options
  • Save NP-chaonay/48649bb207a2ce58f8c4f808eb16d4db to your computer and use it in GitHub Desktop.
Save NP-chaonay/48649bb207a2ce58f8c4f808eb16d4db to your computer and use it in GitHub Desktop.
New Year Countdown But On Python
# WARNING: beware when using relative path, pls check working directory too.
# REMARK: pls see all comments, and in near actual NY event, run this script before time that "Countdown Final Alert" is occured (23:45 of NY Eve).
import subprocess as sp
import datetime,time
# Path to song
main_song_path='./Music/Edited/Events/NewYear2023/'
# Timestamp for "Countdown Final Alert" which alert before NY. 15minutes
FCAts=datetime.datetime(
datetime.datetime.today().year,
12,
31,
23,
45,
).timestamp()
# Timestamp for NY 0:0 o'clock
NYCts=datetime.datetime(
datetime.datetime.today().year+1,
1,
1,
0,
0,
).timestamp()
## This is for debugging/testing only
# What debug code done is to simulate that every passing of each hour is the passing through 00:00 of New Year Day
# to enable/disable debug set this variable (enabled by default for you to test it first, this debugging is not meant for actual usage, after successful debug and everything ok, then set it False)
DEBUG=True
while DEBUG:
FCAts=datetime.datetime(
datetime.datetime.today().year,
datetime.datetime.today().month,
datetime.datetime.today().day,
datetime.datetime.today().hour,
45,
).timestamp()
NYCts=FCAts+60*15
break
## [End section]
# This function is for waiting for timestamp is passed, I no worry about battery usage
def TimeWait(timestamp):
while True:
tmp1=timestamp-time.time()
if tmp1<=0: return
else:
time.sleep(min(60,tmp1))
# This is helper function for play the song (at the main_song_path)
# you have to set path to application (I using mpv btw, you can adapt the entire code to your application) too
def PlaySong(songname):
# path to app, for mpv on Windows, set to mpv.com
apppath="./Applications/mpv-x86_64-v3-20221204-git-4574dd5\mpv.com"
# mpv on Windows? set to mpv.com; MPV on non-Windows? set to mpv, for other app, set to the appropriate name
appname="mpv.com"
return sp.Popen([appname,main_song_path+songname], executable=apppath, stdin=sp.DEVNULL, stdout=sp.DEVNULL, stderr=sp.DEVNULL, shell=False, cwd=None, env=None)
## Main operation
# no loop btw
while True:
TimeWait(FCAts)
# add delay for some feeling/speech/celebration/momentum/event/atmosphere
time.sleep(5)
# Play localized New Year song (In Thai, made by Thai, and optmized for (traditional) Thai culture)
proc=PlaySong('NY.flac')
TimeWait(NYCts)
# add delay for some feeling/speech/celebration/momentum/event/atmosphere
time.sleep(15)
# Play Auld Lang Syne, the global NY song played on exact time of NY and many events
proc=PlaySong('ALS.flac')
proc.wait()
# Don't missed this one, it is really good, it is Rickroll (TBH I using Thai version of rickroll, it is literal translation, and it sounds (not just translated word) very fun.)
proc=PlaySong('RR.flac')
proc.wait()
break
## [End section]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment