def get(self):

        utils.add_response_headers(self.request, self.response.headers)
        self.response.headers['Content-Type'] = "text/plain"

        status = commonactions.publish_next()

        self.response.out.write(status + "\r\n")
    def post(self):
        content = self.request.body

        itemsWritten = sync.synchronize_common(content)

        utils.add_response_headers(self.request, self.response.headers)
        self.response.headers['Content-Type'] = "text/plain"
        self.response.out.write("Items Written: " + str(itemsWritten))
    def get(self):
        userAgent = self.request.headers.get('User-Agent', None)

        if utils.is_development() == False and self.request.scheme == 'http' and utils.device_supports_ssl_tni(userAgent):
            self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
            self.response.headers['Pragma'] = 'public'
            self.redirect(utils.redirect_url(self.request.path, self.request.query_string), permanent=True)

        utils.add_response_headers(self.request, self.response.headers)
        windows_sshare = utils.enable_windows_share_metadata(self.request.headers.get('User-Agent', None))

        template_vals = {'host': self.request.host_url, 'path': searchPath, 'track': track, 'hash': hash,
                         'users': users, 'showShare': False, 'windowsShare': windows_sshare}
        self.response.out.write(utils.render_template("notfound.html", template_vals))
        self.response.set_status(404)
Exemple #4
0
def process_requests() -> str:
    # Decode the data sent from the alexa
    data = json.loads(flask.request.data.decode('utf-8'))

    # Get the request data to determine what kind of request it was
    request = data.get('request')
    request_type = request.get('type')

    # When there is a launch request
    if request_type == 'LaunchRequest':
        return LaunchRequest()

    # When it is an intent request
    if request_type == 'IntentRequest':
        # Class of intent handlers
        intents = Intents()
        intent = request.get('intent')

        # Pass along any variables obtained from alexa request
        slots = None
        if 'slots' in intent:
            slots = intent.get('slots')

        # Run the corresponding intent handler
        response = getattr(intents, intent.get('name'))(slots)
        return utils.add_response_headers(response)
    def get(self):

        user_agent = self.request.headers.get('User-Agent', None)

        if utils.is_development() == False and self.request.scheme == 'http' and utils.device_supports_ssl_tni(user_agent):
            self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
            self.response.headers['Pragma'] = 'public'
            self.redirect(utils.redirect_url(self.request.path, self.request.query_string), permanent=True)

        search_path = self.request.path.lower()

        new_search_path = utils.convert_old_url(search_path)

        logging.info('Redirect to: ' + new_search_path)

        utils.add_response_headers(self.request, self.response.headers)
        self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
        self.response.headers['Pragma'] = 'public'
        self.redirect(utils.redirect_url(new_search_path, self.request.query_string), permanent=True)
Exemple #6
0
    def test_process_requests(self):
        """ Tests adding headers to responses """
        expected = '{"version": "1.0", "response": {"outputSpeech": {"text": "Hello World!"}}, "sessionAttributes": ""}'
        result = utils.add_response_headers(
            {'outputSpeech': {
                'text': 'Hello World!'
            }})

        self.assertEqual(result, expected)
        self.assertEqual(type(result), str)
Exemple #7
0
    def get(self):

        # Long expiry - so don't need to generate unless an upload has taken place
        expiry_seconds = 60 * 60 * 24 * 7

        if utils.is_cron_task(self.request.headers):
            sitemapbuilder.build_sitemap_index('https://www.markridgwell.co.uk', expiry_seconds)
            sitemapbuilder.build_sitemap_index('http://www.markridgwell.co.uk', expiry_seconds)
            sitemapbuilder.build_sitemap_index('https://www.markridgwell.com', expiry_seconds)
            sitemapbuilder.build_sitemap_index('http://www.markridgwell.com', expiry_seconds)
        else:

            output = sitemapbuilder.build_sitemap_index(self.request.host_url, expiry_seconds)

            utils.add_response_headers(self.request, self.response.headers)
            self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
            self.response.headers['Pragma'] = 'public'
            self.response.headers['Content-Type'] = 'text/xml'
            self.response.out.write(output)
    def get(self):

        utils.add_response_headers(self.request, self.response.headers)
        self.response.headers['Content-Type'] = "text/plain"

        id = 'cff7bc268029dbf1205927eba4a173aa03797cac03c48409f481be049a8803bef9dab95612cc406d719a25c1ab98fa285fc54199f491da127f5c17f26daa5ac2'

        status = commonactions.delete_item_from_publish_queue(id)

        user_address = '*****@*****.**'
        #chat_message_sent = False
        msg = "Deletion status: " + status
        xmpp.send_invite(user_address)
        xmpp.send_message(user_address, msg)
        #status_code = xmpp.send_message(user_address, msg)
        #chat_message_sent = (status_code == xmpp.NO_ERROR)

        #if not chat_message_sent:

        self.response.out.write(status)
Exemple #9
0
def LaunchRequest() -> str:
    """ The handler for the skill launch request

    :return: The text to say when the skill is launched
    """
    response = {
        'outputSpeech': {
            'text': 'What would you like to do?',
            'type': 'PlainText'
        },
        'shouldEndSession': False
    }
    # Add the response headers
    response = utils.add_response_headers(response)
    return response
Exemple #10
0
    def get(self):
        pubsubhubub.update('http://markridgwell.superfeedr.com', 'http://www.markridgwell.co.uk/rss.xml')

        utils.add_response_headers(self.request, self.response.headers)
        self.response.headers['Content-Type'] = "text/plain"
        self.response.out.write("OK")
Exemple #11
0
 def get(self):
     utils.add_response_headers(self.request, self.response.headers)
     self.response.headers['Content-Type'] = "text/plain"
     self.response.out.write("OK")
Exemple #12
0
 def get(self):
     utils.add_response_headers(self.request, self.response.headers)
     self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
     self.response.headers['Pragma'] = 'public'
     self.redirect('https://www.markridgwell.co.uk/rss.xml', permanent=True)
Exemple #13
0
    def get(self):

        userAgent = self.request.headers.get('User-Agent', None)

        # Long expiry - so don't need to generate unless an upload has taken place
        expiry_seconds = 60 * 60 * 24 * 7
        memcachedKey = 'rss-output'
        output = ''

        memcacheEnabled = capabilities.CapabilitySet('memcache').is_enabled()

        if memcacheEnabled:
            try:
                output = memcache.get(memcachedKey)
            except KeyError:
                output = ''

        if output is None or len(output) == 0:

            q = models.GeneratedItem.query(models.GeneratedItem.id == memcachedKey)
            pregenerated = q.get()
            if pregenerated is None:
                count = 200

                recentItemsSearch = models.GalleryItem.query(models.GalleryItem.type == 'photo').order(
                    -models.GalleryItem.updated).fetch(count)
                when = datetime.datetime.now()
                builddate = when

                recentItems = []
                if recentItemsSearch:
                    latestDate = None
                    for item in recentItemsSearch:
                        if utils.is_public_publishable_path(item.path):
                            recentItems.append(item)
                            if latestDate is None:
                                latestDate = item.updated
                            else:
                                if latestDate < item.updated:
                                    latestDate = item.updated
                    if latestDate <> None:
                        when = latestDate

                template_vals = {'host': self.request.host_url, 'items': recentItems, 'pubdate': when,
                                 'builddate': builddate}

                output = utils.render_template("rss.html", template_vals)

                pregenerated = models.GeneratedItem(
                    id=memcachedKey,
                    text=output,
                    updated=when)
                pregenerated.put();
            else:
                output = pregenerated.text

        if memcacheEnabled:
            memcache.set(memcachedKey, output, expiry_seconds)

        utils.add_response_headers(self.request, self.response.headers)
        self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
        self.response.headers['Pragma'] = 'public'
        self.response.headers['Content-Type'] = 'application/rss+xml'
        self.response.out.write(output)
Exemple #14
0
    def get(self):

        host = self.request.host_url

        user_agent = self.request.headers.get('User-Agent', None)

        if utils.is_development() == False:
            if self.request.scheme == 'http' and utils.device_supports_ssl_tni(user_agent):
                self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
                self.response.headers['Pragma'] = 'public'
                self.redirect(utils.redirect_url(self.request.path, self.request.query_string), permanent=True)

            if host != 'http://www.markridgwell.co.uk' and host != 'https://www.markridgwell.co.uk':
                self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
                self.response.headers['Pragma'] = 'public'
                self.redirect(utils.redirect_url(self.request.path, self.request.query_string), permanent=True)
                return



        windows_share = utils.enable_windows_share_metadata(user_agent)
        search_path = self.request.path.lower()

        hash = utils.generate_url_hash(search_path)

        q = models.GalleryItem.query(models.GalleryItem.id == hash)

        track = utils.should_track(self.request.headers)
        if track:
            logging.info('Tracking: Enabled')
        else:
            logging.info('Tracking: Disabled')

        item = q.get()
        if item is None:
            new_search_path = utils.convert_old_url(search_path)

            should_report_error = True
            if new_search_path <> search_path:
                hash = utils.generate_url_hash(new_search_path)
                search_path = new_search_path
                q = models.GalleryItem.query(models.GalleryItem.id == hash)
                item = q.get()

                if item is not None:
                    should_report_error = False
                    utils.add_response_headers(self.request, self.response.headers)
                    self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
                    self.response.headers['Pragma'] = 'public'
                    self.redirect(utils.redirect_url(new_search_path, self.request.query_string), permanent=True)

            if should_report_error:
                template_vals = {'host': self.request.host_url, 'path': search_path, 'track': track, 'hash': hash,
                                 'users': users, 'showShare': False, 'windowsShare': windows_share}
                utils.add_response_headers(self.request, self.response.headers)
                self.response.out.write(utils.render_template("notfound.html", template_vals))
                self.response.set_status(404)
        else:
            children = None
            if item.children:
                children = []
                for child in item.children:
                    thumbnail_url = None
                    if child.thumbnail:
                        base_child_image_path = child.path
                        if child.originalAlbumPath:
                            base_child_image_path = child.originalAlbumPath

                        thumbnail_url = utils.image_url(
                            base_child_image_path, child.thumbnail)
                    tag_id = utils.path_to_tagId(child.path)
                    childItem = {'id': child.id, 'path': child.path, 'title': child.title, 'type': child.type,
                                 'description': child.description, 'thumbnail': child.thumbnail,
                                 'thumbnailUrl': thumbnail_url, "tagId": tag_id}
                    children.append(childItem)

            parent_item_url = None
            breadcrumbs = None
            if item.breadcrumbs:
                breadcrumbs = []
                last_crumb_tag_id = utils.path_to_tagId(item.path)
                for crumb in reversed(item.breadcrumbs):
                    if parent_item_url is None:
                        parent_item_url = host + crumb.path
                    tag_id = utils.path_to_tagId(crumb.path)
                    crumb_item = {'id': crumb.id, 'path': crumb.path, 'title': crumb.title, 'description': crumb.description, "tagId": last_crumb_tag_id}
                    breadcrumbs.insert(0, crumb_item)
                    last_crumb_tag_id = tag_id
            if parent_item_url is None:
                parent_item_url = host

            resize_css = None
            thumbnail_image_url = None
            full_image_url = None
            image_width = None
            image_height = None

            base_image_path = item.path
            if item.originalAlbumPath:
                base_image_path = item.originalAlbumPath

            if item.resizes:

                ordered_resizes = sorted(item.resizes, key=lambda r: r.width)

                css = utils.build_image_css(item, ordered_resizes)
                if css is None:
                    first = None
                    last = None
                    resize_css = None
                else:
                    first = css['first']
                    last = css['last']
                    resize_css = '<style>' + css['css'] + '</style>'

                if first is None:
                    resize_css = ''
                else:
                    thumbnail_image_url = utils.image_url(base_image_path, first)

                    full_image_url = utils.image_url(base_image_path, last)
                    image_width = last.width
                    image_height = last.height

            first_sibling = None
            previous_sibling = None
            next_sibling = None
            last_sibling = None

            if item.firstSibling is not None:
                first_sibling = {'title': item.firstSibling.title, 'url': item.firstSibling.path}

            if item.previousSibling is not None:
                previous_sibling = {'title': item.previousSibling.title, 'url': item.previousSibling.path}

            if item.nextSibling is not None:
                next_sibling = {'title': item.nextSibling.title, 'url': item.nextSibling.path}

            if item.lastSibling is not None:
                last_sibling = {'title': item.lastSibling.title, 'url': item.lastSibling.path}

            keywords_text = None
            if item.keywords:
                keywords_text = ",".join(item.keywords)

            show_share = utils.should_share(user_agent)

            views = 0
            if item.resizes:

                if tracking.is_sharing_callback(user_agent):
                    views = tracking.record_share(item.id, item.path)
                else:
                    if tracking.is_trackable(user_agent):
                        views = tracking.record_view(item.id, item.path)

            original_album_path = ''
            title = item.title
            if children is None:
                title = itemnaming.photo_title(item, 10000)

                if item.originalAlbumPath:
                    original_album_path = item.originalAlbumPath

            description = ''
            if item.description:
                md = markdown.Markdown()
                raw_description = item.description
                description = md.convert(raw_description)

            keywords = []
            if item.keywords:
                item_to_select = ''
                if item.path.startswith('/albums/'):
                    if item.breadcrumbs:
                        item_to_select = utils.path_to_tagId(item.breadcrumbs[-1].path) + '-' + utils.path_to_tagId(item.path)
                else:
                    item_to_select = utils.path_to_tagId(item.path)

                for keyword in item.keywords:
                    keyword_url = utils.generate_keyword_url(host, keyword, item_to_select)

                    keywords.append(
                        {'name': keyword, 'url': keyword_url}
                    )

            template_vals = {'host': host, 'path': search_path, 'track': track, 'hash': hash, 'users': users,
                             'title': title, 'item': item, 'children': children, 'breadcrumbs': breadcrumbs,
                             'resizecss': resize_css, 'staticurl': self.request.relative_url('/static'),
                             'thumbnail_url': thumbnail_image_url, 'fullImageUrl': full_image_url,
                             'fullImageWidth': image_width, 'fullImageHeight': image_height,
                             'firstSibling': first_sibling, 'previousSibling': previous_sibling,
                             'nextSibling': next_sibling, 'lastSibling': last_sibling,
                             'keywords': keywords, 'showShare': show_share, 'windowsShare': windows_share,
                             'parentItemUrl': parent_item_url, 'description': description,
                             'original_album_path': original_album_path, 'keywords_text': keywords_text}
            if children is None:
                self.response.out.write(utils.render_template("photo.html", template_vals))
            else:
                if search_path == '/':
                    self.response.out.write(utils.render_template("home.html", template_vals))
                else:
                    self.response.out.write(utils.render_template("index.html", template_vals))

            utils.add_response_headers(self.request, self.response.headers)
            self.response.headers['Cache-Control'] = 'public,max-age=%d' % 86400
            self.response.headers['Pragma'] = 'public'
            self.response.headers['X-PageViews'] = str(views)