Skip to content

Instantly share code, notes, and snippets.

@dkeza
Last active November 25, 2021 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkeza/9d24e3ba392e0fb5ba9016e513ebd890 to your computer and use it in GitHub Desktop.
Save dkeza/9d24e3ba392e0fb5ba9016e513ebd890 to your computer and use it in GitHub Desktop.
Fix wrong date time on Raspberry Pi 3 in LibreELEC (Krypton) v8.0.1 MR (Kodi), when connected over WiFi
#!/usr/bin/env python
## Python 2.7 script
## Use it as workaround for Kodi LibreELEC wrong date time bug, when used on Raspberry Pi 3 over WiFi.
## Log in into LibreELEC over SSH, create this script as executable,
##
## $ nano fixtime.py
## $ chmod +x fixtime.py
##
## and call it from autostart.sh
##
## $ nano /storage/.config/autostart.sh
##
## Add delay 10 sec in autostart.sh:
##
## (sleep 10;
## /storage/./fixtime.py
## ) &
import urllib2
import sys
import subprocess
from datetime import datetime, timedelta
## Returns date (GMT) from Google HTTP response header in this format
## (2017, 5, 25, 9, 40, 23, 0, 1, 0)
d = urllib2.urlopen('http://www.google.com/').info().getdate('Date')
## Create python datetime type
dp = datetime(d[0], d[1], d[2], d[3], d[4], d[5], d[6])
## Add 2 hours for CET time zone
df = dp + timedelta(hours=2)
## Create tuple, to get datetime parts
t = df.timetuple()
## Convert to format needed for date command in terminal window on BusyBox in LibreELEC
## [YYYY.]MM.DD-hh:mm[:ss]
s = str(t.tm_year) + '.' + str(t.tm_mon).zfill(2) + '.' + str(t.tm_mday).zfill(2) + '-' +str(t.tm_hour).zfill(2) +':'+str(t.tm_min).zfill(2) + ':' + str(t.tm_sec).zfill(2)
## Print it in terminal window for visual check
print s
## Call OS date command with our new date
subprocess.check_output(['date', '--set', s])
sys.exit(0)
@cpassuel
Copy link

You saved my day, this bug was driving me crazy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment