Skip to content

Commit 62fc3da

Browse files
author
leonard
committed
small fixes + new api point to get companies of a given APE code
1 parent 86ca12b commit 62fc3da

5 files changed

Lines changed: 42 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,6 @@ notebooks
116116
venv
117117
data
118118
*.tmp
119-
119+
bundles/
120120
sql_data
121121
migrations

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ Create and activate virtual environment python 3.9.4.
2424
The package uses [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv).
2525
```
2626
make create_environment
27+
```
28+
```
2729
make dev_requirements
2830
```
2931

3032
In production run the following instead :
3133
```
3234
make create_environment
35+
```
36+
```
3337
make prod_requirements
3438
```
3539

enthic/app.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
get_financial_data_by_siren,
1515
)
1616
from enthic.database.fetch import fetchall
17+
from enthic.database.mysql import initialize_mysql
1718
from enthic.decorator.insert_request import insert_request
1819
from enthic.ontology import (
1920
APE_CODE,
@@ -50,6 +51,9 @@
5051
application.config["MYSQL_DB"] = "enthic"
5152

5253

54+
initialize_mysql(application)
55+
56+
5357
@application.route(
5458
"/company/siren/<int:siren>/<string:year>", methods=["GET"], strict_slashes=False
5559
)
@@ -83,6 +87,29 @@ def company_siren(siren):
8387
return AllSirenCompany(siren)
8488

8589

90+
@application.route("/company/ape/<string:ape>", methods=["GET"], strict_slashes=False)
91+
@insert_request
92+
def company_ape(ape):
93+
sql_query = """SELECT identity.siren, denomination, value FROM identity
94+
INNER JOIN annual_statistics ON identity.siren=annual_statistics.siren
95+
WHERE stats_type = 1"""
96+
enthic_ape_code = get_corresponding_ape_codes(ape)
97+
98+
if len(enthic_ape_code) > 1:
99+
sql_query += f" AND ape IN {tuple(enthic_ape_code)}"
100+
elif len(enthic_ape_code) == 1:
101+
sql_query += f" AND ape = {enthic_ape_code[0]}"
102+
sql_query += """GROUP BY siren
103+
ORDER BY value DESC"""
104+
sql_param = {"ape": enthic_ape_code}
105+
companies = fetchall(sql_query, sql_param)
106+
result = [
107+
{"siren": item[0], "denomination": item[1], "score": item[2]}
108+
for item in companies
109+
]
110+
return OKJSONResponse(result)
111+
112+
86113
@application.route("/exist/siren/<sirens>", methods=["GET"], strict_slashes=False)
87114
def company_denomination_year(sirens):
88115
"""

enthic/database/mysql.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from flask import current_app as application
21
from flask_mysqldb import MySQL
32

4-
try:
5-
mysql = MySQL(application)
6-
except RuntimeError:
7-
pass # RUNTIME ERROR: WORKING OUTSIDE OF APPLICATION CONTEXT. LIKE EXECUTING SPHINX
3+
mysql = None
4+
5+
6+
def initialize_mysql(application):
7+
global mysql
8+
try:
9+
mysql = MySQL(application)
10+
except RuntimeError:
11+
pass # RUNTIME ERROR: WORKING OUTSIDE OF APPLICATION CONTEXT. LIKE EXECUTING SPHINX

references/naf_transition.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"65.06": "45.20A",
33
"79.06": "68.31Z",
4+
"07.11Z": "77.11A",
45
"07.42C": "71.12B",
56
"07.03D": "68.32A",
67
"07.22A": "58.29A",

0 commit comments

Comments
 (0)