cosas bonitas con el fiching
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -1,4 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<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" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (autoficher)" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from app import config_parser
|
from app import config_parser
|
||||||
import telegram
|
import telegram
|
||||||
|
import random
|
||||||
|
|
||||||
config = config_parser.ConfigParser().loadConfig()
|
config = config_parser.ConfigParser().loadConfig()
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import requests, json, pytz
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import random
|
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()
|
args = arg_parser.ArgParser().parse()
|
||||||
config = config_parser.ConfigParser().loadConfig()
|
config = config_parser.ConfigParser().loadConfig()
|
||||||
@@ -41,6 +41,7 @@ class timenetManager:
|
|||||||
def sendReport(self):
|
def sendReport(self):
|
||||||
# self.telegram.sendMessage(self.message_acumulator)
|
# self.telegram.sendMessage(self.message_acumulator)
|
||||||
asyncio.run(self.telegram.sendMessage(self.message_acumulator))
|
asyncio.run(self.telegram.sendMessage(self.message_acumulator))
|
||||||
|
self.message_acumulator = ""
|
||||||
|
|
||||||
def updateTime(self):
|
def updateTime(self):
|
||||||
self.headers["tn-d"] = "\"" + datetime.now().astimezone(pytz.UTC).strftime("%Y-%m-%dT%H:%M:%SZ") + "\""
|
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})
|
return self.get('check/info', {"guid": args.user})
|
||||||
|
|
||||||
def sendUpdate(self):
|
def sendUpdate(self):
|
||||||
|
conditional_response = [{
|
||||||
|
"text": "fichado",
|
||||||
|
"text2": "fichar",
|
||||||
|
"emoji": "🕐🏢🏃♂️🏡"
|
||||||
|
},{
|
||||||
|
"text": "desfichado",
|
||||||
|
"text2": "desfichar",
|
||||||
|
"emoji": "🏡🏃♂️🏢🕐"
|
||||||
|
}]
|
||||||
|
|
||||||
if args.pin is None:
|
if args.pin is None:
|
||||||
# if pin is None, prompt for it
|
# if pin is None, prompt for it
|
||||||
@@ -89,9 +99,10 @@ class timenetManager:
|
|||||||
response = None
|
response = None
|
||||||
if not args.debug:
|
if not args.debug:
|
||||||
self.addMessage("####HACIENDO CHECK####")
|
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)
|
sleep(rand)
|
||||||
self.addMessage("Esperando %s segundos para fichar/desfichar en un minuto aleatorio" % rand)
|
|
||||||
self.updateTime()
|
self.updateTime()
|
||||||
data = {
|
data = {
|
||||||
"cp": config['user'],
|
"cp": config['user'],
|
||||||
@@ -129,14 +140,6 @@ class timenetManager:
|
|||||||
self.addMessage("🕐 Ya se ha realizado este marcaje antes a las %s" % time)
|
self.addMessage("🕐 Ya se ha realizado este marcaje antes a las %s" % time)
|
||||||
else:
|
else:
|
||||||
time = datetime.now().astimezone(pytz.timezone("Europe/Madrid")).strftime("%H:%M")
|
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))
|
self.addMessage('%s Has %s correctamente a las %s' % (conditional_response[int(typ)]['emoji'], conditional_response[int(typ)]['text'], time))
|
||||||
else:
|
else:
|
||||||
self.addMessage("🟥🕐 No se ha podido fichar, la web no ha devuelto 200 OK")
|
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