cbar-rates 1.2.0__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.
@@ -0,0 +1,19 @@
1
+ cbar-rates
2
+ =====
3
+
4
+ v1.2.0 (2024-12-02)
5
+ -----
6
+ * Ensured that the order of currencies in the "currencies" dictionary matches the order specified in the input currencies list by using `OrderedDict`.
7
+
8
+ v1.1.0 (2024-12-01)
9
+ -----
10
+ * Added functionality to retrieve CBAR rates with the difference between values for two different dates.
11
+
12
+ v1.0.1 (2024-11-25)
13
+ -----
14
+ * Refactored type hints for better clarity and consistency.
15
+ * Added validation to raise TypeError if currencies is not a list of strings.
16
+
17
+ v1.0.0 (2024-11-24)
18
+ -----
19
+ * Initial release.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Tahir Jalilov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ include CHANGES.md
2
+ include LICENSE.md
3
+ include MANIFEST.in
4
+ include README.md
5
+ recursive-include tests *.py
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.1
2
+ Name: cbar-rates
3
+ Version: 1.2.0
4
+ Summary: Python library to work with AZN (Azerbaijani manat) official rates
5
+ Author-email: Tahir Jalilov <tahir.jalilov@gmail.com>
6
+ Project-URL: Homepage, https://github.com/TahirJalilov/cbar-rates/
7
+ Project-URL: Repository, https://github.com/TahirJalilov/cbar-rates/
8
+ Project-URL: Issues, https://github.com/TahirJalilov/cbar-rates/issues
9
+ Project-URL: Changelog, https://github.com/TahirJalilov/cbar-rates/blob/main/CHANGES.md
10
+ Keywords: cbar-rates,AZN,Azerbaijan,AZN-Rates,CBAR,Manat,Mezenne
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Information Technology
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: Implementation :: CPython
26
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
27
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
28
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.7
31
+ Description-Content-Type: text/markdown
32
+ License-File: LICENSE.md
33
+ Requires-Dist: typing_extensions>=4.7.0; python_version < "3.9"
34
+ Requires-Dist: requests>=2.20.0
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest>=7.4.4; extra == "dev"
37
+
38
+ # CBAR Rates
39
+
40
+ A Python library to work with Azerbaijani manat (AZN) official exchange rates based on [CBAR](https://cbar.az/currency/rates?language=en) (The Central Bank of the Republic of Azerbaijan).
41
+
42
+ ## Features
43
+ - Retrieve official CBAR exchange rates for the Azerbaijani manat (AZN).
44
+ - Compare exchange rates between two dates and calculate differences.
45
+ - Filter results by specific currency codes (e.g., USD, EUR).
46
+
47
+ ## Requirements
48
+ - Python 3.7 or higher
49
+ - `requests` library
50
+
51
+ ## Installation
52
+
53
+ Install the library using pip:
54
+
55
+ ```bash
56
+ pip install cbar-rates --upgrade
57
+ ```
58
+
59
+ For isolated installations, use a virtual environment:
60
+
61
+ ```bash
62
+ python3 -m venv venv
63
+ source venv/bin/activate # On Windows: venv\Scripts\activate
64
+ pip install cbar-rates
65
+ ```
66
+
67
+ ## Examples
68
+
69
+ ### Usage of `get_rates()`
70
+ ```python
71
+ from datetime import date
72
+ import cbar
73
+
74
+ rates_date = date.today()
75
+ currencies = ["USD", "EUR"]
76
+
77
+ rates = cbar.get_rates(rates_date, currencies)
78
+
79
+ print(rates)
80
+ # Output:
81
+ {
82
+ "date": "18.11.2024",
83
+ "currencies": {
84
+ "USD": {
85
+ "nominal": "1",
86
+ "rate": 1.7
87
+ },
88
+ "EUR": {
89
+ "nominal": "1",
90
+ "rate": 1.7919
91
+ },
92
+ }
93
+ }
94
+ ```
95
+
96
+ ### Usage of `get_rates_with_diff()`
97
+ ```python
98
+ from datetime import date
99
+ import cbar
100
+
101
+ previous_date = date(2024, 11, 25)
102
+ date_ = date(2024, 11, 26)
103
+ currencies = ["USD", "EUR"]
104
+
105
+ rates = cbar.get_rates_with_diff(previous_date, date_, currencies)
106
+
107
+ print(rates)
108
+ # Output:
109
+ {
110
+ "previous_date": "25.11.2024",
111
+ "date": "26.11.2024",
112
+ "currencies": {
113
+ "USD": {
114
+ "nominal": "1",
115
+ "previous_rate": 1.7,
116
+ "rate": 1.7,
117
+ "difference": 0.0,
118
+ },
119
+ "EUR": {
120
+ "nominal": "1",
121
+ "previous_rate": 1.7814,
122
+ "rate": 1.7815,
123
+ "difference": 0.0001,
124
+ },
125
+ }
126
+ }
127
+ ```
128
+
129
+ You can find all available currency codes on the [CBAR website](https://www.cbar.az/currency/rates?language=en)
130
+
131
+ ## License
132
+ This project is licensed under the [MIT License](https://github.com/TahirJalilov/cbar-rates?tab=MIT-1-ov-file#MIT-1-ov-file).
@@ -0,0 +1,95 @@
1
+ # CBAR Rates
2
+
3
+ A Python library to work with Azerbaijani manat (AZN) official exchange rates based on [CBAR](https://cbar.az/currency/rates?language=en) (The Central Bank of the Republic of Azerbaijan).
4
+
5
+ ## Features
6
+ - Retrieve official CBAR exchange rates for the Azerbaijani manat (AZN).
7
+ - Compare exchange rates between two dates and calculate differences.
8
+ - Filter results by specific currency codes (e.g., USD, EUR).
9
+
10
+ ## Requirements
11
+ - Python 3.7 or higher
12
+ - `requests` library
13
+
14
+ ## Installation
15
+
16
+ Install the library using pip:
17
+
18
+ ```bash
19
+ pip install cbar-rates --upgrade
20
+ ```
21
+
22
+ For isolated installations, use a virtual environment:
23
+
24
+ ```bash
25
+ python3 -m venv venv
26
+ source venv/bin/activate # On Windows: venv\Scripts\activate
27
+ pip install cbar-rates
28
+ ```
29
+
30
+ ## Examples
31
+
32
+ ### Usage of `get_rates()`
33
+ ```python
34
+ from datetime import date
35
+ import cbar
36
+
37
+ rates_date = date.today()
38
+ currencies = ["USD", "EUR"]
39
+
40
+ rates = cbar.get_rates(rates_date, currencies)
41
+
42
+ print(rates)
43
+ # Output:
44
+ {
45
+ "date": "18.11.2024",
46
+ "currencies": {
47
+ "USD": {
48
+ "nominal": "1",
49
+ "rate": 1.7
50
+ },
51
+ "EUR": {
52
+ "nominal": "1",
53
+ "rate": 1.7919
54
+ },
55
+ }
56
+ }
57
+ ```
58
+
59
+ ### Usage of `get_rates_with_diff()`
60
+ ```python
61
+ from datetime import date
62
+ import cbar
63
+
64
+ previous_date = date(2024, 11, 25)
65
+ date_ = date(2024, 11, 26)
66
+ currencies = ["USD", "EUR"]
67
+
68
+ rates = cbar.get_rates_with_diff(previous_date, date_, currencies)
69
+
70
+ print(rates)
71
+ # Output:
72
+ {
73
+ "previous_date": "25.11.2024",
74
+ "date": "26.11.2024",
75
+ "currencies": {
76
+ "USD": {
77
+ "nominal": "1",
78
+ "previous_rate": 1.7,
79
+ "rate": 1.7,
80
+ "difference": 0.0,
81
+ },
82
+ "EUR": {
83
+ "nominal": "1",
84
+ "previous_rate": 1.7814,
85
+ "rate": 1.7815,
86
+ "difference": 0.0001,
87
+ },
88
+ }
89
+ }
90
+ ```
91
+
92
+ You can find all available currency codes on the [CBAR website](https://www.cbar.az/currency/rates?language=en)
93
+
94
+ ## License
95
+ This project is licensed under the [MIT License](https://github.com/TahirJalilov/cbar-rates?tab=MIT-1-ov-file#MIT-1-ov-file).
@@ -0,0 +1,5 @@
1
+ from cbar.core import get_rates, get_rates_with_diff
2
+
3
+ __all__ = ["get_rates", "get_rates_with_diff"]
4
+
5
+ __version__ = "1.2.0"
@@ -0,0 +1,173 @@
1
+ """Core components for cbar rates."""
2
+
3
+ import requests
4
+ import xml.etree.ElementTree as ET
5
+ from collections import OrderedDict
6
+ from datetime import date, timedelta
7
+ from typing import Dict, List, Optional, Union
8
+
9
+
10
+ def _get_cbar_data(
11
+ date_: date,
12
+ ) -> Dict[str, Union[str, Dict[str, Dict[str, Union[float, str]]]]]:
13
+ """Get xml file with rates from CBAR parse it and return as dictionary.
14
+
15
+ Args:
16
+ date_ (date): Date of the rates.
17
+
18
+ Returns:
19
+ dict: Parsed data including the date and currency rates.
20
+
21
+ Raises:
22
+ HTTPError: If a request error occurs.
23
+ """
24
+ request_url = "https://cbar.az/currencies/{}.xml".format(date_.strftime("%d.%m.%Y"))
25
+ response = requests.get(request_url, timeout=10)
26
+ response.raise_for_status()
27
+ tree = ET.fromstring(response.text)
28
+ currencies = {}
29
+ for currency in tree.iter("Valute"):
30
+ currencies[currency.get("Code")] = {
31
+ "nominal": currency.find("Nominal").text,
32
+ "rate": float(currency.find("Value").text),
33
+ }
34
+
35
+ cbar_data = {"date": tree.attrib.get("Date"), "currencies": currencies}
36
+
37
+ return cbar_data
38
+
39
+
40
+ def get_rates(
41
+ date_: Optional[date] = None, currencies: Optional[List[str]] = None
42
+ ) -> Dict[str, Union[str, Dict[str, Dict[str, Union[int, float]]]]]:
43
+ """Get exchange rates for a given date and optionally filter by currency codes.
44
+
45
+ Args:
46
+ date_ (Optional[date]): Date of the rates. Defaults to today's date.
47
+ currencies (Optional[List[str]]): List of ISO 4217 currency codes
48
+ (https://www.cbar.az/currency/rates?language=en) to filter results.
49
+ Defaults to all available currencies.
50
+
51
+ Returns:
52
+ OrderedDict: Exchange rates structured as:
53
+ {
54
+ "date": "18.11.2024",
55
+ "currencies": {
56
+ "USD": {
57
+ "nominal": "1",
58
+ "rate": 1.7
59
+ },
60
+ "EUR": {
61
+ "nominal": "1",
62
+ "rate": 1.85
63
+ },
64
+ }
65
+ }
66
+ Raises:
67
+ TypeError: If currencies is not a list of strings.
68
+ """
69
+ if date_ is None:
70
+ date_ = date.today()
71
+
72
+ rates = _get_cbar_data(date_)
73
+
74
+ if currencies is not None:
75
+ if not isinstance(currencies, list) or not all(
76
+ isinstance(s, str) for s in currencies
77
+ ):
78
+ raise TypeError(
79
+ "Currencies must be a list of strings (ISO 4217 currency codes)."
80
+ )
81
+
82
+ currencies_set = {s.upper() for s in currencies}
83
+
84
+ filtered_currencies = {
85
+ currency: rates["currencies"].get(currency)
86
+ for currency in currencies_set
87
+ if currency in rates["currencies"]
88
+ }
89
+
90
+ rates["currencies"] = OrderedDict(
91
+ (currency, filtered_currencies[currency]) for currency in currencies_set
92
+ )
93
+
94
+ return rates
95
+
96
+
97
+ def get_rates_with_diff(
98
+ previous_date: Optional[date] = None,
99
+ date_: Optional[date] = None,
100
+ currencies: Optional[List[str]] = None,
101
+ ) -> Dict[str, Union[str, Dict[str, Dict[str, Union[int, float]]]]]:
102
+ """Get exchange rates with difference for given dates and optionally filter by currency codes.
103
+
104
+ Args:
105
+ previous_date (Optional[date]): Previous date of the rates. Defaults to date_ - 1 day.
106
+ date_ (Optional[date]): Date of the rates. Defaults to previous_date + 1 day.
107
+ If both previous_date and date_ are None, today - 1 day and today.
108
+ currencies (Optional[List[str]]): List of ISO 4217 currency codes
109
+ (https://www.cbar.az/currency/rates?language=en) to filter results.
110
+ Defaults to all available currencies.
111
+
112
+ Returns:
113
+ OrderedDict: Exchange rates with differences structured as:
114
+ {
115
+ "previous_date": "25.11.2024",
116
+ "date": "26.11.2024",
117
+ "currencies": {
118
+ "USD": {
119
+ "nominal": "1",
120
+ "previous_rate": 1.7,
121
+ "rate": 1.7,
122
+ "difference": 0.0,
123
+ },
124
+ "EUR": {
125
+ "nominal": "1",
126
+ "previous_rate": 1.7814,
127
+ "rate": 1.7815,
128
+ "difference": 0.0001,
129
+ },
130
+ }
131
+ }
132
+ Raises:
133
+ TypeError: If currencies is not a list of strings.
134
+ ValueError: If date inputs are inconsistent.
135
+ """
136
+
137
+ if previous_date is None and date_ is None:
138
+ date_ = date.today()
139
+ previous_date = date_ - timedelta(days=1)
140
+ elif previous_date is not None and date_ is None:
141
+ date_ = previous_date + timedelta(days=1)
142
+ elif previous_date is None and date_ is not None:
143
+ previous_date = date_ - timedelta(days=1)
144
+
145
+ if previous_date >= date_:
146
+ raise ValueError("previous_date must be earlier than date_.")
147
+
148
+ previous_result = get_rates(previous_date, currencies)
149
+ result = get_rates(date_, currencies)
150
+
151
+ rates = {
152
+ "previous_date": previous_result["date"],
153
+ "date": result["date"],
154
+ "currencies": {},
155
+ }
156
+
157
+ for currency, data in previous_result["currencies"].items():
158
+ previous_rate = data["rate"]
159
+ rate = result["currencies"][currency]["rate"]
160
+ difference = rate - previous_rate
161
+
162
+ rates["currencies"][currency] = {
163
+ "nominal": data["nominal"],
164
+ "previous_rate": previous_rate,
165
+ "rate": rate,
166
+ "difference": round(difference, 4),
167
+ }
168
+
169
+ rates["currencies"] = OrderedDict(
170
+ (currency, rates["currencies"][currency]) for currency in currencies
171
+ )
172
+
173
+ return rates
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.1
2
+ Name: cbar-rates
3
+ Version: 1.2.0
4
+ Summary: Python library to work with AZN (Azerbaijani manat) official rates
5
+ Author-email: Tahir Jalilov <tahir.jalilov@gmail.com>
6
+ Project-URL: Homepage, https://github.com/TahirJalilov/cbar-rates/
7
+ Project-URL: Repository, https://github.com/TahirJalilov/cbar-rates/
8
+ Project-URL: Issues, https://github.com/TahirJalilov/cbar-rates/issues
9
+ Project-URL: Changelog, https://github.com/TahirJalilov/cbar-rates/blob/main/CHANGES.md
10
+ Keywords: cbar-rates,AZN,Azerbaijan,AZN-Rates,CBAR,Manat,Mezenne
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Information Technology
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: Implementation :: CPython
26
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
27
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
28
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.7
31
+ Description-Content-Type: text/markdown
32
+ License-File: LICENSE.md
33
+ Requires-Dist: typing_extensions>=4.7.0; python_version < "3.9"
34
+ Requires-Dist: requests>=2.20.0
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest>=7.4.4; extra == "dev"
37
+
38
+ # CBAR Rates
39
+
40
+ A Python library to work with Azerbaijani manat (AZN) official exchange rates based on [CBAR](https://cbar.az/currency/rates?language=en) (The Central Bank of the Republic of Azerbaijan).
41
+
42
+ ## Features
43
+ - Retrieve official CBAR exchange rates for the Azerbaijani manat (AZN).
44
+ - Compare exchange rates between two dates and calculate differences.
45
+ - Filter results by specific currency codes (e.g., USD, EUR).
46
+
47
+ ## Requirements
48
+ - Python 3.7 or higher
49
+ - `requests` library
50
+
51
+ ## Installation
52
+
53
+ Install the library using pip:
54
+
55
+ ```bash
56
+ pip install cbar-rates --upgrade
57
+ ```
58
+
59
+ For isolated installations, use a virtual environment:
60
+
61
+ ```bash
62
+ python3 -m venv venv
63
+ source venv/bin/activate # On Windows: venv\Scripts\activate
64
+ pip install cbar-rates
65
+ ```
66
+
67
+ ## Examples
68
+
69
+ ### Usage of `get_rates()`
70
+ ```python
71
+ from datetime import date
72
+ import cbar
73
+
74
+ rates_date = date.today()
75
+ currencies = ["USD", "EUR"]
76
+
77
+ rates = cbar.get_rates(rates_date, currencies)
78
+
79
+ print(rates)
80
+ # Output:
81
+ {
82
+ "date": "18.11.2024",
83
+ "currencies": {
84
+ "USD": {
85
+ "nominal": "1",
86
+ "rate": 1.7
87
+ },
88
+ "EUR": {
89
+ "nominal": "1",
90
+ "rate": 1.7919
91
+ },
92
+ }
93
+ }
94
+ ```
95
+
96
+ ### Usage of `get_rates_with_diff()`
97
+ ```python
98
+ from datetime import date
99
+ import cbar
100
+
101
+ previous_date = date(2024, 11, 25)
102
+ date_ = date(2024, 11, 26)
103
+ currencies = ["USD", "EUR"]
104
+
105
+ rates = cbar.get_rates_with_diff(previous_date, date_, currencies)
106
+
107
+ print(rates)
108
+ # Output:
109
+ {
110
+ "previous_date": "25.11.2024",
111
+ "date": "26.11.2024",
112
+ "currencies": {
113
+ "USD": {
114
+ "nominal": "1",
115
+ "previous_rate": 1.7,
116
+ "rate": 1.7,
117
+ "difference": 0.0,
118
+ },
119
+ "EUR": {
120
+ "nominal": "1",
121
+ "previous_rate": 1.7814,
122
+ "rate": 1.7815,
123
+ "difference": 0.0001,
124
+ },
125
+ }
126
+ }
127
+ ```
128
+
129
+ You can find all available currency codes on the [CBAR website](https://www.cbar.az/currency/rates?language=en)
130
+
131
+ ## License
132
+ This project is licensed under the [MIT License](https://github.com/TahirJalilov/cbar-rates?tab=MIT-1-ov-file#MIT-1-ov-file).
@@ -0,0 +1,14 @@
1
+ CHANGES.md
2
+ LICENSE.md
3
+ MANIFEST.in
4
+ README.md
5
+ pyproject.toml
6
+ cbar/__init__.py
7
+ cbar/core.py
8
+ cbar_rates.egg-info/PKG-INFO
9
+ cbar_rates.egg-info/SOURCES.txt
10
+ cbar_rates.egg-info/dependency_links.txt
11
+ cbar_rates.egg-info/requires.txt
12
+ cbar_rates.egg-info/top_level.txt
13
+ tests/__init__.py
14
+ tests/test_core.py
@@ -0,0 +1,7 @@
1
+ requests>=2.20.0
2
+
3
+ [:python_version < "3.9"]
4
+ typing_extensions>=4.7.0
5
+
6
+ [dev]
7
+ pytest>=7.4.4
@@ -0,0 +1,78 @@
1
+ [build-system]
2
+ requires = ["setuptools>=65.0.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cbar-rates"
7
+ description = "Python library to work with AZN (Azerbaijani manat) official rates"
8
+ authors = [
9
+ { name = "Tahir Jalilov", email = "tahir.jalilov@gmail.com" },
10
+ ]
11
+
12
+ readme = { file = "README.md", content-type = "text/markdown" }
13
+ requires-python = ">=3.7"
14
+ keywords = ["cbar-rates", "AZN", "Azerbaijan", "AZN-Rates", "CBAR", "Manat", "Mezenne"]
15
+ classifiers = [
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: Information Technology",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.7",
24
+ "Programming Language :: Python :: 3.8",
25
+ "Programming Language :: Python :: 3.9",
26
+ "Programming Language :: Python :: 3.10",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Programming Language :: Python :: Implementation :: CPython",
31
+ "Programming Language :: Python :: Implementation :: PyPy",
32
+ "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
33
+ "Topic :: Software Development :: Libraries :: Python Modules",
34
+ "Typing :: Typed",
35
+ ]
36
+ dependencies = [
37
+ "typing_extensions >= 4.7.0; python_version < '3.9'",
38
+ "requests >= 2.20.0"
39
+ ]
40
+ dynamic = ["version"]
41
+
42
+ [project.urls]
43
+ Homepage = "https://github.com/TahirJalilov/cbar-rates/"
44
+ Repository = "https://github.com/TahirJalilov/cbar-rates/"
45
+ Issues = "https://github.com/TahirJalilov/cbar-rates/issues"
46
+ Changelog = "https://github.com/TahirJalilov/cbar-rates/blob/main/CHANGES.md"
47
+
48
+ [project.optional-dependencies]
49
+ dev = ["pytest>=7.4.4"]
50
+
51
+ [tool.setuptools.packages.find]
52
+ include = ["cbar*"]
53
+
54
+ [tool.setuptools.dynamic]
55
+ version = { attr = "cbar.__version__" }
56
+
57
+ [tool.pytest.ini_options]
58
+ pythonpath = ["."]
59
+ testpaths = ["tests"]
60
+
61
+ [tool.ruff]
62
+ line-length = 88
63
+
64
+ [tool.tox]
65
+ legacy_tox_ini = """
66
+ [tox]
67
+ minversion = 4.15.0
68
+
69
+ [testenv]
70
+ description = Run the tests with pytest
71
+ package = wheel
72
+ wheel_build_env = .pkg
73
+ changedir = tests
74
+ deps =
75
+ pytest>=6
76
+ commands =
77
+ pytest {tty:--color=yes} --basetemp="{envtmpdir}" {posargs}
78
+ """
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,58 @@
1
+ import pytest
2
+ import requests
3
+ import cbar
4
+
5
+ from datetime import date
6
+
7
+
8
+ def test_cbar_xml():
9
+ r = requests.get("https://cbar.az/currencies/18.11.2024.xml", timeout=10)
10
+
11
+ assert r.status_code == 200
12
+ assert r.text.startswith('<?xml version="1.0" encoding="UTF-8"?>')
13
+
14
+
15
+ def test_get_rates():
16
+ date_ = date(2024, 11, 18)
17
+ rates = cbar.get_rates(date_=date_, currencies=["USD"])
18
+
19
+ assert isinstance(rates, dict)
20
+ assert rates["date"] == "18.11.2024"
21
+ assert rates["currencies"] == {"USD": {"nominal": "1", "rate": 1.7}}
22
+
23
+
24
+ def test_get_rates_type_error():
25
+ with pytest.raises(
26
+ TypeError,
27
+ match="Currencies must be a list of strings \(ISO 4217 currency codes\).",
28
+ ):
29
+ cbar.get_rates(currencies=1)
30
+
31
+
32
+ def test_get_rates_with_diff():
33
+ previous_date = date(2024, 11, 25)
34
+ date_ = date(2024, 11, 26)
35
+ rates = cbar.get_rates_with_diff(
36
+ previous_date=previous_date, date_=date_, currencies=["EUR"]
37
+ )
38
+
39
+ assert isinstance(rates, dict)
40
+ assert rates["previous_date"] == "25.11.2024"
41
+ assert rates["date"] == "26.11.2024"
42
+ assert rates["currencies"] == {
43
+ "EUR": {
44
+ "nominal": "1",
45
+ "previous_rate": 1.7814,
46
+ "rate": 1.7815,
47
+ "difference": 0.0001,
48
+ }
49
+ }
50
+
51
+
52
+ def test_get_rates_with_diff_value_error():
53
+ with pytest.raises(
54
+ ValueError, match="previous_date must be earlier than date_."
55
+ ):
56
+ previous_date = date(2025, 1, 1)
57
+ date_ = date(2024, 1, 1)
58
+ cbar.get_rates_with_diff(previous_date, date_)