Exemplo n.º 1
0
def get_photo_history():
    req = request.get_json(force=True)
    user = req['user']
    fotos = db.session.query(Fotografia).filter(Fotografia.emailinst == user).order_by(Fotografia.datafoto).all()
    fotografias = []
    for f in fotos:
        try:
            foto = {}
            readImage(f.path)
            foto['latitude'] = f.latitude
            foto['longitude'] = f.longitude
            foto['date'] = f.datafoto
            if f.nomeconc == 'desconhecido':
                foto['concept'] = ''
            else:
                foto['concept'] = f.nomeconc
            if './static' in f.path:
                temp = f.path.replace('./static/img/', '')
                temp = temp.split('/')
                foto['img'] = URL_PATH + 'pending/' + str(temp[0]+':'+temp[1])
            else:
                temp = f.path.replace('../', '')
                temp = temp.replace('treino/', '')
                foto['img'] = URL_PATH + temp
            fotografias.append(foto)
        except:
            print('Could not find: ' + f.path)
    return jsonify(fotografias[::-1])
Exemplo n.º 2
0
def get_atraction(id):
    conceito = db.session.query(Conceito).get(id)
    temp = db.session.query(Fotografia).filter(Fotografia.nomeconc==id).all()
    fotos = []
    fotos.append(temp[0])
    fotos.append(temp[1])
    fotografias = []
    for f in fotos:
        try:
            foto = ""
            readImage(f.path)
            if './static' in f.path:
                temp = f.path.replace('./static/img/', '')
                temp = temp.split('/')
                foto = URL_PATH + 'pending/' + str(temp[0]+':'+temp[1])
            else:
                temp = f.path.replace('../', '')
                temp = temp.replace('treino/', '')
                foto = URL_PATH + temp
            fotografias.append(foto)
        except:
            print('Could not find: ' + f.path)
    res = {}
    #res['name'] = conceito.nome
    res['name'] = conceito.nome
    res['id'] = conceito.nomeconceito
    res['description'] = conceito.descricao
    res['latitude'] = conceito.latitude
    res['longitude'] = conceito.longitude
    res['photos'] = fotografias
    return jsonify(res)
Exemplo n.º 3
0
def get_all_atractions():
    conceitos = Conceito.query.all()
    res = []

    for c in conceitos:
        temp = {}
        if c.nomeconceito == 'desconhecido':
            continue
        temp['id'] = c.nomeconceito
        temp['name'] = c.nome
        temp['latitude'] = c.latitude
        temp['longitude'] = c.longitude
        temp['description'] = c.descricao
        if c.latitude is None:
            temp['city'] = ''
        elif c.latitude is not None:
            geolocator = Nominatim()
            print(str(c.latitude) + ', ' + str(c.longitude))
            location = geolocator.reverse(str(c.latitude) + ', ' + str(c.longitude))
            if location is None:
                temp['city'] = ''
            else:
                location = location.address.split(',')
                if len(location) <= 9 and len(location) > 1:
                    temp['city'] = location[2]
                elif len(location) >= 10:
                    temp['city'] = location[3]
                else:
                    temp['city'] = ''
        fotos = db.session.query(Fotografia).filter(Fotografia.nomeconc==c.nomeconceito).all()
        path = ''
        for f in fotos:
            foto = {}
            
            try:
            
                readImage(f.path)
                if f.nomeconc == 'desconhecido':
                    foto['concept'] = ''
                else:
                    foto['concept'] = f.nomeconc
                if './static' in f.path:
                    temp1 = f.path.replace('./static/img/', '')
                    temp1 = temp1.split('/')
                    path = URL_PATH + 'pending/' + str(temp1[0]+':'+temp1[1])
                else:
                    temp1 = f.path.replace('../', '')
                    temp1 = temp1.replace('treino/', '')
                    path = URL_PATH + temp1
                break
            except:
                print('Could not find: ' + f.path)
        temp['imgName'] = path
        res.append(temp)
    return res
Exemplo n.º 4
0
def get_route_instance(id):
    instance = db.session.query(InstanciaPercurso).get(id)
    if instance is None:
        return jsonify({})
    route = db.session.query(Percurso).get(instance.idperc)

    res = {}
    res['title'] = route.titulo
    res['description'] = route.descricao

    fotos = db.session.query(Fotografia).filter(Fotografia.idinstperc==id).all()

    fotografias = []
    for f in fotos:
        try:
            foto = {}
            readImage(f.path)
            if './static' in f.path:
                temp = f.path.replace('./static/img/', '')
                temp = temp.split('/')
                foto['img'] = URL_PATH + 'pending/' + str(temp[0]+':'+temp[1])
            else:
                temp = f.path.replace('../', '')
                temp = temp.replace('treino/', '')
                foto['img'] = URL_PATH + temp
            foto['latitude'] = f.latitude
            foto['longitude'] = f.longitude
            foto['id'] = f.id
            foto['date'] = f.datafoto
            fotografias.append(foto)
        except:
            print('Could not find: ' + f.path)

    res['markers'] = fotografias
    pontos = db.session.query(Ponto).filter(Ponto.idperc == route.id).all()

    pnts = []
    for p in pontos:
        temp = {}
        temp['latitude'] = p.latitude
        temp['longitude'] = p.longitude
        pnts.append(temp)

    res['trajectory'] = pnts    

    return jsonify(res)
Exemplo n.º 5
0
def share_map_2(id):
    instance = db.session.query(InstanciaPercurso).get(id)
    if instance is None:
        return '<h1>Not Found</h1>'
    route = db.session.query(Percurso).get(instance.idperc)

    fotos = db.session.query(Fotografia).filter(Fotografia.idinstperc == id).all()

    fotografias = []
    for f in fotos:
        try:
            foto = {}
            foto['img'] = readImage(f.path)
            foto['latitude'] = f.latitude
            foto['longitude'] = f.longitude
            foto['id'] = f.id
            foto['date'] = f.datafoto
            foto['concept'] = f.nomeconc
            conceito = db.session.query(Conceito).get(f.nomeconc)
            foto['description'] = conceito.descricao
            if './static' in f.path:
                temp = f.path.replace('./static/img/', '')
                temp = temp.split('/')
                foto['path'] = '/sendimage/pending/' + str(temp[0] + ':' + temp[1])
            else:
                temp = f.path.replace('../', '')
                temp = temp.replace('treino/', '')
                foto['path'] = '/sendimage/' + temp
            fotografias.append(foto)
        except:
            print('Could not find: ' + f.path)

    pontos = db.session.query(Ponto).filter(Ponto.idperc == route.id).all()

    pnts = []
    for p in pontos:
        temp = {}
        temp['latitude'] = p.latitude
        temp['longitude'] = p.longitude
        pnts.append(temp)

    center = {}

    latitudes = 0
    longitudes = 0
    for p in pnts:
        latitudes += p['latitude']
        longitudes += p['longitude']

    center['latitude'] = latitudes / len(pnts)
    center['longitude'] = longitudes / len(pnts)

    return render_template('user_instance.html', center=center, points=pnts, fotos=fotografias, title=route.titulo,
                           desc=route.descricao)
Exemplo n.º 6
0
def user_gallery():
    if 'uid' not in session:
        return render_template('signIn.html', message='You have to log in first.')
    fotos = getPathFotosUser(session['email']) # função com a lista dos paths
    to_send = []
    for f in fotos:
        try:
            readImage(f.path)
            print(f.path)
            if 'static' in f.path:
                name = f.path.split('/')[-1]
                concept = f.nomeconc
                to_send.append(('pending', concept + ':' + name))
                print(concept + ':' + name)
            else:
                name = f.path.split('/')[-1]
                to_send.append((f.nomeconc, name))
                print(f.nomeconc, name)
        except:
            continue

    return render_template('user_gallery.html', images=to_send, admin=False)
Exemplo n.º 7
0
'''
Exemplo de um cliente RESTful para a API exposta pelo servidor
criado em server.py
'''

import requests
import json
from img_utils import readImage
#import time

#################################################
# Cliente para testar funcionamento da REST API #
#################################################

img = readImage('./temp.jpg') # converter imagem para string base64

# json para o pedido
data = {
    "image" : img
    #"user" : "*****@*****.**",
    #"lat" : 40.00,
    #"long" : 40.01,
    # "date"
}

#print(data)

url = 'http://192.168.160.192:5000/search' # url do serviço

#start = time.time()