Skip to content

Commit

Permalink
refactoring files in order to generate a .exe file
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuslab committed Aug 21, 2021
1 parent 396b376 commit 795e751
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 67 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
venv/
__pycache__
.env
output/main_file.py
build/
dist/
output/
40 changes: 40 additions & 0 deletions main.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(['src\\main.py'],
pathex=['C:\\Users\\Matheus\\Pictures\\cobli-bi'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
4 changes: 2 additions & 2 deletions src/costs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import requests
import pandas as pd
from initial import start_timestamp, end_timestamp, apiKey
from initial import start_timestamp, end_timestamp


def getCostsDataFrame(apiKey=apiKey, end_timestamp=end_timestamp, start_timestamp=start_timestamp):
def getCostsDataFrame(apiKey=None, end_timestamp=end_timestamp, start_timestamp=start_timestamp):
costsURL = f"https://api.cobli.co/herbie-1.1/costs/report?begin={start_timestamp}&end={end_timestamp}&tz=America%2FFortaleza"
costsResponse = requests.get(costsURL, headers={'cobli-api-key': apiKey})
return pd.read_excel(costsResponse.content, 0)
Expand Down
41 changes: 41 additions & 0 deletions src/generate_bi_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import inspect
import requests
from productivity import getProductivityDataFrame, productivity_function_name
from costs import getCostsDataFrame, costs_function_name
from incidents import getIncidentsDataFrame, incidents_function_name
import os
from dotenv import load_dotenv

load_dotenv()

productivityScript = inspect.getsource(getProductivityDataFrame)
costsScript = inspect.getsource(getCostsDataFrame)
incidentsScript = inspect.getsource(getIncidentsDataFrame)

with open("../output/data.py", "r") as dataFile:
apiKeyList = dataFile.read() or os.getenv('API_KEY')
parsedApiKeyList = apiKeyList.replace(' ', '').split(',')

os.remove("../output/data.py")

with open("../src/initial.py", "r") as initialFile, \
open('../output/main_file.py', 'w') as main_file:
main_file.write(initialFile.read() + '\n\n')
main_file.write(costsScript + '\n')
main_file.write(incidentsScript + '\n')
main_file.write(productivityScript + '\n')
for key in parsedApiKeyList:
response = requests.get('https://api.cobli.co/api-keys/external-auth', headers={'cobli-api-key': key})

if(response.status_code != 200):
print(f"Algo de errado aconteceu na coleta de dados da API, usando a chave {key} \n\n")
input("Pressione uma tecla para continuar!")
exit()

fleetId = response.headers.get('cobli-fleet-id').replace('.', '_').replace('-', '_')
main_file.write(
f"costsFunction_{fleetId} = {costs_function_name}('{key}')\n\n")
main_file.write(
f"incidentsFunction_{fleetId} = {incidents_function_name}('{key}')\n\n")
main_file.write(
f"productivityFunction_{fleetId} = {productivity_function_name}('{key}')\n\n")
4 changes: 2 additions & 2 deletions src/incidents.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import requests
import pandas as pd
from initial import start_timestamp, end_timestamp, apiKey
from initial import start_timestamp, end_timestamp


def getIncidentsDataFrame(apiKey=apiKey, end_timestamp=end_timestamp, start_timestamp=start_timestamp):
def getIncidentsDataFrame(apiKey=None, end_timestamp=end_timestamp, start_timestamp=start_timestamp):
incidentsURL = f"https://api.cobli.co/herbie-1.1/stats/incidents/report?begin={start_timestamp}&end={end_timestamp}&tz=America%2FFortaleza"
incidentsResponse = requests.get(
incidentsURL, headers={'cobli-api-key': apiKey})
Expand Down
5 changes: 1 addition & 4 deletions src/initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import pandas as pd
import time
import datetime
import platform
import os
from shutil import which

# Input de Dados
#
start = "01/06/2021 16:31:32.123"
end = "16/06/2021 23:59:59.123"
apiKey = os.getenv('API_KEY')

#
format_string = "%d/%m/%Y %H:%M:%S.%f"
start_timestamp = int(time.mktime(
Expand Down
18 changes: 18 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import platform
from shutil import which

if platform.system() == "Windows" and which("python") is None:
if not os.path.isfile('./python.exe'):
print("Fazendo download do Python")
os.system("curl https://www.python.org/ftp/python/3.9.6/python-3.9.6-amd64.exe -o python.exe --silent")
print("Instalando Python no seu computador...")
os.system(".\python.exe /passive")
os.system("pip install -q pandas matplotlib requests openpyxl")

apiKeyList = input('Por favor, digite as chaves de API das frotas desejadas, separadas por vírgula: \n\n')

with open("../output/data.py", "w") as dataFile:
dataFile.write(apiKeyList)

os.system("python ../src/generate_bi_script.py")
39 changes: 0 additions & 39 deletions src/my_script.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/productivity.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import requests
import pandas as pd
from initial import start_timestamp, end_timestamp, apiKey
from initial import start_timestamp, end_timestamp


def getProductivityDataFrame(apiKey=apiKey, end_timestamp=end_timestamp, start_timestamp=start_timestamp):
def getProductivityDataFrame(apiKey=None, end_timestamp=end_timestamp, start_timestamp=start_timestamp):
productivityURL = f"https://api.cobli.co/herbie-1.1/stats/performance/vehicle/report?begin={start_timestamp}&end={end_timestamp}&tz=America%2FFortaleza"
productivityResponse = requests.get(
productivityURL, headers={'cobli-api-key': apiKey})
Expand Down
17 changes: 0 additions & 17 deletions src/windows_requirements.py

This file was deleted.

0 comments on commit 795e751

Please sign in to comment.