From 4ffed0a5f69772308164460686cac571fb1e4d78 Mon Sep 17 00:00:00 2001 From: nataliagranato Date: Wed, 20 Mar 2024 11:26:04 -0300 Subject: [PATCH 1/5] fix: pylint note at 3.85/10 --- analise-de-custos.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/analise-de-custos.py b/analise-de-custos.py index f416fa3..18580c4 100644 --- a/analise-de-custos.py +++ b/analise-de-custos.py @@ -1,14 +1,17 @@ -import boto3 import datetime +import boto3 # Configuração do cliente boto3 ce_client = boto3.client('ce', region_name='us-east-1') # Substitua 'us-east-1' pela sua região # Taxa de câmbio da AWS para converter para BRL -currency_conversion_rate = 5.50 # Substitua pelo valor da taxa de câmbio atual +CURRENCY_CONVERSION_RATE = 5.50 # Substitua pelo valor da taxa de câmbio atual # Função para obter o período desejado de forma interativa def get_custom_date_range(): + """ + Obtém o período desejado de forma interativa. + """ print("Digite o período desejado para análise de custos:") start_date_str = input("Data de início (AAAA-MM-DD): ") end_date_str = input("Data de término (AAAA-MM-DD): ") @@ -23,6 +26,9 @@ def get_custom_date_range(): # Função para obter e listar os serviços e valores de gastos def list_costs_by_service(start_date, end_date): + """ + Obtém e lista os serviços e valores de gastos. + """ response = ce_client.get_cost_and_usage( TimePeriod={ 'Start': start_date.strftime('%Y-%m-%d'), @@ -42,7 +48,7 @@ def list_costs_by_service(start_date, end_date): for group in result['Groups']: service_name = group['Keys'][0] cost = float(group['Metrics']['BlendedCost']['Amount']) - cost_brl = cost * currency_conversion_rate + cost_brl = cost * CURRENCY_CONVERSION_RATE print(f"Serviço: {service_name}, Custo em USD: ${cost:.2f}, Custo em BRL: R${cost_brl:.2f}") if __name__ == '__main__': From 97cea0613482ab44fbb807117e29f4f75af78bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nat=C3=A1lia=20Granato?= <91998391+nataliagranato@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:29:36 -0300 Subject: [PATCH 2/5] fix: pylint note at 5.38/10 From 582997b18e69b89a0c071c704066ecdbab0f4d42 Mon Sep 17 00:00:00 2001 From: nataliagranato Date: Wed, 20 Mar 2024 11:51:11 -0300 Subject: [PATCH 3/5] feat: tests and __init__.py --- .gitignore | 2 ++ README.md | 14 ++++++++++ __init__.py | 9 +++++++ __pycache__/analise_de_custos.cpython-311.pyc | Bin 0 -> 3283 bytes analise-de-custos.py => analise_de_custos.py | 25 +++++++++++++++--- tests/test_analise_de_custos.py | 6 +++++ 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 __init__.py create mode 100644 __pycache__/analise_de_custos.cpython-311.pyc rename analise-de-custos.py => analise_de_custos.py (76%) create mode 100644 tests/test_analise_de_custos.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3454843 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tests/__pycache__ +.vscode \ No newline at end of file diff --git a/README.md b/README.md index c714956..a779e9e 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,18 @@ Para executar o script, você pode usar o seguinte comando: python3 analise-de-custos.py ``` +Ou + +``` +python3 -m analise_de_custos +``` + O script irá solicitar que você insira as datas de início e término para a análise de custos. As datas devem ser inseridas no formato AAAA-MM-DD. Em seguida, o script irá listar os custos dos serviços AWS para o período de tempo especificado. + +## Extras + +- 1. **Executando o teste**: + +``` +python3 -m unittest tests.test_analise_de_custos +``` diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..650bc0d --- /dev/null +++ b/__init__.py @@ -0,0 +1,9 @@ +from analise_de_custos import get_custom_date_range, list_costs_by_service + +def main(): + start_date, end_date = get_custom_date_range() + if start_date and end_date: + list_costs_by_service(start_date, end_date) + +if __name__ == '__main__': + main() diff --git a/__pycache__/analise_de_custos.cpython-311.pyc b/__pycache__/analise_de_custos.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dd10e7f1396cbce847bf8f137f697a38cfec2489 GIT binary patch literal 3283 zcmbVO&2QVt6(35ZM9H!hn`UBJiN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;p(QN=uo_Ymaho!F?xEs|rT}7A9w{2{2fTYKsvzu<6*4trI`itCiqzn{Yl&1(q_jC052l)8( zCr?*tzC(jX4HP?(5lc|m04=H}X_!3D?7e~!mLAJlm0%m%((n;gwL@r}BWbOTi|q?0 zP0+gvNEA7OQy-upy?f2e_<>dny1LZ9ACzNi9xyq9a}u%fT5X_gjJP1gki+5<6dWvP zG_P3hyZ2&CHy4+!p7|^|$I1d+Y|9h5bvGJI+`1RD+=*!X;jM)z=&?)d1#CG1ZvbJu zOMqARF#wuk_1plAFtReq=<8q+>m-xXEcXqf8io0Ft2d4{Bdcrk>r}^b+3T9cf+3C2 zA|@21E!SL5HS+p~bMpL}LGMQ5FzvI_M*m0B0>yj@f_jjM%t~V$1075A@x@swJ{EFW zo)iF4HiH3N2W-5AaFQ~BpP|VBmK0ytY<%U`0L*l2XyHLT9*r$5Cl~I;9!BFd=45^4awPj_IE$i>1(L@suW4NmiqkN{^N{ zB2YsjEvzIJ(2}d`$wO^24ZKl!v`fujKlhf9Sw}Zr^|I zFXHI~abjPb*d4Bj7ftbERR|skWBbC`&Pqj?HihXr=N$Cb5hXklN2>iJ&-`^43XD}x zNWkmu10E13*YB z@FyKv+^VXp7c5t!6v#NNkq{;Jr-^2o>d^B_Cfi5+B_bbFA$m&h`KviqF|zna8Q$_wQ`&UK2E&B(F?G2QoPZzfbcdwLvmnyzXrti|02i8wYWi(WGi41%~ zT4Z{Zq512ew;9CxN*nvmK-n3n2B*ux=}Pdt89ZNMhqi7% Date: Wed, 20 Mar 2024 11:57:15 -0300 Subject: [PATCH 4/5] feat: tests and __init__.py --- __init__.py | 17 ++++++++++++----- __pycache__/analise_de_custos.cpython-311.pyc | Bin 3283 -> 0 bytes tests/test_analise_de_custos.py | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) delete mode 100644 __pycache__/analise_de_custos.cpython-311.pyc diff --git a/__init__.py b/__init__.py index 650bc0d..a199d1c 100644 --- a/__init__.py +++ b/__init__.py @@ -1,9 +1,16 @@ -from analise_de_custos import get_custom_date_range, list_costs_by_service +""" +Este é o módulo principal do projeto aws_cost_py. +Ele importa e executa as funções do módulo analise_de_custos. +""" + +from .analise_de_custos import get_custom_date_range, list_costs_by_service def main(): + """ + Função principal que solicita ao usuário um intervalo de datas e lista os custos dos serviços AWS para esse intervalo. + """ start_date, end_date = get_custom_date_range() - if start_date and end_date: - list_costs_by_service(start_date, end_date) + list_costs_by_service(start_date, end_date) -if __name__ == '__main__': - main() +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/__pycache__/analise_de_custos.cpython-311.pyc b/__pycache__/analise_de_custos.cpython-311.pyc deleted file mode 100644 index dd10e7f1396cbce847bf8f137f697a38cfec2489..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3283 zcmbVO&2QVt6(35ZM9H!hn`UBJiNnHnVj(Nrn*>Pgq)lu~&6lGDl9Sd(3xO8LTBVXG z49R3|$b}C*=#WEtS_8=fUKB{Y$ZmI!xwI(ie?T%=SRf#@K+!|di;8rCAg8{etS@H^ zv>go}XXbs)d-LW;z3T1tB51$;?mhmq2cf^xNwcwsgSRhW@EKB&!er4( z8NePg01__DV^6nL2KJHYdP1JRQyVeMk-{4uLknYB)59N!7^{cibVki5^KuTS8-9*o zPqiGvfClM==k4zq8l(=i*%am_%wD%v7^G9l!=^a8xtrZw=MgUBL3%TxV4iHw*HL@RNO3376ZENb89iY_yzy($_e#+2t?GMU<|I`rV6ykM zs;H8JHT+1n2hy5KazK%T=CM5KwUy#nS4m!;wI|eyZWOY3R$79WETvSC&w~M3 zlN4E}6oZYuuTvRS!V>r+xlA4$wVh7dmW&Iqt4JoD(ed|gs2~$rlJk3CWHTD3MpK5S ztJ?k0D z$JDc;PD&5Jz1m0)2(%qd8fQV#8~qfgjJ;QTzfl{hBWkXYQDjJQR+S9R*!zNH)X7+g zx3~g<7-zfSh{9;AIez+M+s4hC8n{Sv?I?YDKkmrd>UK* zckueEDih@vJuPAs^bl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5hXklN2>iJ&-`^43XD}x zNWkmu10E13*YB z@FyKv+^VXp7c5t!6v#NNkq{;Jr-^2o>d^B_Cfi5+B_bbFA$m&h`KviqF|zna8Q$_wQ`&UK2E&B(F?G2QoPZzfbcdwLvmnyzXrti|02i8wYWi(WGi41%~ zT4Z{Zq512ew;9CxN*nvmK-n3n2B*ux=}Pdt89ZNMhqi7% Date: Wed, 20 Mar 2024 12:35:34 -0300 Subject: [PATCH 5/5] fix: pylint note at 5.38/10 --- __pycache__/analise_de_custos.cpython-311.pyc | Bin 0 -> 3295 bytes analise_de_custos.py | 22 +++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) create mode 100644 __pycache__/analise_de_custos.cpython-311.pyc diff --git a/__pycache__/analise_de_custos.cpython-311.pyc b/__pycache__/analise_de_custos.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bf30a568e26977daa52232c86cdb64e283858633 GIT binary patch literal 3295 zcmbVOUu+Y}8J}J6+Ut!IlWZ1}7{XR05R1#710+bGh5T`WBN!9|*SM{$jc1ZuYJ1)N z1DD9D^3VrA@W9(ef=W46f*|g6Csmbrs;c^>k9M?Gtd&w#s`^m%#TBiD=u5v@$99}+ ztG46W&$ILWo9~-%emgHaJ4FO-fc*#geGs8P(w9c#_6KjbVDK5jD2XtG*$k6pyni;y zvWTz`eGLWd!`v7A3l^c*@YGw9!~P_X13yJcKNf%nh=7AX^7zI{(D%Op!PgCO^aJ1| zgGrGDjUFNzJs=SvK_a$WWe{c)ZBJCRSHOrEGcBT&UMaegE&T%98C_9xYDP0j3X@dY zHZ9#86Jr^or1hLtdX-g{?Of?)>6gS*@~WZkORI*Wn@U|=!7wz5@klGZgwgcJi81ld zbiHwxO_Q~tZH^Mvv_?OSGH!=KRx~}A%BfjGmjmtSwRC+@r!=WFVQ+uM(4<;G8x1or z;O%vDhCx;{wFrW3=dQPNeTTSA5Lt~41P2eB8?tr4X2UZ=1%$cw6mK2SZppQ8);jw? z`C$GpAHD)x@GZl3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