import os
import pandas
from IPython.display import Javascript
from IPython.display import HTML

title_name = 'Tasks'
file_name = 'tasks.csv'
css_name = '//cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css'
js_name = '//cdn.datatables.net/1.10.12/js/jquery.dataTables.min'

def read_task():
  if os.path.exists(file_name):
    return pandas.DataFrame.from_csv(file_name)
  else:
    return pandas.DataFrame()

def save_task(data):
  pandas.DataFrame(data).to_csv(file_name)

def add_task(name, content):
  data = read_task()
  df = pandas.DataFrame([{'name':name,'content':content,'status':'new'}], columns = ['name','content','status'])
  data = data.append(df, ignore_index=True)
  save_task(data)

def show_task():
  data = read_task()
  js = '''
    <link rel='stylesheet' type='text/css' href='%s'>
    <script>
      require.config({
        paths: {
          dataTables: '%s'
        }
     });
      require(['dataTables'], function(){
        $('.dataframe').DataTable();
      });
    </script>
  '''%(css_name, js_name)
  return HTML('<h2>%s</h2>'%(title_name) + data.to_html() + js)

def update_task(id, **kwargs):
  data = read_task()
  if kwargs.get('name'):
    data['name'][id] = kwargs.get('name')
  if kwargs.get('content'):
    data['content'][id] = kwargs.get('content')
  if kwargs.get('status'):
    data['status'][id] = kwargs.get('status')
  save_task(data)

def delete_task(id):
  data = read_task()
  data = data.drop(id)
  save_task(data)

@@ -88,16 +88,46 @@
 ort HTML
+%0Afrom datetime import datetime
 %0A%0Atitle_
@@ -581,16 +581,26 @@
 Frame(%5B%7B
+%0A         
 'name':n
@@ -603,16 +603,26 @@
 e':name,
+%0A         
 'content
@@ -631,16 +631,26 @@
 content,
+%0A         
 'status'
@@ -655,16 +655,92 @@
 s':'new'
+,%0A         'created_at':datetime.now().strftime(%22%25Y/%25m/%25d %25H:%25M:%25S%22)%0A       
 %7D%5D, colu
@@ -753,16 +753,17 @@
 %5B'name',
+ 
 'content
@@ -764,24 +764,25 @@
 ontent',
+ 
 'status'
 %5D)%0A  dat
@@ -773,16 +773,44 @@
 'status'
+, 'created_at', 'updated_at'
 %5D)%0A  dat
@@ -1352,22 +1352,49 @@
 data
-%5B'name'%5D%5Bid%5D =
+.loc.__setitem__((slice(id, id), 'name'),
  kwa
@@ -1408,16 +1408,17 @@
 ('name')
+)
 %0A  if kw
@@ -1446,17 +1446,49 @@
     data
-%5B
+.loc.__setitem__((slice(id, id), 
 'content
@@ -1488,23 +1488,18 @@
 content'
-%5D%5Bid%5D =
+),
  kwargs.
@@ -1512,16 +1512,17 @@
 ontent')
+)
 %0A  if kw
@@ -1553,17 +1553,49 @@
 data
-%5B
+.loc.__setitem__((slice(id, id), 
 'status'
 %5D%5Bid
@@ -1594,15 +1594,10 @@
 tus'
-%5D%5Bid%5D =
+),
  kwa
@@ -1613,16 +1613,117 @@
 status')
+)%0A  data.loc.__setitem__((slice(id, id), 'updated_at'), datetime.now().strftime(%22%25Y/%25m/%25d %25H:%25M:%25S%22))
 %0A  save_

add created_at, updated_at