Helper Functions

Helper functions.

Functions can be directly called from core

usage example:

from ozcore import core

core.translate("merhaba")
ozcore.core.helpers.now_prefix(separator='-', format='now')[source]

datetime today or now as prefix

Parameters
  • separator (str) – default None, a seperator string for date and time

  • format (str) –

    default Now,

    ("now")=> "%y%m%d-%H%M%S"
    ("today")=> "%y%m%d"
    ("or any valid format")=> "%y%m%d-%H%M%S"
    

Returns

str

Hint

useful for naming files

ozcore.core.helpers.clean_html(html)[source]

cleans given html and returns a markdown

Parameters

html – html markup str as input

Returns

str, as mardown

ozcore.core.helpers.md_2_html(md_text)[source]

converts markdown to html

Parameters

md_text – markdown str as input

Returns

str, as html markup

ozcore.core.helpers.translate(text='None', dest='en', src='auto', html=False)[source]
translate text via Google Translator.
connects free to google translator,
limits text to max. 12.000 chars
Parameters
  • text – str, text to translate (may use html or markdown too)

  • dest – str, destination lang, defaults to english (en)

  • src – str, source lang, defaults to auto

  • html – bool, if cleaned and set False returns Markdown, if set True returns html

Returns

str or html

Warning

given text should not have special chars
and may need to be cleaned by _clean_html
ozcore.core.helpers.serialize_a_json_field(val, node=None)[source]
safely eval a field with a string list or dict inherited from a json file

e.g. [{name:test}] => list object having dict node ‘name’

Parameters
  • val – json | dict, field value passed

  • node – str, key name in the dictionary

Returns

  • semicolon seperated values if val is a set, dict or list

  • if node is given, returns the values in the node as semicolon separated string

  • if val is None, returns None

  • if fails to the opretion returns back the val itself

Hint

useful in serializing fields in a dataframe having dict like objects

ozcore.core.helpers.dirme(me)[source]

lists methods of a given module in Jupyter Notebook

Parameters

me – str, module, argument, method

Returns

  • displays module, arg or method as a pandas DataFrame

  • display option, set to the len of df (in Jupyter Notebook)

ozcore.core.helpers.unzip(url: str, dest: pathlib.PosixPath, chunk_size: int = 1048576, remove_zip: bool = False)[source]

Downloads and unzips a zip file

Parameters
  • url – str, uri to zip file

  • dest – PosixPath, destination folder

  • chunk_size – int, default 1 MB

  • remove_zip – bool, default False, unlinks zip file after unzip operation

Returns

tqdm progress bar and typer echo messages