'Query the PlexPy database with raw SQL. Automatically makes a backup of
the database if the latest backup is older then 24h. `api_sql` must be
manually enabled in the config file.
Required parameters:
query (str):        The SQL query
Optional parameters:
None
Returns:
None'

def sql(self, query=''):

    if (not plexpy.CONFIG.API_SQL):
        self._api_msg = 'SQL    not    enabled    for    the    API.'
        return
    if (not query):
        self._api_msg = 'No    SQL    query    provided.'
        return
    if (not len(os.listdir(plexpy.CONFIG.BACKUP_DIR))):
        self.backup_db()
    elif any([((os.path.getctime(os.path.join(plexpy.CONFIG.BACKUP_DIR, file_)) < (time.time() - 86400)) and file_.endswith('.db')) for file_ in os.listdir(plexpy.CONFIG.BACKUP_DIR)]):
        self.backup_db()
    db = database.MonitorDatabase()
    rows = db.select(query)
    return rows
