Inital template for Inkycal-Server module
This commit is contained in:
		| @@ -6,36 +6,73 @@ For use with Robert Sierre's inkycal web-service | |||||||
|  |  | ||||||
| Copyright by aceisace | Copyright by aceisace | ||||||
| """ | """ | ||||||
|  | from inkycal.modules.template import inkycal_module | ||||||
| from os import path | from inkycal.custom import * | ||||||
| from PIL import ImageOps |  | ||||||
| import requests | import requests | ||||||
| import numpy | # 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? |  | ||||||
| """----------------------------------------------------------------""" |  | ||||||
|  |  | ||||||
|  |  | ||||||
| path = path.replace('{model}', model).replace('{width}',str(display_width)).replace('{height}',str(display_height)) | filename = os.path.basename(__file__).split('.py')[0] | ||||||
| print(path) | logger = logging.getLogger(filename) | ||||||
|  | logger.setLevel(level=logging.ERROR) | ||||||
| try: |  | ||||||
|   # POST request, passing path_body in the body |  | ||||||
|   im = Image.open(requests.post(path, json=path_body, stream=True).raw) | class Inkyserver(inkycal_module): | ||||||
|    |   """Inkyserver class""" | ||||||
| except FileNotFoundError: |  | ||||||
|   raise Exception('Your file could not be found. Please check the path to your file.') |   name = "Inkycal Server" | ||||||
|  |  | ||||||
| except OSError: |   requires = { | ||||||
|   raise Exception('Please check if the path points to an image file.') |     "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 | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user