-
Notifications
You must be signed in to change notification settings - Fork 0
/
eia.py
37 lines (25 loc) · 969 Bytes
/
eia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import requests
import pandas as pd
import datetime
import numpy as np
from io import StringIO, BytesIO
######### 美国能源信息署 #########
EIA_HEADERS = {
"Accept": "application/json, text/plain, */*",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Accept-Encoding": "gzip, deflate, br",
"Cache-Control": "no-cache",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Host": "www.eia.gov",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0",
}
def update_eia_weekly_us_crude_oil_production_ddata():
se = requests.session()
url = 'https://www.eia.gov/dnav/pet/hist_xls/WCRFPUS2w.xls'
r = se.get(url, verify=False, headers=EIA_HEADERS)
df = pd.read_excel(BytesIO(r.content), sheet_name='Data 1')
print(df)
if __name__=="__main__":
update_eia_weekly_us_crude_oil_production_ddata()
pass