# Buggy code
def _sync_http(self):
    """
    simple syncer to import events from .ics files
    """
    import icalendar

    self.syncer = caldav.HTTPSyncer(
        self._resource,
        user=self._username,
        password=self._password,
        verify=self._ssl_verify,
        auth=self._auth,
    )
    self._dbtool.check_account_table(self.name)
    ics = self.syncer.get_ics()
    cal = icalendar.Calendar.from_ical(ics)
    remote_uids = list()
    for component in cal.walk():
        if component.name in ["VEVENT"]:
            remote_uids.append(str(component["UID"]))
            try:
                self._dbtool.update(
                    component, self.name, href=str(component["UID"]), etag="", status=OK
                )
            except backend.UpdateFailed as error:
                logging.error(error)
    # events from an icalendar retrieved over stupid http have no href
    # themselves, so their uid is safed in the `href` column
    locale_uids = [
        uid for uid, account in self._dbtool.get_all_href_from_db([self.name])
    ]
    remote_deleted = list(set(locale_uids) - set(remote_uids))
    if remote_deleted != list():
        for uid in remote_deleted:
            logging.debug(
                "removing remotely deleted event {0} from the local db".format(uid)
            )
            self._dbtool.delete(uid, self.name)


# Traceback (sqlite3.OperationalError)
Traceback (most recent call last):
File "/home/catern/src/khal/virt/bin/khal", line 5, in <module>
pkg_resources.run_script('khal==0.1.0.dev', 'khal')
File "/home/catern/src/khal/virt/lib/python2.7/site-packages/pkg_resources.py", line 540, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/home/catern/src/khal/virt/lib/python2.7/site-packages/pkg_resources.py", line 1462, in run_script
exec_(script_code, namespace, namespace)
File "/home/catern/src/khal/virt/lib/python2.7/site-packages/pkg_resources.py", line 41, in exec_
exec("""exec code in globs, locs""")
File "<string>", line 1, in <module>
File "/home/catern/src/khal/virt/lib/python2.7/site-packages/khal-0.1.0.dev-py2.7.egg/EGG-INFO/scripts/khal", line 72, in <module>

File "build/bdist.linux-x86_64/egg/khal/controllers.py", line 178, in __init__
File "build/bdist.linux-x86_64/egg/khal/backend.py", line 440, in get_allday_range
File "build/bdist.linux-x86_64/egg/khal/backend.py", line 164, in sql_ex
sqlite3.OperationalError: no such table: simple_d

# Fixed code
def _sync_http(self):
    """
    simple syncer to import events from .ics files
    """
    import icalendar

    self.syncer = caldav.HTTPSyncer(
        self._resource,
        user=self._username,
        password=self._password,
        verify=self._ssl_verify,
        auth=self._auth,
    )
    # self._dbtool.check_account_table(self.name)
    ics = self.syncer.get_ics()
    cal = icalendar.Calendar.from_ical(ics)
    remote_uids = list()
    for component in cal.walk():
        if component.name in ["VEVENT"]:
            remote_uids.append(str(component["UID"]))
            try:
                self._dbtool.update(
                    component, self.name, href=str(component["UID"]), etag="", status=OK
                )
            except backend.UpdateFailed as error:
                logging.error(error)
    # events from an icalendar retrieved over stupid http have no href
    # themselves, so their uid is safed in the `href` column
    locale_uids = [
        uid for uid, account in self._dbtool.get_all_href_from_db([self.name])
    ]
    remote_deleted = list(set(locale_uids) - set(remote_uids))
    if remote_deleted != list():
        for uid in remote_deleted:
            logging.debug(
                "removing remotely deleted event {0} from the local db".format(uid)
            )
            self._dbtool.delete(uid, self.name)