Skip to content

Instantly share code, notes, and snippets.

@hhoover
Created July 28, 2025 15:19
Show Gist options
  • Select an option

  • Save hhoover/c2dd56420fab513f4d9755aec7d9d0a8 to your computer and use it in GitHub Desktop.

Select an option

Save hhoover/c2dd56420fab513f4d9755aec7d9d0a8 to your computer and use it in GitHub Desktop.
output blood glucose number and trend to file
#!/usr/bin/env python3
from pydexcom import Dexcom
class ANSI_Compatible:
END = '\x1b[0m'
# If Foreground is False that means color effect on Background
def Color(ColorNo, Foreground=True): # 0 - 255
FB_G = 38 # Effect on foreground
if Foreground != True:
FB_G = 48 # Effect on background
return '\x1b[' + str(FB_G) + ';5;' + str(ColorNo) + 'm'
dexcom = Dexcom("USERNAME", "PASSWORD")
bg = dexcom.get_current_glucose_reading()
if(bg is not None):
if 80 <= bg.value <= 200:
color = ANSI_Compatible.Color(120)
else:
color = ANSI_Compatible.Color(196)
glucose_number = (color + str(bg.value) + ANSI_Compatible.END)
with open('bg_file.txt', 'w') as f:
f.write('{}{}'.format(glucose_number,bg.trend_arrow))
else:
exit%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment