cosas bonitas con el fiching
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from app import config_parser
|
||||
import telegram
|
||||
import random
|
||||
|
||||
config = config_parser.ConfigParser().loadConfig()
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import requests, json, pytz
|
||||
from datetime import datetime
|
||||
from time import sleep
|
||||
import random
|
||||
from app import arg_parser, config_parser, telegram_bot, google_calendar
|
||||
from app import arg_parser, config_parser, telegram_bot, google_calendar, utils
|
||||
|
||||
args = arg_parser.ArgParser().parse()
|
||||
config = config_parser.ConfigParser().loadConfig()
|
||||
@@ -41,6 +41,7 @@ class timenetManager:
|
||||
def sendReport(self):
|
||||
# self.telegram.sendMessage(self.message_acumulator)
|
||||
asyncio.run(self.telegram.sendMessage(self.message_acumulator))
|
||||
self.message_acumulator = ""
|
||||
|
||||
def updateTime(self):
|
||||
self.headers["tn-d"] = "\"" + datetime.now().astimezone(pytz.UTC).strftime("%Y-%m-%dT%H:%M:%SZ") + "\""
|
||||
@@ -58,6 +59,15 @@ class timenetManager:
|
||||
return self.get('check/info', {"guid": args.user})
|
||||
|
||||
def sendUpdate(self):
|
||||
conditional_response = [{
|
||||
"text": "fichado",
|
||||
"text2": "fichar",
|
||||
"emoji": "🕐🏢🏃♂️🏡"
|
||||
},{
|
||||
"text": "desfichado",
|
||||
"text2": "desfichar",
|
||||
"emoji": "🏡🏃♂️🏢🕐"
|
||||
}]
|
||||
|
||||
if args.pin is None:
|
||||
# if pin is None, prompt for it
|
||||
@@ -89,9 +99,10 @@ class timenetManager:
|
||||
response = None
|
||||
if not args.debug:
|
||||
self.addMessage("####HACIENDO CHECK####")
|
||||
rand = random.randint(0, 230);
|
||||
rand = utils.numero_aleatorio_con_probabilidad(230, 0.5)
|
||||
self.addMessage("Esperando %s segundos para %s en un minuto aleatorio" % (rand,conditional_response[int(typ)]["text2"]))
|
||||
self.sendReport()
|
||||
sleep(rand)
|
||||
self.addMessage("Esperando %s segundos para fichar/desfichar en un minuto aleatorio" % rand)
|
||||
self.updateTime()
|
||||
data = {
|
||||
"cp": config['user'],
|
||||
@@ -129,14 +140,6 @@ class timenetManager:
|
||||
self.addMessage("🕐 Ya se ha realizado este marcaje antes a las %s" % time)
|
||||
else:
|
||||
time = datetime.now().astimezone(pytz.timezone("Europe/Madrid")).strftime("%H:%M")
|
||||
|
||||
conditional_response = [{
|
||||
"text": "fichado",
|
||||
"emoji": "🕐🏢🏃♂️🏡"
|
||||
},{
|
||||
"text": "desfichado",
|
||||
"emoji": "🏡🏃♂️🏢🕐"
|
||||
}]
|
||||
self.addMessage('%s Has %s correctamente a las %s' % (conditional_response[int(typ)]['emoji'], conditional_response[int(typ)]['text'], time))
|
||||
else:
|
||||
self.addMessage("🟥🕐 No se ha podido fichar, la web no ha devuelto 200 OK")
|
||||
|
||||
15
app/utils.py
Normal file
15
app/utils.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import random
|
||||
|
||||
|
||||
def numero_aleatorio_con_probabilidad(rango, probabilidad_alta):
|
||||
# Generar un número aleatorio entre 0 y 1
|
||||
probabilidad = random.random()
|
||||
|
||||
# Calcular el rango ajustado
|
||||
rango_ajustado = int(rango * probabilidad_alta)
|
||||
|
||||
# Generar un número aleatorio ponderado
|
||||
numero = random.randint(0, rango_ajustado) if probabilidad < probabilidad_alta else random.randint(
|
||||
rango_ajustado, rango)
|
||||
|
||||
return numero
|
||||
Reference in New Issue
Block a user