<commit_before># -*- coding: utf-8 -*-
'''
Created on 16 janv. 2016

@author: romain
'''

import falcon
import os
import config
from PIL import Image

from db import db

preview_size = 600,600

class Map(object):
    '''
    Get the map according to the UUID
    '''

    _table = "maps"
    
    def map_id_is_valid(self, map_id):
        
        is_valid = True
        if map_id is None:
            is_valid = False
        return is_valid

    def on_get(self, req, resp):
        '''Return JPEG map image according to id param
        '''

        map_id = req.get_param('id')
        if not self.map_id_is_valid(map_id):
            resp.status = falcon.HTTP_400
        else:
            cur = db.cursor()
            
            #id (uuid), path (str), geom (geom), address (str), level (str), building (str)
            query = "SELECT path FROM %s" % self._table
                    # Look at 1/10 (0.1) degrees around spot.
            query += " WHERE id='%s'" % (map_id)
            cur.execute(query)
            map_path = cur.fetchall()[0][0]
            

            resp.set_header('X-Powered-By', 'OpenEvacMap')
            if map_path is None:
                resp.status = falcon.HTTP_404
            else:
                full_path = os.path.join(config.map_dir,map_path)
                preview = req.params.get('preview','0')
                if preview=='1':
                    outfile = os.path.splitext(full_path)[0] + "_preview.jpg"
                    print(outfile)
                    if os.path.exists(outfile)==False:
                        im = Image.open(full_path)
                        im.thumbnail(preview_size, Image.ANTIALIAS)
                        im.save(outfile, "JPEG")
                    full_path=outfile<commit_msg>Syntax compatible with falcon 0.1.8<commit_after># -*- coding: utf-8 -*-
'''
Created on 16 janv. 2016

@author: romain
'''

import falcon
import os
import config
from PIL import Image

from db import db

preview_size = 600,600

class Map(object):
    '''
    Get the map according to the UUID
    '''

    _table = "maps"
    
    def map_id_is_valid(self, map_id):
        
        is_valid = True
        if map_id is None:
            is_valid = False
        return is_valid

    def on_get(self, req, resp):
        '''Return JPEG map image according to id param
        '''

        map_id = req.get_param('id')
        if not self.map_id_is_valid(map_id):
            resp.status = falcon.HTTP_400
        else:
            cur = db.cursor()
            
            #id (uuid), path (str), geom (geom), address (str), level (str), building (str)
            query = "SELECT path FROM %s" % self._table
                    # Look at 1/10 (0.1) degrees around spot.
            query += " WHERE id='%s'" % (map_id)
            cur.execute(query)
            map_path = cur.fetchall()[0][0]
            

            resp.set_header('X-Powered-By', 'OpenEvacMap')
            if map_path is None:
                resp.status = falcon.HTTP_404
            else:
                full_path = os.path.join(config.map_dir,map_path)
                preview = req.get_param('preview')
                if preview is None:
                    preview = '0'
                if preview=='1':
                    outfile = os.path.splitext(full_path)[0] + "_preview.jpg"
                    print(outfile)
                    if os.path.exists(outfile)==False:
                        im = Image.open(full_path)
                        im.thumbnail(preview_size, Image.ANTIALIAS)
                        im.save(outfile, "JPEG")
                    full_path=outfile
{'fraction_non_alphanumeric': 0.1085100523271826, 'fraction_numerical': 0.016799779675020655, 'mean_word_length': 1.5100207325501036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6049205', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1067, 'n_words': 273}