|
14 | 14 | get_financial_data_by_siren, |
15 | 15 | ) |
16 | 16 | from enthic.database.fetch import fetchall |
| 17 | +from enthic.database.mysql import initialize_mysql |
17 | 18 | from enthic.decorator.insert_request import insert_request |
18 | 19 | from enthic.ontology import ( |
19 | 20 | APE_CODE, |
|
50 | 51 | application.config["MYSQL_DB"] = "enthic" |
51 | 52 |
|
52 | 53 |
|
| 54 | +initialize_mysql(application) |
| 55 | + |
| 56 | + |
53 | 57 | @application.route( |
54 | 58 | "/company/siren/<int:siren>/<string:year>", methods=["GET"], strict_slashes=False |
55 | 59 | ) |
@@ -83,6 +87,29 @@ def company_siren(siren): |
83 | 87 | return AllSirenCompany(siren) |
84 | 88 |
|
85 | 89 |
|
| 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 | + |
86 | 113 | @application.route("/exist/siren/<sirens>", methods=["GET"], strict_slashes=False) |
87 | 114 | def company_denomination_year(sirens): |
88 | 115 | """ |
|
0 commit comments