json config
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
config.json
|
||||||
@@ -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)
|
obligatoryArgs.add_argument('-t', '--type', help="Tipo marcado. 0 = Entrada, 1 = Salida", type=int)
|
||||||
|
|
||||||
optionalArgs = parser.add_argument_group("Argumentos opcionales")
|
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")
|
optionalArgs.add_argument('-h', '--help', action="help", help="Esta ayuda")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
class AutoFicher():
|
class AutoFicher():
|
||||||
# URL de la api
|
# URL de la api
|
||||||
headers = {
|
headers = {
|
||||||
@@ -51,7 +53,11 @@ class AutoFicher():
|
|||||||
config = None
|
config = None
|
||||||
|
|
||||||
def __init__(self):
|
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):
|
def loadConfig(self):
|
||||||
with open('sample.config.json', 'r') as f:
|
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))
|
bot.sendMessage(chat_id=self.config['telegram']['chat_id'], text=str(message))
|
||||||
|
|
||||||
def get(self, url, data={}, headers={}):
|
def get(self, url, data={}, headers={}):
|
||||||
|
furl = self.config['api_url'] + url
|
||||||
if url != "version":
|
if url != "version":
|
||||||
self.url = self.url + "v1/"
|
furl = self.config['api_url'] + "v1/" + url
|
||||||
return requests.get(self.config['api_url']+url, data=data, headers=headers)
|
return requests.get(furl, data=data, headers=headers)
|
||||||
|
|
||||||
def post(self, url, data={}, headers={}):
|
def post(self, url, data={}, headers={}):
|
||||||
|
furl = self.config['api_url'] + url
|
||||||
if url != "version":
|
if url != "version":
|
||||||
self.url = self.url + "v1/"
|
furl = self.config['api_url'] + "v1/" + url
|
||||||
return requests.post(self.config['api_url']+url, data=data, headers=headers)
|
return requests.post(furl, data=data, headers=headers)
|
||||||
|
|
||||||
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") + "\""
|
||||||
|
|
||||||
def getVersion(self):
|
def getVersion(self):
|
||||||
self.updateTime()
|
self.updateTime()
|
||||||
@@ -97,7 +105,8 @@ class AutoFicher():
|
|||||||
elif hour in hOUT:
|
elif hour in hOUT:
|
||||||
typ = 1
|
typ = 1
|
||||||
else:
|
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:
|
else:
|
||||||
typ = args.type
|
typ = args.type
|
||||||
|
|
||||||
@@ -120,5 +129,7 @@ class AutoFicher():
|
|||||||
else:
|
else:
|
||||||
self.sendReport("No se ha podido fichar, la web no ha devuelto 200 OK")
|
self.sendReport("No se ha podido fichar, la web no ha devuelto 200 OK")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
af = AutoFicher()
|
af = AutoFicher()
|
||||||
|
af.sendUpdate()
|
||||||
|
|||||||
0
config.json
Normal file
0
config.json
Normal file
Reference in New Issue
Block a user