json config

This commit is contained in:
Omar Sánchez
2021-10-08 14:09:18 +02:00
parent f212b586b0
commit 6b7a7a24e4
3 changed files with 20 additions and 8 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
config.json

View File

@@ -36,11 +36,13 @@ obligatoryArgs.add_argument('-p', '--pin', help="Contraseña", type=int, require
obligatoryArgs.add_argument('-t', '--type', help="Tipo marcado. 0 = Entrada, 1 = Salida", type=int)
optionalArgs = parser.add_argument_group("Argumentos opcionales")
optionalArgs.add_argument('-bt', '--basedtime', help="Hacer check o descheck según la hora del dia", action="store_true")
optionalArgs.add_argument('-bt', '--basedtime', help="Hacer check o descheck según la hora del dia",
action="store_true")
optionalArgs.add_argument('-h', '--help', action="help", help="Esta ayuda")
args = parser.parse_args()
class AutoFicher():
# URL de la api
headers = {
@@ -51,7 +53,11 @@ class AutoFicher():
config = None
def __init__(self):
self.loadConfig()
try:
self.loadConfig()
except:
print("No se ha podido cargar el archivo de configuración")
exit(20)
def loadConfig(self):
with open('sample.config.json', 'r') as f:
@@ -62,17 +68,19 @@ class AutoFicher():
bot.sendMessage(chat_id=self.config['telegram']['chat_id'], text=str(message))
def get(self, url, data={}, headers={}):
furl = self.config['api_url'] + url
if url != "version":
self.url = self.url + "v1/"
return requests.get(self.config['api_url']+url, data=data, headers=headers)
furl = self.config['api_url'] + "v1/" + url
return requests.get(furl, data=data, headers=headers)
def post(self, url, data={}, headers={}):
furl = self.config['api_url'] + url
if url != "version":
self.url = self.url + "v1/"
return requests.post(self.config['api_url']+url, data=data, headers=headers)
furl = self.config['api_url'] + "v1/" + url
return requests.post(furl, data=data, headers=headers)
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") + "\""
def getVersion(self):
self.updateTime()
@@ -97,7 +105,8 @@ class AutoFicher():
elif hour in hOUT:
typ = 1
else:
print("No se ha fichado ni desfichado ya que estamos en horario laboral, fuerze el estado con el parametro --type <0 = Entrada, 1 = Salida>")
print(
"No se ha fichado ni desfichado ya que estamos en horario laboral, fuerze el estado con el parametro --type <0 = Entrada, 1 = Salida>")
else:
typ = args.type
@@ -120,5 +129,7 @@ class AutoFicher():
else:
self.sendReport("No se ha podido fichar, la web no ha devuelto 200 OK")
if __name__ == '__main__':
af = AutoFicher()
af.sendUpdate()

0
config.json Normal file
View File