diff --git a/.gitignore b/.gitignore index 64b2173..97fa546 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ *.pyc .env .venv +*.DS_Store +.vscode +config.txt diff --git a/whereis.py b/whereis.py index b9fca16..a2d0434 100644 --- a/whereis.py +++ b/whereis.py @@ -21,6 +21,8 @@ COLORED = 1 UNCOLORED = 0 +config_location = "/home/pi/.whereabouts/config.txt" + try: import requests except ImportError: @@ -41,57 +43,70 @@ def get_location( user_number, auth_token ): def load_config(): lines = [] - with open( "/home/pi/rpi-whereis-0.1/config.txt" ) as f: + with open( config_location ) as f: lines = f.read().splitlines() return { "caption" : lines[0], "user_number" : lines[1], "auth_token" : lines[2], - "old_ds" : lines[3] -} - + "old_ds" : lines[3], + } def save_config(ds): - with open( "/home/pi/rpi-whereis-0.1/config.txt", 'r' ) as f: + lines = [] + with open( config_location, 'r' ) as f: lines = f.readlines() + lines[3] = ds+"\n" - with open("/home/pi/rpi-whereis-0.1/config.txt", 'w') as f: - f.writelines(lines) + + with open( config_location, 'w') as f: + f.writelines(lines) def main(): config = load_config() - + + print(config) + epd = epd2in13b.EPD() epd.init() epd.set_rotate(1) - + # clear the frame buffer frame_black = [0xFF] * (epd.width * epd.height / 8) frame_red = [0xFF] * (epd.width * epd.height / 8) - - epd.draw_filled_rectangle(frame_red, 0, 0, 250, 55, COLORED); - - font = ImageFont.truetype('/usr/share/fonts/AmaticSC-Bold.ttf', 38) - epd.draw_string_at(frame_red, 25, 10, config["caption"], font, UNCOLORED) - + + epd.draw_filled_rectangle(frame_black, 0, 0, 250, 40, COLORED); + + font = ImageFont.truetype('/usr/share/fonts/marvinVisions.otf', 28) + epd.draw_string_at(frame_black, 12, 6, config["caption"], font, UNCOLORED) + data = get_location( config["user_number"], config["auth_token"] ) - ds = "unknown" + # Add this to config to make it customisable + ds = "MCUK (Probably)" print(data) - + if(u'description' in data): print(data["description"]) ds = data["description"] - - epd.draw_string_at(frame_black, 25, 60, ds, font, COLORED) - + + print(type(ds)) + print(type(config["caption"])) + print(len(ds)) + print(len(config["caption"])) + + if(len(ds) > len(config["caption"])): + font1 = ImageFont.truetype('/usr/share/fonts/marvinVisions.otf', 20) + epd.draw_string_at(frame_black, 12, 45, ds, font1, COLORED) + else: + epd.draw_string_at(frame_black, 12, 45, ds, font, COLORED) + if (config["old_ds"] != ds): - epd.display_frame(frame_black, frame_red) - + epd.display_frame(frame_black, frame_red) + save_config(ds) if __name__ == '__main__': - main() - + main() \ No newline at end of file