Пример #1
0
    def handle(self, *args, **options):
        cal = Calendar()
        cal.add("prodid", "-//My calendar product//mxm.dk//")
        cal.add("version", "2.0")

        cursor = DatabaseWrapper(
            settings_dict={"NAME": options["inputfile"], "CONN_MAX_AGE": None, "OPTIONS": [], "AUTOCOMMIT": False}
        ).cursor()

        cursor.execute(
            "SELECT Z_PK, cast(ZWHEN as integer), ZDURATIONMINUTES, ZNAME FROM ZPOMODOROS ORDER BY ZWHEN DESC LIMIT %s",
            [options["limit"]],
        )

        for zpk, zwhen, zminutes, zname in cursor.fetchall():
            seconds = zminutes * 60
            start = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL - seconds, pytz.utc)
            end = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL, pytz.utc)

            event = Event()
            event.add("summary", u"{0}".format(zname, zminutes))
            event.add("dtstart", start)
            event.add("dtend", end)
            event["uid"] = zpk
            cal.add_component(event)
        print cal.to_ical()
Пример #2
0
    def handle(self, *args, **options):
        tags = {}
        if options['tagfile']:
            with open(options['tagfile']) as fp:
                for line in fp:
                    key, value = line.strip().split('=')
                    tags[key] = value

        user = User.objects.get(username=options['user'])
        pomodoros = Pomodoro.objects.filter(owner=user)
        if options['no_input'] is False:
            while len(pomodoros):
                self.stdout.write('Delete %d pomodoros for %s' % (len(pomodoros), user))
                if input('Confirm yes/no ').lower() == 'yes':
                    break
        pomodoros.delete()
        self.stdout.write('Importing Pomodoros')

        cursor = DatabaseWrapper(settings_dict={
            'NAME': options['inputfile'],
            'CONN_MAX_AGE': None,
            'OPTIONS': [],
            'AUTOCOMMIT': False,
        }).cursor()
        cursor.execute('SELECT cast(ZWHEN as integer), ZDURATIONMINUTES, ZNAME FROM ZPOMODOROS ')
        for zwhen, zminutes, zname in cursor.fetchall():
            seconds = zminutes * 60

            p = Pomodoro()
            p.title = zname
            p.owner = user
            #  p.start = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL - seconds, pytz.utc)
            #  p.end = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL, pytz.utc)
            p.created = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL - seconds, pytz.utc)

            for word in p.title.split():
                if word.startswith('#'):
                    p.category = word.strip('#')
                    break

            if not p.category:
                for search, tag in tags.items():
                    if search in p.title:
                        p.category = tag
                        break

            p.duration = zminutes
            p.save()
            self.stdout.write('Added %s' % p)