Last active
September 10, 2018 11:42
-
-
Save thotypous/174533c761ec3fd1e2f5a2349fc0585e to your computer and use it in GitHub Desktop.
Cadastro de visitantes em lote na Wi-Fi da UFSCar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import sys | |
| import csv | |
| import requests | |
| username = '<redacted>' | |
| password = '<redacted>' | |
| inicio_validade = '2018-09-10T00:00:00.000Z' | |
| fim_validade = '2018-09-17T23:59:59.999Z' | |
| justificativa = 'SECOMP' | |
| r = requests.post('https://sistemas.ufscar.br/sagui-api/api/login', | |
| json={'username': username, 'password': password}) | |
| login_data = r.json() | |
| assert 'ROLE_VISITANTE_CADASTRAR_VISITANTE' in login_data['roles'] | |
| headers = {'Authorization': '%s %s' % (login_data['token_type'], | |
| login_data['access_token'])} | |
| for cpf, email, nome in csv.reader(sys.stdin, delimiter=';'): | |
| r = requests.post('https://sistemas.ufscar.br/sagui-api/visitante', | |
| json={'cpf': cpf, 'email': email, 'nome': nome}, | |
| headers=headers) | |
| cadastro = r.json() | |
| print(repr(cadastro)) | |
| id_visitante = cadastro['id'] | |
| r = requests.post('https://sistemas.ufscar.br/sagui-api/visitante/%d/autorizar' % id_visitante, | |
| json={'visitante': id_visitante, | |
| 'inicioValidade': inicio_validade, | |
| 'fimValidade': fim_validade, | |
| 'justificativa': justificativa}, | |
| headers=headers) | |
| autorizacao = r.json() | |
| print(repr(autorizacao)) | |
| print() | |
| requests.post('https://sistemas.ufscar.br/sagui-api/api/logout', | |
| headers=headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment