# Path: picatrix/lib/framework.py
# class MagicProtocol(Protocol):
# class MagicArgument:
# class MagicArgumentParser(argparse.ArgumentParser):
# class _Magic:
#   def __call__(self, *args: Any) -> Any:
#   def __init__(self, *argc, **kwargs):
#   def __init__(self, *args, **kwargs):
#   def exit(self, status: Optional[int] = 0, message: Optional[Text] = ''):
#   def __init__(
#       self,
#       fn: MagicProtocol,
#       arguments: Optional[List[MagicArgument]] = None,
#       name_func: Optional[Callable[[Text], Text]] = None):
#   def __call__(self, line: Text, cell: Optional[Text] = None) -> Optional[Any]:
#   def __dir__(self):
#   def __getattribute__(self, name: Text):
# def _get_arguments_from_arg_lines(
#     arg_lines: List[Text]) -> List[Dict[Text, Text]]:
# def _get_argument_lines_from_docstring(lines: List[Text]) -> List[Text]:
# def _add_function_arguments_to_parser(
#     fn: MagicProtocol, parser: MagicArgumentParser):
# def _parse_docstring(function: MagicProtocol) -> List[Dict[Text, Text]]:
# def _parse_line_string(line: Text) -> List[Text]:
# def picatrix_helper(function: Callable[..., Any]) -> Callable[..., Any]:
# def picatrix_magic(
#     function: Optional[MagicProtocol] = None,
#     arguments: Optional[List[MagicArgument]] = None,
#     name_func: Optional[Callable[[Text], Text]] = None,
#     conditional: Optional[Callable[[None], bool]] = None) -> MagicProtocol:
#   def wrapper(func):
# 
# Path: picatrix/lib/state.py
# def state(refresh_state: bool = False):
#   """Property that returns a state object."""
#   # pylint: disable=global-statement
#   # Making sure we have only one state object.
#   global __state
# 
#   with _LOCK:
#     if refresh_state or __state is None:
#       __state = State()
# 
#     return __state
# 
# Path: picatrix/lib/utils.py
# def ask_question(question: Text, input_type: Optional[Any] = Text) -> Any:
# def clear_notebook_output():
# def ipython_bind_global(name: Text, value: Any) -> Any:
# def ipython_get_global(name: Text) -> Any:
# def ipython_remove_global(name: Text):


import datetime
import logging
import os
import dateutil.parser
import pandas as pd
from typing import Any, Dict, List, Optional, Text, Union
from dfdatetime import time_elements
from timesketch_api_client import aggregation as api_aggregation
from timesketch_api_client import client as api_client
from timesketch_api_client import config
from timesketch_api_client import search as api_search
from timesketch_api_client import sketch as api_sketch
from timesketch_api_client import story as api_story
from timesketch_api_client import timeline as api_timeline
from timesketch_import_client import helper, importer
from picatrix.lib import framework, state, utils
    minutes: int,
    seconds: Optional[int] = 90,
    fields: Optional[Text] = '') -> pd.DataFrame:
  """Run a Timesketch context query using a magic.

  This is a magic to run a context query in Timesketch around a
  single date and save them to a dataframe.

  If minutes are provided the seconds will be ignored.

  Args:
    data (str): the date string, in the form of %Y-%m-%dT%H:%M:%S%z.
    minutes (int): number of minutes to include in context.
    seconds (int): number of seconds to include in context, defaults
        to 90 seconds.
    fields (str): optional list of fields to include in the returned data.

  Returns:
    DataFrame containing the all surrounding events.
  """
  connect()
  date = data.strip()

  if minutes:
    seconds = minutes * 60

  return get_context_date(
      date, minutes=minutes, seconds=seconds, return_fields=fields)



# Path: picatrix/lib/framework.py
# class MagicProtocol(Protocol):
# class MagicArgument:
# class MagicArgumentParser(argparse.ArgumentParser):
# class _Magic:
#   def __call__(self, *args: Any) -> Any:
#   def __init__(self, *argc, **kwargs):
#   def __init__(self, *args, **kwargs):
#   def exit(self, status: Optional[int] = 0, message: Optional[Text] = ''):
#   def __init__(
#       self,
#       fn: MagicProtocol,
#       arguments: Optional[List[MagicArgument]] = None,
#       name_func: Optional[Callable[[Text], Text]] = None):
#   def __call__(self, line: Text, cell: Optional[Text] = None) -> Optional[Any]:
#   def __dir__(self):
#   def __getattribute__(self, name: Text):
# def _get_arguments_from_arg_lines(
#     arg_lines: List[Text]) -> List[Dict[Text, Text]]:
# def _get_argument_lines_from_docstring(lines: List[Text]) -> List[Text]:
# def _add_function_arguments_to_parser(
#     fn: MagicProtocol, parser: MagicArgumentParser):
# def _parse_docstring(function: MagicProtocol) -> List[Dict[Text, Text]]:
# def _parse_line_string(line: Text) -> List[Text]:
# def picatrix_helper(function: Callable[..., Any]) -> Callable[..., Any]:
# def picatrix_magic(
#     function: Optional[MagicProtocol] = None,
#     arguments: Optional[List[MagicArgument]] = None,
#     name_func: Optional[Callable[[Text], Text]] = None,
#     conditional: Optional[Callable[[None], bool]] = None) -> MagicProtocol:
#   def wrapper(func):
# 
# Path: picatrix/lib/state.py
# def state(refresh_state: bool = False):
#   """Property that returns a state object."""
#   # pylint: disable=global-statement
#   # Making sure we have only one state object.
#   global __state
# 
#   with _LOCK:
#     if refresh_state or __state is None:
#       __state = State()
# 
#     return __state
# 
# Path: picatrix/lib/utils.py
# def ask_question(question: Text, input_type: Optional[Any] = Text) -> Any:
# def clear_notebook_output():
# def ipython_bind_global(name: Text, value: Any) -> Any:
# def ipython_get_global(name: Text) -> Any:
# def ipython_remove_global(name: Text):


# Path: picatrix/magics/timesketch.py
import datetime
import logging
import os
import dateutil.parser
import pandas as pd
from typing import Any, Dict, List, Optional, Text, Union
from dfdatetime import time_elements
from timesketch_api_client import aggregation as api_aggregation
from timesketch_api_client import client as api_client
from timesketch_api_client import config
from timesketch_api_client import search as api_search
from timesketch_api_client import sketch as api_sketch
from timesketch_api_client import story as api_story
from timesketch_api_client import timeline as api_timeline
from timesketch_import_client import helper, importer
from picatrix.lib import framework, state, utils

    minutes: int,
    seconds: Optional[int] = 90,
    fields: Optional[Text] = '') -> pd.DataFrame:
  """Run a Timesketch context query using a magic.

  This is a magic to run a context query in Timesketch around a
  single date and save them to a dataframe.

  If minutes are provided the seconds will be ignored.

  Args:
    data (str): the date string, in the form of %Y-%m-%dT%H:%M:%S%z.
    minutes (int): number of minutes to include in context.
    seconds (int): number of seconds to include in context, defaults
        to 90 seconds.
    fields (str): optional list of fields to include in the returned data.

  Returns:
    DataFrame containing the all surrounding events.
  """
  connect()
  date = data.strip()

  if minutes:
    seconds = minutes * 60

  return get_context_date(
      date, minutes=minutes, seconds=seconds, return_fields=fields)



@framework.picatrix_magic