Exemplo n.º 1
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)
Exemplo n.º 2
0
        '_t': 'creation_date',
        '_w': 'pomodoro_duration'
    }
    df = df_original.copy()
    #df['_d'] = df['_d'].apply(lambda x: total_time(x))
    df['_l'] = df['_l'].apply(lambda x: datetime.datetime.fromtimestamp(x))
    df['_t'] = df['_t'].apply(lambda x: datetime.datetime.fromtimestamp(x))
    df.rename(columns=new_column_names, inplace=True)
    return df


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|Projects|~~~~~~~~~~~~~~~~~~~~~~```````

projects = {}
for index, project_sample in format_projects(df_projects).iterrows():
    project = Project.objects.create(
        creation_date=project_sample.creation_date,
        name=project_sample.project_name,
        user_id=2,
        pomodoro_duration=project_sample.pomodoro_duration)
    projects[project_sample.id] = project

for index, sample1 in format_work_units(df_work_units).iterrows():
    date = time_date_to_datetime(sample1.time, sample1.date)
    pomodoro = Pomodoro()
    pomodoro.project = projects[sample1.project_id]
    pomodoro.user_id = 2
    pomodoro.date = date
    pomodoro.duration = sample1.duration
    pomodoro.save()