Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -23,6 +23,7 @@ from bs4 import BeautifulSoup
|
|
23 |
from flask import Flask
|
24 |
|
25 |
server = Flask(__name__)
|
|
|
26 |
# external JavaScript files
|
27 |
external_scripts = [
|
28 |
'https://datacipen-eventia.hf.space/copilot/index.js'
|
@@ -437,30 +438,7 @@ def searchByRome(codeRome):
|
|
437 |
allRome.append({"value": refRome['metadata']['rome'], "label": refRome['metadata']['rome'] + " - " + refRome['metadata']['libelle_rome']})
|
438 |
return sorted(allRome, key=lambda element:element["value"])
|
439 |
|
440 |
-
def connexion_France_Travail():
|
441 |
-
client = Api(client_id=os.getenv('POLE_EMPLOI_CLIENT_ID'),
|
442 |
-
client_secret=os.getenv('POLE_EMPLOI_CLIENT_SECRET'))
|
443 |
-
return client
|
444 |
|
445 |
-
def API_France_Travail(romeListArray):
|
446 |
-
client = connexion_France_Travail()
|
447 |
-
todayDate = datetime.datetime.today()
|
448 |
-
month, year = (todayDate.month-1, todayDate.year) if todayDate.month != 1 else (12, todayDate.year-1)
|
449 |
-
start_dt = todayDate.replace(day=1, month=month, year=year)
|
450 |
-
end_dt = datetime.datetime.today()
|
451 |
-
results = []
|
452 |
-
for k in romeListArray:
|
453 |
-
if k[0:1] == ' ':
|
454 |
-
k = k[1:]
|
455 |
-
params = {"motsCles": k.replace('/', '').replace('-', '').replace(',', '').replace(' ', ','),'minCreationDate': dt_to_str_iso(start_dt),'maxCreationDate': dt_to_str_iso(end_dt),'range':'0-149'}
|
456 |
-
try:
|
457 |
-
search_on_big_data = client.search(params=params)
|
458 |
-
results += search_on_big_data["resultats"]
|
459 |
-
except:
|
460 |
-
print("Il n'y a pas d'offres d'emploi.")
|
461 |
-
|
462 |
-
results_df = pd.DataFrame(results)
|
463 |
-
return results_df
|
464 |
|
465 |
theme_toggle = dmc.Tooltip(
|
466 |
dmc.ActionIcon(
|
@@ -627,7 +605,39 @@ class CustomDash(Dash):
|
|
627 |
|
628 |
#app = Dash(__name__, external_scripts=external_scripts, external_stylesheets=dmc.styles.ALL, on_error=custom_error_handler)
|
629 |
app = CustomDash(__name__, server=server, external_scripts=external_scripts, external_stylesheets=dmc.styles.ALL, on_error=custom_error_handler)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
630 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
631 |
app.layout = dmc.MantineProvider(
|
632 |
[
|
633 |
html.Div(
|
|
|
23 |
from flask import Flask
|
24 |
|
25 |
server = Flask(__name__)
|
26 |
+
from flask_caching import Cache
|
27 |
# external JavaScript files
|
28 |
external_scripts = [
|
29 |
'https://datacipen-eventia.hf.space/copilot/index.js'
|
|
|
438 |
allRome.append({"value": refRome['metadata']['rome'], "label": refRome['metadata']['rome'] + " - " + refRome['metadata']['libelle_rome']})
|
439 |
return sorted(allRome, key=lambda element:element["value"])
|
440 |
|
|
|
|
|
|
|
|
|
441 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
|
443 |
theme_toggle = dmc.Tooltip(
|
444 |
dmc.ActionIcon(
|
|
|
605 |
|
606 |
#app = Dash(__name__, external_scripts=external_scripts, external_stylesheets=dmc.styles.ALL, on_error=custom_error_handler)
|
607 |
app = CustomDash(__name__, server=server, external_scripts=external_scripts, external_stylesheets=dmc.styles.ALL, on_error=custom_error_handler)
|
608 |
+
cache = Cache(app.server, config={
|
609 |
+
'CACHE_TYPE': 'filesystem',
|
610 |
+
'CACHE_REDIS_URL': 'cache-directory'
|
611 |
+
})
|
612 |
+
|
613 |
+
TIMEOUT = 60
|
614 |
+
@cache.memoize(timeout=TIMEOUT)
|
615 |
+
def connexion_France_Travail():
|
616 |
+
client = Api(client_id=os.getenv('POLE_EMPLOI_CLIENT_ID'),
|
617 |
+
client_secret=os.getenv('POLE_EMPLOI_CLIENT_SECRET'))
|
618 |
+
return client
|
619 |
|
620 |
+
@cache.memoize(timeout=TIMEOUT)
|
621 |
+
def API_France_Travail(romeListArray):
|
622 |
+
client = connexion_France_Travail()
|
623 |
+
todayDate = datetime.datetime.today()
|
624 |
+
month, year = (todayDate.month-1, todayDate.year) if todayDate.month != 1 else (12, todayDate.year-1)
|
625 |
+
start_dt = todayDate.replace(day=1, month=month, year=year)
|
626 |
+
end_dt = datetime.datetime.today()
|
627 |
+
results = []
|
628 |
+
for k in romeListArray:
|
629 |
+
if k[0:1] == ' ':
|
630 |
+
k = k[1:]
|
631 |
+
params = {"motsCles": k.replace('/', '').replace('-', '').replace(',', '').replace(' ', ','),'minCreationDate': dt_to_str_iso(start_dt),'maxCreationDate': dt_to_str_iso(end_dt),'range':'0-149'}
|
632 |
+
try:
|
633 |
+
search_on_big_data = client.search(params=params)
|
634 |
+
results += search_on_big_data["resultats"]
|
635 |
+
except:
|
636 |
+
print("Il n'y a pas d'offres d'emploi.")
|
637 |
+
|
638 |
+
results_df = pd.DataFrame(results)
|
639 |
+
return results_df
|
640 |
+
|
641 |
app.layout = dmc.MantineProvider(
|
642 |
[
|
643 |
html.Div(
|