diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..ed8ebf583f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/Procfile b/Procfile new file mode 100644 index 0000000000..caf672282e --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn server:app diff --git a/README.md b/README.md index 5cfcfd7847..4fa428908f 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,57 @@ # Fundamentus -Esta é uma pequena API feita em python3 para análise de ações da BOVESPA utilizando o site fundamentus (www.fundamentus.com.br), que retorna os -principais indicadores fundamentalistas em formato JSON. -A API utiliza o microframework Flask. -Também é possível utilizar via linha de comando. - -# Linha de comando - $ python3 fundamentus.py - -# API -Execute o server.py e conecte no endereço (ex.: http://127.0.0.1:5000/) com seu browser - -# Requirements - Flask - lxml - -Install with: - pip3 install -r required.txt + +This is a simple Python3 API to help analysing BOVESPA stocks, it collects data (scraping) from the Fundamentus website (www.fundamentus.com.br), which contains important "fundamental indicators", and return it as JSON. + +This API uses the Flask microframework, but it can also be used directly on command line. + +## Development env setup + +Install the dependencies: + +`$ pip3 install -r requirements.txt` + +## Command line usage + +`$ python3 fundamentus.py` + +## HTTP API + +### Development API + +`$ python3 server.py` + +After starting the server, access the URL on your browser. + +### Production API + +`$ gunicorn server:app` + +After starting the server, access the URL on your browser. + +## Production deploy + +You can easily deploy this API to production, using [Heroku](https://www.heroku.com/): + +### Heroku initial setup + +* First, you need to install the Heroku CLI, if you haven't yet: +* Then, you need to login to it `$ heroku login` +* Lastly, you need to create a heroku app `$ heroku create your-api-name-here` + +### Deploy + +You can deploy to heroku, with: + +* `$ git push heroku master` + +In case you are in a different branch, ex `develop`, you can deploy with: + +* `$ git push heroku develop:master` + +After deploying to heroku, you can access the API on + +### Production troubleshooting + +In case the production API on Heroku fails, you can visualize the logs with this command: + +`$ heroku logs --tail` diff --git a/required.txt b/required.txt deleted file mode 100644 index c732cdcdd3..0000000000 --- a/required.txt +++ /dev/null @@ -1,7 +0,0 @@ -# pip3 install -r required.txt -Flask>=1.0.0 -itsdangerous>=1.0.0 -Jinja2>=2.10.1 -lxml>=4.6.2 -MarkupSafe>=1.0.0 -Werkzeug>=1.0.0 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000..7d0b3b3011 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +click==7.1.2 +Flask==1.1.2 +gunicorn==20.0.4 +itsdangerous==1.1.0 +Jinja2==2.11.3 +lxml==4.6.2 +MarkupSafe==1.1.1 +Werkzeug==1.0.1 diff --git a/server.py b/server.py index d4b7c8a155..fe1cbb0ba1 100755 --- a/server.py +++ b/server.py @@ -13,7 +13,7 @@ @app.route("/") def json_api(): global lista, dia - + # Then only update once a day if dia == datetime.strftime(datetime.today(), '%d'): return jsonify(lista) @@ -22,4 +22,5 @@ def json_api(): lista = {outer_k: {inner_k: float(inner_v) for inner_k, inner_v in outer_v.items()} for outer_k, outer_v in lista.items()} return jsonify(lista) -app.run(debug=True) +if __name__ == '__main__': + app.run(debug=True)