update and eu
This commit is contained in:
parent
3bc5ba09f9
commit
24e530566c
|
@ -4,6 +4,7 @@ import re
|
|||
import demjson
|
||||
import requests
|
||||
from fake_useragent import UserAgent
|
||||
from config import config
|
||||
|
||||
# TODO need add comments
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import pandas as pd
|
||||
import numpy as np
|
||||
import re
|
||||
import io
|
||||
import demjson
|
||||
import requests
|
||||
from fake_useragent import UserAgent
|
||||
|
@ -9,25 +9,67 @@ from fake_useragent import UserAgent
|
|||
|
||||
url = {
|
||||
"eurostat": "http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/",
|
||||
"ecb": "https://sdw.ecb.europa.eu/servlet/homePageChart?from=dynamic&"
|
||||
"ecb": "https://sdw-wsrest.ecb.europa.eu/service/data/"
|
||||
}
|
||||
|
||||
class ecb_data(object):
|
||||
def __init__(self, url=url["ecb"]):
|
||||
self.url = url
|
||||
|
||||
def ecb_data():
|
||||
"""
|
||||
Full Name: Gross Domestic Product
|
||||
Description: Billions of Dollars, Quarterly, Seasonally Adjusted Annual Rate
|
||||
Return: pd.DataFrame
|
||||
"""
|
||||
tmp_url = url["fred_econ"]
|
||||
ua = UserAgent()
|
||||
request_header = {"User-Agent": ua.random}
|
||||
request_params = {
|
||||
"id": "GDP",
|
||||
"cosd": "{}".format(startdate),
|
||||
"coed": "{}".format(enddate)
|
||||
}
|
||||
r = requests.get(tmp_url, params = request_params, headers = request_header)
|
||||
data_text = r.content
|
||||
df = pd.read_csv(io.StringIO(data_text.decode('utf-8')))
|
||||
return df
|
||||
def codebook(self):
|
||||
return "please follow the ECB's codebook: https://sdw.ecb.europa.eu/browse.do?node=9691101"
|
||||
|
||||
def get_data(self,
|
||||
datacode="ICP",
|
||||
key="M.U2.N.000000.4.ANR",
|
||||
startdate="2000-01-01",
|
||||
enddate="2020-01-01"):
|
||||
"""
|
||||
"""
|
||||
tmp_url = self.url + "{}/".format(datacode) + "{}".format(key)
|
||||
ua = UserAgent()
|
||||
request_header = {"User-Agent": ua.random, 'Accept': 'text/csv'}
|
||||
request_params = {
|
||||
"startPeriod": "{}".format(startdate),
|
||||
"endPeriod": "{}".format(enddate)
|
||||
}
|
||||
r = requests.get(tmp_url, params = request_params, headers = request_header)
|
||||
data_text = r.content
|
||||
df = pd.read_csv(io.StringIO(data_text.decode('utf-8')))
|
||||
return df
|
||||
|
||||
class eurostat_data(object):
|
||||
def __init__(self, url=url["eurostat"]):
|
||||
self.url = url
|
||||
|
||||
def codebook(self):
|
||||
return "please follow the EuroStat's codebook: \nhttps://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?sort=1&dir=dic"
|
||||
|
||||
def get_data(self,
|
||||
datasetcode="nama_10_gdp",
|
||||
precision="1",
|
||||
unit="CP_MEUR",
|
||||
na_item="B1GQ",
|
||||
time="2020"):
|
||||
"""
|
||||
"""
|
||||
tmp_url = self.url + "{}".format(datasetcode)
|
||||
ua = UserAgent()
|
||||
request_header = {"User-Agent": ua.random, 'Accept': 'text/csv'}
|
||||
request_params = {
|
||||
"precision": "{}".format(precision),
|
||||
"unit": "{}".format(unit),
|
||||
"na_item": "{}".format(na_item),
|
||||
"time": "{}".format(time)
|
||||
}
|
||||
r = requests.get(tmp_url, params = request_params, headers = request_header)
|
||||
data_text = r.text
|
||||
data_json = demjson.decode(data_text)
|
||||
value = data_json['value']
|
||||
abb = data_json['dimension']['geo']['category']['index']
|
||||
abb = {abb[k]:k for k in abb}
|
||||
geo = data_json['dimension']['geo']['category']['label']
|
||||
geo_list = [abb[int(k)] for k in list(value.keys())]
|
||||
geo = [geo[k] for k in geo_list]
|
||||
df = pd.DataFrame({"Geo":geo, "{}".format(na_item): list(value.values())})
|
||||
return df
|
|
@ -1,29 +1 @@
|
|||
from CEDA.MacroEcon.cn import (
|
||||
gdp_quarterly,
|
||||
ppi_monthly,
|
||||
cpi_monthly,
|
||||
pmi_monthly,
|
||||
fai_monthly,
|
||||
hi_old_monthly,
|
||||
hi_new_monthly,
|
||||
ci_eei_monthly,
|
||||
ig_monthly,
|
||||
cgpi_monthly,
|
||||
cci_csi_cei_monthly,
|
||||
trscg_monthly,
|
||||
ms_monthly,
|
||||
ie_monthly,
|
||||
stock_monthly,
|
||||
fgr_monthly,
|
||||
ctsf_monthly,
|
||||
sao_monthly,
|
||||
fdi_monthly,
|
||||
gr_monthly,
|
||||
ti_monthly,
|
||||
nl_monthly,
|
||||
dfclc_monthly,
|
||||
fl_monthly,
|
||||
drr_monthly,
|
||||
interest_monthly,
|
||||
gdc_daily
|
||||
)
|
||||
from CEDA import *
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import requests
|
||||
|
||||
def config(http:str, https:str, auth:bool, user:str, passwd:str):
|
||||
if auth == False:
|
||||
proxies = {
|
||||
"http": "{}".format(http),
|
||||
"https": "{}".format(https)
|
||||
}
|
||||
return proxies
|
||||
if auth == True:
|
||||
proxies = {
|
||||
"http": "http://{}:{}@{}".format(user, passwd, http),
|
||||
"https": "https://{}:{}@{}".format(user, passwd, https),
|
||||
}
|
||||
return proxies
|
|
@ -28,4 +28,5 @@ python -m pip install CEDApy
|
|||
* Thanks [akshare](https://github.com/jindaxiang/akshare/)
|
||||
* Thanks [EastMoney](https://www.eastmoney.com)
|
||||
* Thanks [St.Louis Fred Reserve Bank](https://fred.stlouisfed.org/)
|
||||
* Thanks [eurostat Economic Indicators](https://ec.europa.eu/eurostat/cache/infographs/economy/desktop/index.html)
|
||||
* Thanks [eurostat Economic Indicators](https://ec.europa.eu/eurostat/cache/infographs/economy/desktop/index.html)
|
||||
* Thanks [Europen Central Bank](https://www.ecb.europa.eu)
|
Loading…
Reference in New Issue