96 lines
3.5 KiB
Python
96 lines
3.5 KiB
Python
import GlobalVariable as MYSY_GV
|
|
from pymongo import MongoClient
|
|
from collections import Counter
|
|
|
|
import prj_common as mycommon
|
|
from unidecode import unidecode
|
|
import inspect
|
|
import sys, os
|
|
from autocorrect import Speller
|
|
from datetime import datetime
|
|
import re
|
|
import Ela_Spacy as ls
|
|
|
|
|
|
|
|
|
|
def YTUBES_ela_index_class(external_code="", source_field = ""):
|
|
try:
|
|
|
|
collection = MYSY_GV.YTUBES_dbname["mysyclass"]
|
|
|
|
print(" lalalalal1")
|
|
if( len(str(source_field)) == 0):
|
|
source_field = 'default'
|
|
|
|
print(" external_code = "+str(external_code)+ " source_field = "+str(source_field))
|
|
for doc in collection.find({"external_code":external_code}):
|
|
print(" 3333")
|
|
# Indexation du champ : video_text , donc la transcription d'une video
|
|
if (str(source_field) == "video_text"):
|
|
print(" lalalalal")
|
|
chaine = doc["video_text"]
|
|
# mycommon.myprint(" external_code = "+str(doc["external_code"])+" ==> "+str(chaine))
|
|
retval = ls.YTUBES_ela_index_record_field(chaine, str(doc["external_code"]), source_field)
|
|
|
|
'''
|
|
# Apres indexation, on met a jour la formation pour
|
|
# mettre le champ "indexe" a 1.
|
|
'''
|
|
if (retval):
|
|
# mise à jour du champ "indexed"
|
|
myobjectif = {}
|
|
myobjectif['indexed_video_text'] = '0'
|
|
|
|
ret_val2 = collection.find_and_modify(query={"external_code": external_code},
|
|
update={"$set": myobjectif}
|
|
)
|
|
|
|
if (ret_val2 and ret_val2['_id']):
|
|
mycommon.myprint("La formation indexée YTUBES (champs video_text) =" + str(ret_val2['_id']))
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
return True
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False
|
|
|
|
|
|
def YTUBES_RedText():
|
|
try:
|
|
|
|
print(" on est dans ytubes read")
|
|
Y_collection = MYSY_GV.YTUBES_dbname["mysyclass"]
|
|
|
|
|
|
|
|
nb_class_indexed = 0
|
|
for doc in Y_collection.find({'indexed_video_text': '0'}):
|
|
if ("video_text" in doc.keys()):
|
|
chaine = doc["video_text"]
|
|
#mycommon.myprint(" video_texte = " + str(doc["external_code"]) + " ==> " + str(chaine))
|
|
|
|
|
|
retval = YTUBES_ela_index_class(str(doc["external_code"]), "video_text")
|
|
# print(" apres : ela_index_all_classes_video_texte retval = " + str(retval))
|
|
|
|
if (retval is False):
|
|
mycommon.myprint("IMPOSSIBLE d'indexer la formation = " + str(doc["external_code"]))
|
|
else:
|
|
nb_class_indexed = nb_class_indexed + 1
|
|
|
|
# retval = ls.ela_index_record_field(chaine, str(doc["external_code"]))
|
|
|
|
mycommon.myprint(str(nb_class_indexed) + " ont été indexes YTUBES- champ video_text")
|
|
return True, str(nb_class_indexed) + " ont été indexes YTUBES - champ video_text "
|
|
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False |