Example #1
0
	def __init__(self, setToken, getToken, scope, extras=''):
		self.ip = helper.getIP()
		self.scope = scope
		self.oauth = None
		self.cbGetToken = getToken
		self.cbSetToken = setToken
		self.ridURI = 'https://photoframe.sensenet.nu'
		self.state = None
		self.extras = extras
Example #2
0
width, height, tvservice = display.setConfiguration(
    settings.getUser('tvservice'), settings.getUser('display-special'))
settings.setUser('tvservice', tvservice)
settings.setUser('width', width)
settings.setUser('height', height)
settings.save()

# Force display to desired user setting
display.enable(True, True)

# Load services
services = ServiceManager(settings)

# Spin until we have internet, check every 10s
while True:
    settings.set('local-ip', helper.getIP())

    if settings.get('local-ip') is None:
        logging.error(
            'You must have functional internet connection to use this app')
        display.message('No internet\n\nCheck wifi-config.txt or cable')
        time.sleep(10)
    else:
        break

# Let the display know the URL to use
display.setConfigPage('http://%s:%d/' % (settings.get('local-ip'), 7777))

# Prep random
random.seed(long(time.clock()))
colormatch = colormatch(settings.get('colortemp-script'),
Example #3
0
    def selectImageFromAlbum(self, destinationDir, supportedMimeTypes,
                             displaySize, randomize):
        # chooses an album and selects an image from that album --> return {'id':, 'mimetype':, 'error':, 'source':}
        # if no (new) images can be found --> return None

        keywordList = list(self.getKeywords())
        keywordCount = len(keywordList)
        if keywordCount == 0:
            return {
                'id': None,
                'mimetype': None,
                'source': None,
                'error': 'No albums have been specified'
            }

        if randomize:
            index = self.getRandomKeywordIndex()
        else:
            index = self.keywordIndex

        # if current keywordList[index] does not contain any new images --> just run through all albums
        for i in range(0, keywordCount):
            if not randomize and (index + i) >= keywordCount:
                # (non-random image order): return if the last album is exceeded --> serviceManager should use next service
                break
            self.keywordIndex = (index + i) % keywordCount
            keyword = keywordList[self.keywordIndex]

            # a provider-specific implementation for 'getImagesFor' is obligatory!
            images = self.getImagesFor(keyword)
            if images is None:
                logging.warning(
                    'Function returned None, this is used sometimes when a temporary error happens. Still logged'
                )
                self.imageIndex = 0
                continue
            if len(images) > 0 and 'error' in images[0]:
                return images[0]
            self._STATE["_NUM_IMAGES"][keyword] = len(images)
            if len(images) == 0:
                self.imageIndex = 0
                continue
            elif any(key not in images[0].keys() for key in
                     ['id', 'url', 'mimetype', 'source', 'filename']):
                return {
                    'id':
                    None,
                    'mimetype':
                    None,
                    'source':
                    None,
                    'error':
                    'You haven\'t implemented "getImagesFor" correctly (some keys are missing)'
                }
            self.saveState()

            image = self.selectImage(images, supportedMimeTypes, displaySize,
                                     randomize)
            if image is None:
                self.imageIndex = 0
                continue

            filename = os.path.join(destinationDir, image['id'])
            if CacheManager.useCachedImage(filename):
                if image['mimetype'] is None:
                    image['mimetype'] = helper.getMimeType(filename)
                return {
                    'id': image['id'],
                    'mimetype': image['mimetype'],
                    'source': image['source'],
                    'error': None
                }

            # you should implement 'addUrlParams' if the provider allows 'width' / 'height' parameters!
            recommendedSize = self.calcRecommendedSize(image['size'],
                                                       displaySize)
            url = self.addUrlParams(image['url'], recommendedSize, displaySize)

            try:
                result = self.requestUrl(url, destination=filename)
            except requests.exceptions.RequestException as e:
                # catch any exception caused by malformed url, unstable internet connection, ... that would otherwise break the entire photoframe
                logging.debug(str(e))
                if helper.getIP() is None:
                    return {
                        'id': None,
                        'mimetype': None,
                        'source': None,
                        'error': "No internet connection!"
                    }
                return {
                    'id':
                    None,
                    'mimetype':
                    None,
                    'source':
                    url,
                    'error':
                    "Unable to download image!\nServer might be unavailable or URL could be broken:\n%s"
                    % url
                }
            if result['status'] == 200:
                if image['mimetype'] is None:
                    image['mimetype'] = result['mimetype']
                return {
                    'id': image['id'],
                    'mimetype': image['mimetype'],
                    'source': image['source'],
                    'error': None
                }
            else:
                return {
                    'id': None,
                    'mimetype': None,
                    'source': None,
                    'error': "%d: Unable to download image!" % result['status']
                }

        self.resetIndices()
        return None