From fa97f9b5b8025313f17b7c88e9bf44d42735bd63 Mon Sep 17 00:00:00 2001 From: "sermet.pekin" Date: Thu, 1 Aug 2024 15:16:00 +0300 Subject: [PATCH] datagroups fnc was removed --- Example_get_series_exp.ipynb | 101 +++++----- evdspy/EVDSlocal/console/menu.py | 3 +- evdspy/EVDSlocal/console/menu_async.py | 180 ++++++++++++++++++ evdspy/EVDSlocal/index_requests/datagroups.py | 10 - .../user_requests/Proxy_manager.py | 2 +- .../initial/load_commands_cmds_to_load.py | 16 +- evdspy/EVDSlocal/tests/test_categories.py | 6 +- evdspy/EVDSlocal/tests_main.py | 2 +- pyproject.toml | 2 +- 9 files changed, 240 insertions(+), 82 deletions(-) create mode 100644 evdspy/EVDSlocal/console/menu_async.py diff --git a/Example_get_series_exp.ipynb b/Example_get_series_exp.ipynb index ef3c10b..8417c6e 100644 --- a/Example_get_series_exp.ipynb +++ b/Example_get_series_exp.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "id": "08f96479-49fa-4e27-a33b-81bf55d8ad5a", "metadata": {}, "outputs": [], @@ -13,17 +13,10 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 2, "id": "0c370f8a-5883-43ce-9e47-d338e0ceedf2", "metadata": {}, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requesting... will be running now...\n" - ] - }, { "data": { "text/html": [ @@ -55,31 +48,31 @@ " 0\n", " NaN\n", " NaN\n", - " 01-01-2000\n", + " 01-01-2005\n", " \n", " \n", " 1\n", " NaN\n", " NaN\n", - " 02-01-2000\n", + " 02-01-2005\n", " \n", " \n", " 2\n", - " 0.540098\n", - " 0.542096\n", - " 03-01-2000\n", + " 1.3363\n", + " 1.8233\n", + " 03-01-2005\n", " \n", " \n", " 3\n", - " 0.540793\n", - " 0.545660\n", - " 04-01-2000\n", + " 1.3383\n", + " 1.8105\n", + " 04-01-2005\n", " \n", " \n", " 4\n", - " 0.535815\n", - " 0.552961\n", - " 05-01-2000\n", + " 1.3427\n", + " 1.7976\n", + " 05-01-2005\n", " \n", " \n", " ...\n", @@ -88,58 +81,58 @@ " ...\n", " \n", " \n", - " 8975\n", + " 7148\n", " NaN\n", " NaN\n", " 28-07-2024\n", " \n", " \n", - " 8976\n", - " 32.958600\n", - " 35.773200\n", + " 7149\n", + " 32.9586\n", + " 35.7732\n", " 29-07-2024\n", " \n", " \n", - " 8977\n", - " 32.950900\n", - " 35.711000\n", + " 7150\n", + " 32.9509\n", + " 35.7110\n", " 30-07-2024\n", " \n", " \n", - " 8978\n", - " 33.030400\n", - " 35.761200\n", + " 7151\n", + " 33.0304\n", + " 35.7612\n", " 31-07-2024\n", " \n", " \n", - " 8979\n", - " 33.083500\n", - " 35.814500\n", + " 7152\n", + " 33.0835\n", + " 35.8145\n", " 01-08-2024\n", " \n", " \n", "\n", - "

8980 rows × 3 columns

\n", + "

7153 rows × 3 columns

\n", "" ], "text/plain": [ " TP_DK_USD_A_YTL TP_DK_EUR_A_YTL Tarih\n", - "0 NaN NaN 01-01-2000\n", - "1 NaN NaN 02-01-2000\n", - "2 0.540098 0.542096 03-01-2000\n", - "3 0.540793 0.545660 04-01-2000\n", - "4 0.535815 0.552961 05-01-2000\n", + "0 NaN NaN 01-01-2005\n", + "1 NaN NaN 02-01-2005\n", + "2 1.3363 1.8233 03-01-2005\n", + "3 1.3383 1.8105 04-01-2005\n", + "4 1.3427 1.7976 05-01-2005\n", "... ... ... ...\n", - "8975 NaN NaN 28-07-2024\n", - "8976 32.958600 35.773200 29-07-2024\n", - "8977 32.950900 35.711000 30-07-2024\n", - "8978 33.030400 35.761200 31-07-2024\n", - "8979 33.083500 35.814500 01-08-2024\n", + "7148 NaN NaN 28-07-2024\n", + "7149 32.9586 35.7732 29-07-2024\n", + "7150 32.9509 35.7110 30-07-2024\n", + "7151 33.0304 35.7612 31-07-2024\n", + "7152 33.0835 35.8145 01-08-2024\n", "\n", - "[8980 rows x 3 columns]" + "[7153 rows x 3 columns]" ] }, - "execution_count": 12, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -153,14 +146,14 @@ "\n", "\"\"\" \n", "\n", - "df = get_series(ID , cache = True )\n", + "df = get_series(ID , cache = False , start_date=\"01-01-2005\" )\n", "\n", "df\n" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 3, "id": "339c0542-2c34-4443-b436-dbe03c6d4225", "metadata": {}, "outputs": [ @@ -175,11 +168,11 @@ { "data": { "text/html": [ - "
Could not convert some columns to float type...\n",
+       "
Could not convert some columns to float type...\n",
        "
\n" ], "text/plain": [ - "\u001b[3;38;5;199;40mCould not convert some columns to float type\u001b[0m\u001b[3;33;40m...\u001b[0m\n" + "\u001b[3;36;40mCould not convert some columns to float type\u001b[0m\u001b[3;33;40m...\u001b[0m\n" ] }, "metadata": {}, @@ -195,11 +188,11 @@ { "data": { "text/html": [ - "
Could not convert some columns to float type...\n",
+       "
Could not convert some columns to float type...\n",
        "
\n" ], "text/plain": [ - "\u001b[3;36;40mCould not convert some columns to float type\u001b[0m\u001b[3;33;40m...\u001b[0m\n" + "\u001b[3;35;40mCould not convert some columns to float type\u001b[0m\u001b[3;33;40m...\u001b[0m\n" ] }, "metadata": {}, @@ -318,7 +311,7 @@ "0 04-01-1999 01-08-2024 " ] }, - "execution_count": 18, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -342,7 +335,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 4, "id": "f70b1cf2-7dd9-42ca-9009-0d825f4fcaf2", "metadata": {}, "outputs": [ diff --git a/evdspy/EVDSlocal/console/menu.py b/evdspy/EVDSlocal/console/menu.py index 3be25c8..75e04a6 100644 --- a/evdspy/EVDSlocal/console/menu.py +++ b/evdspy/EVDSlocal/console/menu.py @@ -7,8 +7,7 @@ from ..common.colors import * # from evdspy.utils.utils_general import * indent = " " * 15 -# MenuItem = namedtuple("MenuItem", "func disp sleeptime clear") -# MenuItem = namedtuple("MenuItem", "func disp sleeptime clear") + from typing import Union, List, Callable do_nothing = lambda: True @dataclass diff --git a/evdspy/EVDSlocal/console/menu_async.py b/evdspy/EVDSlocal/console/menu_async.py new file mode 100644 index 0000000..2174a10 --- /dev/null +++ b/evdspy/EVDSlocal/console/menu_async.py @@ -0,0 +1,180 @@ +""" +TODO async menu +""" +if False: + + import asyncio + from IPython.display import display, clear_output + from pathlib import Path + from .menu import check + + + # Placeholder functions for the menu options + async def check(): + pass + + + async def setup(): + pass + + + async def create_options_file(): + pass + + + async def create_series_file(): + pass + + + async def setup_series_steps(): + pass + + + async def get(): + pass + + + async def get_categories_main(): + pass + + + async def help_(): + pass + + + async def show_apikey(): + pass + + + async def set_apikey_input(): + pass + + + async def remove_cache(): + pass + + + async def console_main_from_the_menu(): + pass + + + async def version(): + pass + + + async def py_version(): + pass + + + async def check_compat(): + pass + + + async def main_exit_function(): + pass + + + # Menu item class + class MenuItem: + def __init__(self, function, description): + self.function = function + self.description = description + + + # Menu maker class + class MenuMaker: + def __init__(self, menu_items, exit_item, exit_menu_call_back): + self.menu_items = menu_items + self.exit_item = exit_item + self.exit_menu_call_back = exit_menu_call_back + + async def display(self): + while True: + clear_output(wait=True) + print("Please choose an option:") + for idx, item in enumerate(self.menu_items): + print(f"{idx + 1}. {item.description}") + if self.exit_item: + print(f"{len(self.menu_items) + 1}. Exit") + + user_input = await asyncio.get_event_loop().run_in_executor(None, input, "Enter choice: ") + try: + choice = int(user_input) - 1 + if choice == len(self.menu_items): + await self.exit_menu_call_back() + break + elif 0 <= choice < len(self.menu_items): + await self.menu_items[choice].function() + else: + print("Invalid choice, please try again.") + except ValueError: + print("Invalid input, please enter a number.") + + await asyncio.sleep(0.1) + + + # Function to display the menu + async def menu_display(): + funcs = [ + ("check setup", check), + ("setup", setup), + ("create user options file", create_options_file), + ("create series file", create_series_file), + ("add new series group", setup_series_steps), + ("get data", get), + ("get categories (get all series of a datagroup)", get_categories_main), # next version + # ("get data groups (on development)", get_datagroups_data_main), # next version + ("help", help_), + ("show api key", show_apikey), + ("save api key to file", set_apikey_input), + ("remove cache folders", remove_cache), + ("evdspy as a command line prompt", console_main_from_the_menu), + ("version", version), + ("py version", py_version), + ("check compatibility of your python version", check_compat), + ] + + menu_items = list(map(lambda x: MenuItem(x[1], x[0]), funcs)) + menu_maker = MenuMaker( + menu_items=menu_items, + exit_item=True, + exit_menu_call_back=main_exit_function + ) + await menu_maker.display() + + + # Helper function to start the menu + async def menu_helper_async(): + global menu_already_displayed + menu_already_displayed = True + await menu_display() + + + # Global variable to store the menu task + menu_task = None + + + # Function to start the menu + def start_menu(): + global menu_task + if menu_task and not menu_task.done(): + menu_task.cancel() + menu_task = asyncio.create_task(menu_helper_async()) + + + # Function to stop the menu + def stop_menu(): + global menu_task + if menu_task and not menu_task.done(): + menu_task.cancel() + menu_task = None + print("Menu stopped.") + + + # Start the menu using asyncio.run in a script + if __name__ == "__main__": + asyncio.run(menu_helper_async()) + + # In Jupyter Notebook, call start_menu and stop_menu functions + # start_menu() + # stop_menu() diff --git a/evdspy/EVDSlocal/index_requests/datagroups.py b/evdspy/EVDSlocal/index_requests/datagroups.py index 1c4d6cf..562f739 100644 --- a/evdspy/EVDSlocal/index_requests/datagroups.py +++ b/evdspy/EVDSlocal/index_requests/datagroups.py @@ -65,13 +65,3 @@ def get_all_groups(): except Exception as exc: print(exc) pass -import warnings -def get_datagroups() -> str: - warnings.warn("get_datagroups will be removed in future version. Please use get_series istead [...]", - DeprecationWarning) - return GeneralIndexesDatagroups(EVRequest_=EVRequest(options_=SingletonOptions())).create_url() -# def process_datagroups(data_model_type, content): -# df_op = DFOperations(data_model_type(data=content)) -# df_op.convert_to_df_abstract() -# df = pd.DataFrame.from_records(content) -# df.to_excel("t123.xlsx") \ No newline at end of file diff --git a/evdspy/EVDSlocal/index_requests/user_requests/Proxy_manager.py b/evdspy/EVDSlocal/index_requests/user_requests/Proxy_manager.py index c38a4b7..721017c 100644 --- a/evdspy/EVDSlocal/index_requests/user_requests/Proxy_manager.py +++ b/evdspy/EVDSlocal/index_requests/user_requests/Proxy_manager.py @@ -1,7 +1,6 @@ # ....................................................................... ProxyManager from dataclasses import dataclass from typing import Optional, Any - from evdspy.EVDSlocal.console.proxy_for_menu import get_proxies_env @@ -22,6 +21,7 @@ def get_proxies(self) -> Optional[dict[Any, Any]]: proxies = self.get_proxies_helper() else: proxies = self.proxies + # print("proxies", proxies) return proxies def get_proxies_helper(self) -> Optional[dict[Any, Any]]: diff --git a/evdspy/EVDSlocal/initial/load_commands_cmds_to_load.py b/evdspy/EVDSlocal/initial/load_commands_cmds_to_load.py index a891a48..7130011 100644 --- a/evdspy/EVDSlocal/initial/load_commands_cmds_to_load.py +++ b/evdspy/EVDSlocal/initial/load_commands_cmds_to_load.py @@ -376,14 +376,7 @@ def remove_cache(): print_with_success_style("cahce folder removed...") else: print_with_failure_style("cahce folder coould not be removed...") -def testt_the_latest(): - get_all_groups() - # get_and_process_datagroups_with_code(3) - # def __(): - # *coming, last = get_datagroups_df('json', None, True) - # print(coming) - # print(last) - # print(last()) + def main_exit_function(): ... def menu_display(): @@ -405,8 +398,7 @@ def menu_display(): ("py version", py_version), ("check compatibility of your python version", check_compat), ] - if 'NEXT_RELEASE' in str(Path().cwd()): - funcs.append(('test_the latest', testt_the_latest)) + menu_items = list(map(lambda x: MenuItem(x[1], x[0]), funcs)) MenuMaker( menu_items=menu_items, @@ -418,6 +410,10 @@ def menu_helper(): global menu_already_displayed menu_already_displayed = True menu_display() + + + + def menu_onload(): if CurrentState().menu_will_open: menu_helper() diff --git a/evdspy/EVDSlocal/tests/test_categories.py b/evdspy/EVDSlocal/tests/test_categories.py index 42812c0..8391e38 100644 --- a/evdspy/EVDSlocal/tests/test_categories.py +++ b/evdspy/EVDSlocal/tests/test_categories.py @@ -1,8 +1,8 @@ from ..index_requests.categories import get_categories -from ..index_requests.datagroups import get_datagroups +# from ..index_requests.datagroups import get_datagroups def test_get_categories(capsys): get_categories() -def test_get_datagroups(capsys): - get_datagroups() \ No newline at end of file +# def test_get_datagroups(capsys): +# get_datagroups() \ No newline at end of file diff --git a/evdspy/EVDSlocal/tests_main.py b/evdspy/EVDSlocal/tests_main.py index 1c8ddf9..1282fe1 100644 --- a/evdspy/EVDSlocal/tests_main.py +++ b/evdspy/EVDSlocal/tests_main.py @@ -8,7 +8,7 @@ from evdspy.EVDSlocal.tests.test_apikey_checks import * from evdspy.EVDSlocal.tests.test_categories import * # from evdspy.EVDSlocal.tests.test_main_cmd import * -from evdspy.EVDSlocal.tests.test_datagroups import * +# from evdspy.EVDSlocal.tests.test_datagroups import * #-------------- not necessary for now # # from .tests.test_series_files import * diff --git a/pyproject.toml b/pyproject.toml index 7944d29..27896b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ [tool.poetry] name = "evdspy" -version = "1.1.36" +version = "1.1.37" description = "A versatile interface for the 'EDDS' (EVDS) API of the Central Bank of the Republic of Türkiye (https://evds2.tcmb.gov.tr/index.php?/evds/userDocs). This package allows users to easily access and manage economic data through a user-friendly menu function. It features a robust caching mechanism to enhance the efficiency of data requests by storing frequently accessed data for selected periods. Required API keys can be obtained by registering on the EVDS website." authors = ["Sermet Pekin "] license = "MIT"