import asyncio
import dataset
import datetime

class Task(object):
    def __init__(self, chat_id, goal, callback, delay=25*60):
#        base_event_loop = asyncio.get_event_loop()
#        print("Getting myself")
#        super().__init__(
#            base_event_loop.time()+delay,
#            callback,
#            (),
#            base_event_loop,
#            )
#        super()._scheduled = True
#
#        print("Got myself?")

        self.asyncio_handle = asyncio.get_event_loop().call_later(
            delay,
            callback)
        self.goal = goal
        self.chat_id = chat_id
        self.start_time = datetime.datetime.now()
        with dataset.connect("sqlite:///tasks.db") as d:
            d["tasks"].insert(
                dict(
                    chat_id=self.chat_id,
                    start_time=self.start_time,
                    end_time=None,
                    goal=self.goal,
                    completed=False,
                ))
        print("Finished geting myself.")

    @asyncio.coroutine
    def cancel(self):
        yield from self.asyncio_handle.cancel()

    def complete(self):
        """This function should be called to complete a task.

        Tasks should only complete once the delay is up, but no
        checking is done to make sure this is the case

        TODO make this automatic (maybe inherit from asyncio.Handler?).

        """

        with dataset.connect("sqlite:///tasks.db") as d:
            d["tasks"].update(
                dict(
                    chat_id=self.chat_id,
                    start_time=self.start_time,
                    completed=True,
                    end_time=datetime.datetime.now(),
                ), ['chat_id', 'start_time'])



    def time_remaining(self):
        """Return time remaining in Task."""
        return self.asyncio_handle._when - asyncio.get_event_loop().time()

@@ -1,12 +1,35 @@
+#!/usr/bin/env python3%0A
 import async
@@ -83,16 +83,16 @@
 bject):%0A
+
     def 
@@ -148,315 +148,8 @@
 60):
-%0A#        base_event_loop = asyncio.get_event_loop()%0A#        print(%22Getting myself%22)%0A#        super().__init__(%0A#            base_event_loop.time()+delay,%0A#            callback,%0A#            (),%0A#            base_event_loop,%0A#            )%0A#        super()._scheduled = True%0A#%0A#        print(%22Got myself?%22)
 %0A%0A  
@@ -729,16 +729,17 @@
 elf.%22)%0A%0A
+%0A
     @asy
@@ -787,19 +787,8 @@
     
-yield from 
 self

Clean up code.