#!/usr/bin/env python
"""Command-line program to read a fto statistics csv and output a png graph"""

import argparse
import errno
import logging
import sys
from operator import itemgetter
import io
import warnings
try:
    from urlparse import urlparse
except ImportError:
    from urllib.parse import urlparse


# pylint: disable=unused-import
from typing import Iterable, Hashable, Any, Union, IO, Optional # NOQA
import pandas as pd
import requests
import matplotlib
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    # The backend choice must be called before pyplot import
    matplotlib.use('Agg')
import matplotlib.pyplot as plt

__all__ = ['main', 'generate_figure', 'load_dataframe']


# pylint: disable=invalid-name
log = logging.getLogger(__name__)


class Error(Exception):
    """All errors in this module inherit from this class."""
    pass


class CSVNotReadError(Error):
    """Error for failing to retrieve data from `input_csv`"""
    def __init__(self, msg, errno_):
        # type: (str, int) -> None
        super(CSVNotReadError, self).__init__(msg)
        self.msg = msg
        self.errno = errno_


class CSVNotFoundError(Error):
    """Error when the `input_csv` argument is not found"""