# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: ~/j-n/venv_f-s python3 finance-stuff
#     language: python
#     name: python3_finance-stuff
# ---

from bs4 import BeautifulSoup
import requests
import re
from datetime import datetime
from decimal import Decimal

result = requests.get("http://www.cboe.com/data/current-market-statistics/cboe-daily-market-statistics")

c = result.content

soup = BeautifulSoup(c, 'html.parser')

# +
metadata = {}
metadata['exchange'] = 'CBOE'
metadata['currency'] = 'XXX'

for tag in soup.find_all(text=re.compile('Market Summary for')):
    metadata['date'] = datetime.strptime(tag.findParent().text.strip().splitlines()[-1].strip() + ' 23:55:55', '%A, %B %m, %Y %H:%M:%S')




# +
for tag in soup.find_all(text=re.compile('VIX - CBOE Volatility Index', re.DOTALL)):
    nextrow = tag.findNext('tr')
    verynextrow = tag.findNext('tr').findNext('tr')

headers = nextrow.findAll('td')
quotes = verynextrow.findAll('td')

#print(headers, quotes)

data = {}
i = 0
for header in headers:
    data[header.text.strip().lower()] = Decimal(quotes[i].text.strip())
    #print(i, header.text.strip().lower())
    i += 1

# -

print(metadata, data)

StarcoderdataJupyterScriptsDedupFiltered