cosas bonitas con el fiching

Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
Omar Sánchez Pizarro
2023-11-09 18:48:07 +01:00
parent 1f3f57e3eb
commit e9ec438183
4 changed files with 33 additions and 11 deletions

3
.idea/misc.xml generated
View File

@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.11 (autoficher)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (autoficher)" project-jdk-type="Python SDK" />
</project>

View File

@@ -1,5 +1,6 @@
from app import config_parser
import telegram
import random
config = config_parser.ConfigParser().loadConfig()

View File

@@ -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
View 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