US stock futures data from CNN

CNN website provides a good snapshot of US stock futures market, which is great information if you are trading in stocks. I wanted to have that information handy on my dashboard, so I created a custom_component to scrape all the stock futures information from the page (I explored the scrape sensor, but it did not work). If you are interested, here’s the code (with lot of assistance from @amelchio) :

https://github.com/arsaboo/homeassistant-config/blob/master/custom_components/sensor/futures_cnn.py

To use the sensor, place the file in \custom_components\sensor\ directory and add the following in your configuration.yaml

sensor:
  - platform: futures_cnn
    resources:
      - sp
      - sp_change_pct
      - sp_change
      - dow
      - dow_change_pct
      - dow_change
      - nasdaq
      - nasdaq_change_pct
      - nasdaq_change

Here’s how these sensors appear (after you add them to a group):

If you have any thoughts on improving the code, I am all ears.

1 Like

Thanks a bunch. I was using BS4 but had a lot of trouble on Bloomberg and CNN presumably because of the dynamic content. After 45 min of struggling and failing to scrape using BS4 I came to look at yours and see that you already done all the work. I look forward to reading the code to see how you implemented it but it works perfectly (until CNN changes something) :slight_smile:

File not available any more

The updated code is homeassistant-config/sensor.py at 53c998986fbe84d793a0b174757154ab30e676e4 · arsaboo/homeassistant-config · GitHub

I’m trying to add this component (thanks for creating it!) but I’m getting an error.

I put the futures_cnn.py file on the server in this location /config/custom_components/sensor/futures_cnn.py

After I restart, I’m seeing the following error in the server control logs
Platform error sensor.futures_cnn - Integration 'futures_cnn' not found.

My /config/configuration.yaml has the following for entry:

sensor:
  - platform: time_date
    display_options:
      - "time"
  - platform: futures_cnn
    resources:
      - sp
      - sp_change_pct
      - sp_change
      - dow
      - dow_change_pct
      - dow_change
      - nasdaq
      - nasdaq_change_pct
      - nasdaq_change

Should there be a manifest.json file? What am I doing wrong? Thanks!

Yes, there should be a manifest.json. But I have not had the time to update the sensor. I will take a look at it soon.