Skip to content

Commit

Permalink
Update import_inpn_media.py
Browse files Browse the repository at this point in the history
  • Loading branch information
geobrun authored May 31, 2024
1 parent 14614a7 commit 6763205
Showing 1 changed file with 44 additions and 38 deletions.
82 changes: 44 additions & 38 deletions data/scripts/import_inpn_media/import_inpn_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,45 +84,51 @@ def process_media(cur, cd_ref, media):
# Test si média existe déjà en base
runquery(cur, QUERY_SELECT_TESTEXISTS, (m_obj.cd_ref, m_obj.url, SOURCE))
nb_r = cur.fetchall()

if nb_r[0][0] > 0:
# Mise à jour au cas ou les données
# licence/légende/copyright aient changées
print(f"\t{m_obj}, Action : UPDATE")
runquery(
cur,
QUERY_UPDATE_TMEDIA,
(
m_obj.titre,
m_obj.auteur,
m_obj.desc_media,
m_obj.licence,
m_obj.cd_ref,
m_obj.url,
SOURCE,
),
True,
)

# Test si l'URL du média courant n'est pas morte
r = requests.get(m_obj.url)
if r.status_code == 200:

if nb_r[0][0] > 0:
# Mise à jour au cas ou les données
# licence/légende/copyright aient changées
print(f"\t{m_obj}, Action : UPDATE")
runquery(
cur,
QUERY_UPDATE_TMEDIA,
(
m_obj.titre,
m_obj.auteur,
m_obj.desc_media,
m_obj.licence,
m_obj.cd_ref,
m_obj.url,
SOURCE,
),
True,
)
else:
# Si le média n'existe pas insertion en base
print(f"\t{m_obj}, Action : INSERT")
runquery(
cur,
QUERY_INSERT_TMEDIA,
(
m_obj.cd_ref,
m_obj.titre,
m_obj.url,
m_obj.auteur,
m_obj.desc_media,
2,
SOURCE,
m_obj.licence,
),
True,
)
DB_CONNEXION.commit()

else:
# Si le média n'existe pas insertion en base
print(f"\t{m_obj}, Action : INSERT")
runquery(
cur,
QUERY_INSERT_TMEDIA,
(
m_obj.cd_ref,
m_obj.titre,
m_obj.url,
m_obj.auteur,
m_obj.desc_media,
2,
SOURCE,
m_obj.licence,
),
True,
)
DB_CONNEXION.commit()

print(f"\tERREUR : l'URL du média {m_obj.url} retourne le code HTTP {r.status_code} !")

# SCRIPT
try:
Expand Down

0 comments on commit 6763205

Please sign in to comment.