|
@@ -1,16 +1,15 @@
|
|
from __future__ import print_function, absolute_import
|
|
from __future__ import print_function, absolute_import
|
|
|
|
+import warnings
|
|
|
|
+warnings.simplefilter("ignore", UserWarning)
|
|
|
|
+
|
|
from tornado.ioloop import IOLoop
|
|
from tornado.ioloop import IOLoop
|
|
-from client import Client, ConnectionError
|
|
|
|
from boxconfig import parse_config
|
|
from boxconfig import parse_config
|
|
from dejavu.recognize import FilePerSecondRecognizer
|
|
from dejavu.recognize import FilePerSecondRecognizer
|
|
-from dejavu import Dejavu, CouldntDecodeError
|
|
|
|
|
|
+from dejavu import Dejavu
|
|
from endpoint import setup_endpoint
|
|
from endpoint import setup_endpoint
|
|
-
|
|
|
|
-from multiprocessing import Process
|
|
|
|
import logging as log
|
|
import logging as log
|
|
import requests
|
|
import requests
|
|
-import dateutil
|
|
|
|
-import math
|
|
|
|
|
|
+import json
|
|
import time
|
|
import time
|
|
import os
|
|
import os
|
|
|
|
|
|
@@ -43,7 +42,6 @@ threshold_mode = THRESHOLD_FIXED
|
|
def obt_siguiente_trabajo():
|
|
def obt_siguiente_trabajo():
|
|
url = 'https://api.fourier.audio/na/calendario/pendiente?id=%s' % (config['device_id'],)
|
|
url = 'https://api.fourier.audio/na/calendario/pendiente?id=%s' % (config['device_id'],)
|
|
response = requests.get(url)
|
|
response = requests.get(url)
|
|
- log.info(response.json())
|
|
|
|
return response.json()
|
|
return response.json()
|
|
|
|
|
|
|
|
|
|
@@ -66,8 +64,8 @@ def descargar_anuncio(ad_path):
|
|
return ruta_anuncio
|
|
return ruta_anuncio
|
|
|
|
|
|
else:
|
|
else:
|
|
- print("Error al descargar")
|
|
|
|
- print(response)
|
|
|
|
|
|
+ log.info("Error al descargar")
|
|
|
|
+ log.info(response)
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
|
|
@@ -91,8 +89,8 @@ def descargar_media(box, station, media):
|
|
fp.write(response.content)
|
|
fp.write(response.content)
|
|
return out_file
|
|
return out_file
|
|
else:
|
|
else:
|
|
- print("Error al descargar")
|
|
|
|
- print(response)
|
|
|
|
|
|
+ log.info("Error al descargar")
|
|
|
|
+ log.info(response)
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
|
|
@@ -116,9 +114,9 @@ def obt_calibracion(calibracion):
|
|
return default
|
|
return default
|
|
|
|
|
|
|
|
|
|
-def enviar_resultados(item):
|
|
|
|
- url = 'https://api.fourier.audio/v1/calendario/resultado'
|
|
|
|
- response = requests.post(url, json=item)
|
|
|
|
|
|
+def enviar_resultados(trabajo):
|
|
|
|
+ url = 'https://api.fourier.audio/na/calendario/resultado'
|
|
|
|
+ response = requests.post(url, json=trabajo)
|
|
return response
|
|
return response
|
|
|
|
|
|
|
|
|
|
@@ -127,9 +125,6 @@ def llenar_pila():
|
|
server and add them to a memory queue. """
|
|
server and add them to a memory queue. """
|
|
try:
|
|
try:
|
|
response = obt_siguiente_trabajo()
|
|
response = obt_siguiente_trabajo()
|
|
- # response = client.get_schedule_pending()
|
|
|
|
- # downloaded_counter = len(response['items'])
|
|
|
|
- # for item in response['items']:
|
|
|
|
if len(response["elementos"]) > 0:
|
|
if len(response["elementos"]) > 0:
|
|
queue.put(response)
|
|
queue.put(response)
|
|
|
|
|
|
@@ -138,10 +133,6 @@ def llenar_pila():
|
|
else:
|
|
else:
|
|
loop.add_timeout(time.time() + 30, llenar_pila)
|
|
loop.add_timeout(time.time() + 30, llenar_pila)
|
|
|
|
|
|
- except ConnectionError as ex:
|
|
|
|
- log.error('[feed_queue] cannot feed: {}, retryig later'.format(ex))
|
|
|
|
- loop.add_timeout(time.time() + 15, llenar_pila)
|
|
|
|
-
|
|
|
|
except Exception as ex:
|
|
except Exception as ex:
|
|
""" Errores desconocidos """
|
|
""" Errores desconocidos """
|
|
log.error('[feed_queue] {}'.format(ex))
|
|
log.error('[feed_queue] {}'.format(ex))
|
|
@@ -173,9 +164,7 @@ def procesar_trabajo(pendiente):
|
|
anuncios = []
|
|
anuncios = []
|
|
id_by_ad = {}
|
|
id_by_ad = {}
|
|
item_ids = []
|
|
item_ids = []
|
|
- x = 0
|
|
|
|
for i in pendiente["elementos"]:
|
|
for i in pendiente["elementos"]:
|
|
- x = x + 1
|
|
|
|
id_by_ad[i['anuncio']] = i['id']
|
|
id_by_ad[i['anuncio']] = i['id']
|
|
if i['id'] not in item_ids:
|
|
if i['id'] not in item_ids:
|
|
item_ids.append(i['id'])
|
|
item_ids.append(i['id'])
|
|
@@ -185,7 +174,7 @@ def procesar_trabajo(pendiente):
|
|
anuncios.append(anuncio)
|
|
anuncios.append(anuncio)
|
|
|
|
|
|
except Exception as err:
|
|
except Exception as err:
|
|
- print('[process_segment] [{}] {}'.format(estacion, err))
|
|
|
|
|
|
+ log.info('[process_segment] [{}] {}'.format(estacion, err))
|
|
|
|
|
|
# Descarga de media
|
|
# Descarga de media
|
|
try:
|
|
try:
|
|
@@ -196,37 +185,38 @@ def procesar_trabajo(pendiente):
|
|
media.append((archivo, i["fecha"], i["timestamp"]))
|
|
media.append((archivo, i["fecha"], i["timestamp"]))
|
|
|
|
|
|
except Exception as err:
|
|
except Exception as err:
|
|
- print(err)
|
|
|
|
|
|
+ log.info(err)
|
|
|
|
|
|
dejavu = None
|
|
dejavu = None
|
|
- resultados = []
|
|
|
|
- v = []
|
|
|
|
resultados = {}
|
|
resultados = {}
|
|
try:
|
|
try:
|
|
dejavu = Dejavu({"database_type": "mem"})
|
|
dejavu = Dejavu({"database_type": "mem"})
|
|
try:
|
|
try:
|
|
x = 0
|
|
x = 0
|
|
for ruta, fecha, ts in media:
|
|
for ruta, fecha, ts in media:
|
|
- print("Huellando %s" % (ruta,))
|
|
|
|
- dejavu.fingerprint_file(ruta)
|
|
|
|
|
|
+ log.info("Huellando %s" % (ruta,))
|
|
|
|
+ dejavu.fingerprint_file(ruta, ts)
|
|
except Exception as ex:
|
|
except Exception as ex:
|
|
- print(err)
|
|
|
|
|
|
+ log.info(ex)
|
|
|
|
|
|
for anuncio in anuncios:
|
|
for anuncio in anuncios:
|
|
|
|
+ log.info("Buscando anuncio %s" % (anuncio,))
|
|
for i in dejavu.recognize(recognizer, anuncio, 5):
|
|
for i in dejavu.recognize(recognizer, anuncio, 5):
|
|
if not "id" in i:
|
|
if not "id" in i:
|
|
continue
|
|
continue
|
|
|
|
|
|
- if i["confidence"] < 35:
|
|
|
|
|
|
+ if i["confidence"] < 50:
|
|
continue
|
|
continue
|
|
|
|
|
|
- print(i)
|
|
|
|
obj = i
|
|
obj = i
|
|
obj["match_time"] = None
|
|
obj["match_time"] = None
|
|
|
|
+ nombre_anuncio = os.path.split(anuncio)[-1]
|
|
|
|
+ id = id_by_ad[nombre_anuncio]
|
|
dict = {
|
|
dict = {
|
|
- "id": obj["id"],
|
|
|
|
|
|
+ "id": id,
|
|
"anuncio": anuncio,
|
|
"anuncio": anuncio,
|
|
"fecha": obj["name"],
|
|
"fecha": obj["name"],
|
|
|
|
+ "timestamp": obj["name"] + int(obj['offset_seconds']),
|
|
"confianza": obj["confidence"],
|
|
"confianza": obj["confidence"],
|
|
"longitud": obj["length"],
|
|
"longitud": obj["length"],
|
|
"desfase_segundos": obj["offset_seconds"]
|
|
"desfase_segundos": obj["offset_seconds"]
|
|
@@ -239,8 +229,20 @@ def procesar_trabajo(pendiente):
|
|
|
|
|
|
resultados[i["id"]] = dict
|
|
resultados[i["id"]] = dict
|
|
|
|
|
|
|
|
+ for id in resultados:
|
|
|
|
+ e = resultados[id]
|
|
|
|
+ for i in pendiente['elementos']:
|
|
|
|
+ anuncio = e['anuncio'].replace('/tmp/ads/', '')
|
|
|
|
+ if i['id'] == id and i['anuncio'] == anuncio:
|
|
|
|
+ if 'encontrados' not in i:
|
|
|
|
+ i['encontrados'] = []
|
|
|
|
+ i['encontrados'].append(e)
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ enviar_resultados(pendiente)
|
|
|
|
+
|
|
except Exception as ex:
|
|
except Exception as ex:
|
|
- print(err)
|
|
|
|
|
|
+ log.info(ex)
|
|
|
|
|
|
|
|
|
|
app = setup_endpoint(queue=queue)
|
|
app = setup_endpoint(queue=queue)
|
|
@@ -252,4 +254,4 @@ if __name__ == '__main__':
|
|
log.info('Starting ondemand service')
|
|
log.info('Starting ondemand service')
|
|
loop.start()
|
|
loop.start()
|
|
except KeyboardInterrupt:
|
|
except KeyboardInterrupt:
|
|
- log.error('Process killed')
|
|
|
|
|
|
+ log.error('Process killed')
|