VapingChatbotcopy / List_Sharepoint.py
JSAV's picture
Update List_Sharepoint.py
97efe92
raw
history blame
No virus
1.49 kB
from Autenticacion_sharepoint import auth_sharepoint
import json
context=auth_sharepoint()
def upload_list_sharepoint(tel,name,message,respuesta):
list = context.web.lists.get_by_title("Development_Vaping") #CONECTAMOS A LA LISTA
# Define la nueva interacci贸n
new_interaction = f"""[{"from":{"role":1},"text":"{message}"},
{"from":{"role":0},"text":"{respuesta}"}]"""
# Busca en la lista un elemento con el mismo User_ID
items = list.get_items()
context.load(items)
context.execute_query()
for item in items:
if item.properties['User_ID'] == tel:
# Si el elemento existe, obt茅n el contenido actual
current_content = json.loads(item.properties['Content'], strict=False)
# Agrega la nueva interacci贸n a las actividades actuales
current_content['activities'].extend(json.loads(new_interaction, strict=False))
# Actualiza el campo Content con las nuevas actividades
item.set_property('Content', json.dumps(current_content, ensure_ascii=False))
item.update()
context.execute_query()
return
# Si el elemento no existe, crea uno nuevo
conv = {
"User_Name":f"{name}",
"User_ID": f"{tel}",
"Content": f"""{"activities":[{new_interaction}]}"""
}
# Agrega un elemento a la lista
list.add_item(conv)
list.execute_query()