diff --git a/inkycal/modules/inkycal_server.py b/inkycal/modules/inkycal_server.py index 0fbccaa..fa17e11 100644 --- a/inkycal/modules/inkycal_server.py +++ b/inkycal/modules/inkycal_server.py @@ -6,36 +6,73 @@ For use with Robert Sierre's inkycal web-service Copyright by aceisace """ - -from os import path -from PIL import ImageOps +from inkycal.modules.template import inkycal_module +from inkycal.custom import * import requests -import numpy - -"""----------------------------------------------------------------""" -#path = 'https://github.com/aceisace/Inky-Calendar/raw/master/Gallery/Inky-Calendar-logo.png' -#path ='/home/pi/Inky-Calendar/images/canvas.png' -path = inkycal_image_path -path_body = inkycal_image_path_body -mode = 'auto' # 'horizontal' # 'vertical' # 'auto' -upside_down = False # Flip image by 180 deg (upside-down) -alignment = 'center' # top_center, top_left, center_left, bottom_right etc. -colours = 'bwr' # bwr # bwy # bw -render = True # show image on E-Paper? -"""----------------------------------------------------------------""" +# import numpy -path = path.replace('{model}', model).replace('{width}',str(display_width)).replace('{height}',str(display_height)) -print(path) - -try: - # POST request, passing path_body in the body - im = Image.open(requests.post(path, json=path_body, stream=True).raw) - -except FileNotFoundError: - raise Exception('Your file could not be found. Please check the path to your file.') - -except OSError: - raise Exception('Please check if the path points to an image file.') +filename = os.path.basename(__file__).split('.py')[0] +logger = logging.getLogger(filename) +logger.setLevel(level=logging.ERROR) + + +class Inkyserver(inkycal_module): + """Inkyserver class""" + + name = "Inkycal Server" + + requires = { + "panel_id" : { + "label":"Please enter your panel ID", + }, + + } + + def __init__(self, config): + """Initialize inkycal_feeds module""" + + super().__init__(config) + + config = config['config'] + + # Check if all required parameters are present + for param in self.requires: + if not param in config: + raise Exception('config is missing {}'.format(param)) + + # required parameters + self.panel_id = config["panel_id"] + + # give an OK message + print('{0} loaded'.format(filename)) + + def _validate(self): + """Validate module-specific parameters""" + + if not isinstance(self.panel_id, str): + print('panel_id has to be a string') + +def generate_image(self): + """Generate image for this module""" + + def get_image(url): + """Get an image from a given URL""" +## try: +## # POST request, passing path_body in the body +## im = Image.open(requests.post(path, json=path_body, stream=True).raw) +## +## except FileNotFoundError: +## raise Exception('Your file could not be found. Please check the path to your file.') +## +## except OSError: +## raise Exception('Please check if the path points to an image file.') + pass + ## return image + + def splice(image): + """Splits a 3-colour image to two black-white images""" + pass + ## return im_black, im_colour