Last active
August 7, 2023 17:51
-
-
Save fellipec/90b6c0da017b8ed22f0f8db08d17aeb8 to your computer and use it in GitHub Desktop.
A Clock that use gpsd to read the time from GPS Satellites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import gpsd | |
import datetime | |
import os | |
from time import sleep | |
from pyfiglet import Figlet | |
#Figlet needs the terminal width to proper center the text | |
col = os.get_terminal_size().columns | |
#The clock usually is a larger font than the other text | |
f_clock = Figlet(font='epic',justify='center',width=col) | |
f_other = Figlet(font='small',justify='center',width=col) | |
s=0 #Number of sats | |
sa=0 #Number of sats before | |
def to_color(string, color): | |
color_code = {'blue': '\033[34m', | |
'yellow': '\033[33m', | |
'green': '\033[32m', | |
'bright_green': '\033[92m', | |
'bold_green': '\033[1;92m', | |
'red': '\033[31m', | |
'invertblue': '\033[44m' | |
} | |
return color_code[color] + str(string) + '\033[0m' | |
print("\033c" , end="") | |
main = True | |
while main: | |
# Connect to the local gpsd | |
gpsd.connect() | |
running = True | |
while running: | |
try: | |
p=gpsd.get_current() | |
t=p.get_time(local_time=True) | |
s=p.sats | |
if s != sa: | |
if s != 0: | |
sa = s | |
print('\n') | |
print(to_color(f_other.renderText(t.strftime("%d:%m:%Y")),'blue')) | |
print(to_color(f_clock.renderText(t.strftime("%H:%M:%S")),'bold_green')) | |
print(to_color(f_other.renderText(str(sa) + ' sats'),'yellow')) | |
sleep(1) | |
print("\033c" , end="") | |
except: | |
print(to_color(f_clock.renderText('Sem GPS'),'red')) | |
sleep(5) | |
print("\033c" , end="") | |
running = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment