global-macro-data 0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- global_macro_data-0.1/PKG-INFO +16 -0
- global_macro_data-0.1/README.md +1 -0
- global_macro_data-0.1/global_macro_data/__init__.py +1 -0
- global_macro_data-0.1/global_macro_data/data.py +73 -0
- global_macro_data-0.1/global_macro_data.egg-info/PKG-INFO +16 -0
- global_macro_data-0.1/global_macro_data.egg-info/SOURCES.txt +9 -0
- global_macro_data-0.1/global_macro_data.egg-info/dependency_links.txt +1 -0
- global_macro_data-0.1/global_macro_data.egg-info/requires.txt +2 -0
- global_macro_data-0.1/global_macro_data.egg-info/top_level.txt +1 -0
- global_macro_data-0.1/setup.cfg +4 -0
- global_macro_data-0.1/setup.py +31 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: global_macro_data
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Global Macro Data
|
|
5
|
+
Home-page: https://github.com/Yangbo-Wang/global_macro_data
|
|
6
|
+
Author: Yangbo Wang
|
|
7
|
+
Author-email: wangyangbo2003@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: pandas
|
|
15
|
+
|
|
16
|
+
# Global Macro Data
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Global Macro Data
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .data import get_data
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import os
|
|
4
|
+
import io
|
|
5
|
+
|
|
6
|
+
CSV_URL = "https://www.globalmacrodata.com/GMD.csv"
|
|
7
|
+
|
|
8
|
+
def get_data(cache=True, cache_dir="data/", filename=None, start_year=None, end_year=None, country=None, ISO3=None):
|
|
9
|
+
"""
|
|
10
|
+
Download global macroeconomic data with optional caching and filtering.
|
|
11
|
+
|
|
12
|
+
Parameters:
|
|
13
|
+
cache (bool): Whether to use cached data if available. Default is True.
|
|
14
|
+
cache_dir (str): Directory to store cached data. Default is "data/".
|
|
15
|
+
filename (str): Custom filename for the cached file. Default is "GMD_latest.csv".
|
|
16
|
+
start_year (int): Filter data from this starting year (inclusive).
|
|
17
|
+
end_year (int): Filter data up to this ending year (inclusive).
|
|
18
|
+
country (str or list): Filter data by country name(s).
|
|
19
|
+
ISO3 (str or list): Filter data by ISO3 country code(s).
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
pandas.DataFrame: Filtered dataset.
|
|
23
|
+
"""
|
|
24
|
+
if cache:
|
|
25
|
+
if not os.path.exists(cache_dir):
|
|
26
|
+
os.makedirs(cache_dir)
|
|
27
|
+
|
|
28
|
+
if filename is None:
|
|
29
|
+
filename = "GMD_latest.csv"
|
|
30
|
+
|
|
31
|
+
file_path = os.path.join(cache_dir, filename)
|
|
32
|
+
|
|
33
|
+
# If cache exists, load the data
|
|
34
|
+
if os.path.exists(file_path):
|
|
35
|
+
print(f"Using cached data: {file_path}")
|
|
36
|
+
df = pd.read_csv(file_path)
|
|
37
|
+
else:
|
|
38
|
+
# Download the data
|
|
39
|
+
print(f"Downloading data from {CSV_URL} ...")
|
|
40
|
+
response = requests.get(CSV_URL)
|
|
41
|
+
|
|
42
|
+
if response.status_code == 200:
|
|
43
|
+
df = pd.read_csv(io.StringIO(response.text))
|
|
44
|
+
df.to_csv(file_path, index=False)
|
|
45
|
+
print(f"Data cached at: {file_path}")
|
|
46
|
+
else:
|
|
47
|
+
raise Exception(f"Download failed, HTTP status code: {response.status_code}")
|
|
48
|
+
else:
|
|
49
|
+
# Download fresh data
|
|
50
|
+
print(f"Downloading fresh data from {CSV_URL} ...")
|
|
51
|
+
response = requests.get(CSV_URL)
|
|
52
|
+
if response.status_code == 200:
|
|
53
|
+
df = pd.read_csv(io.StringIO(response.text))
|
|
54
|
+
else:
|
|
55
|
+
raise Exception(f"Download failed, HTTP status code: {response.status_code}")
|
|
56
|
+
|
|
57
|
+
# Apply filtering
|
|
58
|
+
if start_year is not None:
|
|
59
|
+
df = df[df['year'] >= start_year]
|
|
60
|
+
if end_year is not None:
|
|
61
|
+
df = df[df['year'] <= end_year]
|
|
62
|
+
if country is not None:
|
|
63
|
+
if isinstance(country, list):
|
|
64
|
+
df = df[df['countryname'].isin(country)]
|
|
65
|
+
else:
|
|
66
|
+
df = df[df['countryname'] == country]
|
|
67
|
+
if ISO3 is not None:
|
|
68
|
+
if isinstance(ISO3, list):
|
|
69
|
+
df = df[df['ISO3'].isin(ISO3)]
|
|
70
|
+
else:
|
|
71
|
+
df = df[df['ISO3'] == ISO3]
|
|
72
|
+
|
|
73
|
+
return df
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: global_macro_data
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Global Macro Data
|
|
5
|
+
Home-page: https://github.com/Yangbo-Wang/global_macro_data
|
|
6
|
+
Author: Yangbo Wang
|
|
7
|
+
Author-email: wangyangbo2003@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: pandas
|
|
15
|
+
|
|
16
|
+
# Global Macro Data
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
global_macro_data/__init__.py
|
|
4
|
+
global_macro_data/data.py
|
|
5
|
+
global_macro_data.egg-info/PKG-INFO
|
|
6
|
+
global_macro_data.egg-info/SOURCES.txt
|
|
7
|
+
global_macro_data.egg-info/dependency_links.txt
|
|
8
|
+
global_macro_data.egg-info/requires.txt
|
|
9
|
+
global_macro_data.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
global_macro_data
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
def read_readme():
|
|
4
|
+
if os.path.exists("README.md"):
|
|
5
|
+
with open("README.md", "r", encoding="utf-8") as f:
|
|
6
|
+
return f.read()
|
|
7
|
+
return "Global Macro Data package"
|
|
8
|
+
|
|
9
|
+
from setuptools import setup, find_packages
|
|
10
|
+
|
|
11
|
+
setup(
|
|
12
|
+
name="global_macro_data",
|
|
13
|
+
version="0.1",
|
|
14
|
+
packages=find_packages(),
|
|
15
|
+
install_requires=[
|
|
16
|
+
"requests",
|
|
17
|
+
"pandas",
|
|
18
|
+
],
|
|
19
|
+
author="Yangbo Wang",
|
|
20
|
+
author_email="wangyangbo2003@gmail.com",
|
|
21
|
+
description="Global Macro Data",
|
|
22
|
+
long_description=open("README.md", encoding="utf-8").read(),
|
|
23
|
+
long_description_content_type="text/markdown",
|
|
24
|
+
url="https://github.com/Yangbo-Wang/global_macro_data",
|
|
25
|
+
classifiers=[
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"License :: OSI Approved :: MIT License",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
],
|
|
30
|
+
python_requires=">=3.6",
|
|
31
|
+
)
|