import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import math
import re
from bs4 import BeautifulSoup
import requests

# Read in daily temperatures
url = "https://www.usclimatedata.com/climate/provo/utah/united-states/usut0208/2019/1"
weatherdat = pd.read_html(url)

len(weatherdat)

temps = weatherdat[3]
temps.shape
temps.head(5)

def getDat(month):
  url = "https://www.usclimatedata.com/climate/provo/utah/united-states/usut0208/2019/"+month
  weatherdat = pd.read_html(url)
  return(weatherdat[3])

Jandat = getDat("1")
Febdat = getDat("2")

JanFebdat = pd.concat([Jandat,Febdat],axis = 0)
JanFebdat.shape

# All 12 months 
weather2019 = pd.DataFrame()
for thismonth in range(12):
  curmonth = str(thismonth+1)
  curdat = getDat(curmonth)
  weather2019 = pd.concat([weather2019, curdat],axis=0)

weather2019.shape
weather2019.iloc[241,:]
weather2019.to_csv("weather2019.csv",index=False)

