-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToday_oil_price.py
More file actions
38 lines (26 loc) · 975 Bytes
/
Today_oil_price.py
File metadata and controls
38 lines (26 loc) · 975 Bytes
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
37
38
import requests
import json
API_KEY = 'tYTvFTiccRfj'
PROJECT_TOKEN = 'tTXGYJn0fKOF'
RUN_TOKEN = 'tO1VzbSeYdh6'
class Data:
def __init__(self,api_key,project_token):
self.api_key = api_key
self.project_token = project_token
self.params = {
'api_key':self.api_key
}
self.get_data()
def get_data(self): #get the data from the API using token
res = requests.get(f'https://www.parsehub.com/api/v2/projects/{PROJECT_TOKEN}/last_ready_run/data', params={'api_key':API_KEY})
self.data = json.loads(res.text)
def get_today_price(self): #gets real time oil price
return self.data['price']
def get_date_price(self,date): #gets oil price and var from the lasth month
data=self.data['last_month']
for c in data:
if c['date'] == date:
return c
return '0'
data = Data(API_KEY,PROJECT_TOKEN)
print(data.get_today_price())