Continuously sending data to the Arduino cloud

Hello all !
I want to send, via a Python script, the value of the Safran stock retrieved from the Boursorama website to the Arduino Cloud.
I managed to code the script below, but the sending only occurs once

import logging
import sys
import time
sys.path.append("lib")
from arduino_iot_cloud import ArduinoCloudClient
import requests
from bs4 import BeautifulSoup

DEVICE_ID = b"xxx"
SECRET_KEY = b"xxx"

def logging_func():
    logging.basicConfig(
        datefmt="%H:%M:%S",
        format="%(asctime)s.%(msecs)03d %(message)s",
        level=logging.INFO,
    )

def get_value_from_boursorama():
    requete = requests.get("https://www.boursorama.com/cours/1rPSAF/")
    page = requete.content
    soup = BeautifulSoup(page, 'lxml')
    h1 = soup.find("span", {"class": "c-instrument c-instrument--last"})
    return h1.string

if __name__ == "__main__":
    logging_func()
    client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY)
    client.register('datavalue')
    client['datavalue'] = float(get_value_from_boursorama())
    client.start()

I'm a beginner in programming, and the API documentation isn't clear to me. Does the API allow this? If so, how?

Thank you in advance :slight_smile:

look at the example

scrapping stock price out of boursorama web site is likely not in line with their T&Cs (and your bot is possibly going to be blocked). you should get a proper feed.

Thank you J-M-L :slight_smile:
I updated the script as well and it works!

import logging
import sys
import time
sys.path.append("lib")
from arduino_iot_cloud import ArduinoCloudClient
from arduino_iot_cloud import Task
import requests
from bs4 import BeautifulSoup

DEVICE_ID = b"xxx"
SECRET_KEY = b"xxx"

def logging_func():
    logging.basicConfig(
        datefmt="%H:%M:%S",
        format="%(asctime)s.%(msecs)03d %(message)s",
        level=logging.INFO,
    )

def get_value_from_boursorama():
    requete = requests.get("https://www.boursorama.com/cours/1rPSAF/")
    page = requete.content
    soup = BeautifulSoup(page, 'lxml')
    h1 = soup.find("span", {"class": "c-instrument c-instrument--last"})
    return h1.string

def user_task(client):
    client['datavalue'] = float(get_value_from_boursorama())

if __name__ == "__main__":
    logging_func()
    client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY)
    client.register('datavalue')
    #client['datavalue'] = float(get_value_from_boursorama())
    client.register(Task("user_task", on_run=user_task, interval=60.0))
    client.start()

You're right, I'm using this solution temporarily until I find a permanent one

Glad it worked out!