# AUTOGENERATED! DO NOT EDIT! File to edit: 00_core.ipynb (unless otherwise specified).

__all__ = ['say_hello', 'generate_db', 'insert_row']

# Cell
def say_hello(to):
    "Say hello to somebody"
    return f'Hello {to}!'

# Cell
#hide
import pandas as pd
import arrow
import os
from time import gmtime, strftime

# Cell

def generate_db(dbpath='db.csv', prefill=False):
    """Create example database"""
    if prefill:
        df = pd.DataFrame({'name': ['Sam', 'Grant'],
                           'mood': ['😊', '😵'],
                           'message': ['hi', 'hello'],
                           'time_utc' : [arrow.utcnow().format('YYYY-MM-DD HH:mm:ss'),
                                         arrow.utcnow().format('YYYY-MM-DD HH:mm:ss')]})
    else:
        df = pd.DataFrame(columns=['name', 'mood', 'message', 'time_utc'])
    df.to_csv(dbpath, index=None)
    print(f'✓💾 {dbpath} ({os.path.getsize(dbpath)} kb)')


# Cell

def insert_row(df, data, dbpath='db.csv'):
    new_row = pd.Series({'time_utc' : arrow.utcnow().format('YYYY-MM-DD HH:mm:ss'),
                         'name':data['name'],
                         'mood': data['mood'],
                         'message': data['message']})
    df = df.append(new_row, ignore_index=True)
    df.to_csv(dbpath, index=None)
    return df
