Skip to content

Instantly share code, notes, and snippets.

@foxcarlos
Last active November 21, 2019 19:26
Show Gist options
  • Save foxcarlos/42682b0267eea09181d921fe67b3691c to your computer and use it in GitHub Desktop.
Save foxcarlos/42682b0267eea09181d921fe67b3691c to your computer and use it in GitHub Desktop.
Bot Alarmas
from odoo.addons.decimemijobot.tools.tools import CACHE, get_dolartoday_values
from odoo.addons.decimemijobot.tools.tools import get_bitcoin, get_ethereum
from odoo.addons.decimemijobot.tools.tools import get_litecoin, get_dolartoday
def clear_and_update_cache():
CACHE.clear()
get_dolartoday_values()
def obtener_precio(self, comando):
if comando == 'bitcoin':
ultimo_precio = get_bitcoin()
elif comando == 'dolartoday':
ultimo_precio = get_dolartoday()
elif comando == 'ethereum':
ultimo_precio = get_ethereum()
elif comando == 'litecoin':
ultimo_precio = get_litecoin()
elif comando == 'dolarairtm':
ultimo_precio = get_dolar_airtm()
elif comando == 'dolaryadio':
ultimo_precio = get_price_yadio()
elif comando == 'dolarlocalbitcoin':
ultimo_precio = get_localbitcoin_precio()
elif comando == 'dolarcasasdecambio':
ultimo_precio = get_dolar_gobierno()
elif comando == 'dolarbolivarcucuta':
ultimo_precio = get_dolar_bolivar_cucuta()
else:
ultimo_precio = 0
return ultimo_precio
def valida_cuando_limpiar_cache_dolartoday(objeto_alarma):
# Crear en Data una vista con un parter llamado dolartoday_cache
user = objeto_alarma.partner_id.name
if user.lower() == 'dolartoday_cache':
clear_and_update_cache()
comandos = env['decimemijobot.comando'].search([])
for comando in comandos:
for alarma in comando.alarma_ids:
# comando.name
id_telegram = alarma.partner_id.ref
comando_a_consultar = alarma.comando_id.name
frecuencia = alarma.frecuencia
porcentaje = alarma.porcentaje
ultimo_precio = alarma.ultimo_precio
precio_actual = obtener_precio(comando_a_consultar)
if precio_actual <> ultimo_precio:
valida_cuando_limpiar_cache_dolartoday(alarma)
if precio_actual > ultimo_precio:
alta_o_baja = ":arrow_up:"
elif precio_actual < ultimo_precio:
alta_o_baja = ":arrow_down:"
else:
alta_o_baja = "Se mantuvo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment