My common Python hacks
To install the required dependencies, use:
pip install ekcommon
To use:
from commonpy import *
from commonpy.simpleexceptioncontext import SimpleExceptionContext
callback = lambda e: self._eng.statusChanges.emit(f'Exception in processing {e}')
with SimpleExceptionContext('exception in processing',callback=callback):
ret=self.process_internal(ls)
logging.debug(f"process end {ret}")
return ret
In this example , a callback is called when the exception occurs.
@simple_exception_handling(err_description='error in get_symbol_history', return_succ=(None, []), never_throw=True)
@excp_handler(polygon.exceptions.BadResponse, handler=excphandler)
def get_symbol_history(sym, startdate, enddate, iscrypto=False):
# Your code to fetch symbol history here
pass
from commonpy import localize_it, unlocalize_it
import datetime
dt = datetime.datetime.now()
localized_dt = localize_it(dt)
unlocalized_dt = unlocalize_it(localized_dt)
- SimpleExceptionContext: Context manager for handling exceptions with customizable logging and traceback formatting.
- Date and Time Utilities: Functions to localize and unlocalize datetime objects.
- Functional Helpers: Various lambda functions for filtering dictionaries and mapping lists.
Contributions are welcome! Please fork this repository and submit a pull request.
This project is licensed under the MIT License.