timetrack/__init__.py
def update_entry(self, entry_id, time):
        """Find an entry, update its time, rewrite file."""

        # identify the line to be updated
        line = int(entry_id) - 1

        all_data = []
        record = None

        # read all the data from the log into memory
        with open(self.track_file, "r") as f:
            for lineno, x in enumerate(f):
                if lineno != line:
                    all_data.append(x)
                else:
                    record = json.loads(x)

        # if after reading everything we didn't find the line, return error
        if record is None:
            print("Could not find entry with ID {}. Giving up.".format(entry_id))
            return

        # run live timer or parse updated time
        time_add = parse_time(time)

        # check time added was not less than 1 minute
        if time_add == 1:
            print("You must spend at least another minute \
                on this task to update it.")
            return

        # add updated time to total
        record['time'] += time_add

        print("Appending {} minutes to entry {} ({})".format(time_add, entry_id,
                                                            record['project']))

        # inject line into data
        entry = json.dumps(record) + "\n"

        all_data.insert(line, entry)

        # write data to file
        with open(self.track_file, "w") as f:
            for line in all_data:
                f.write(line)
Find an entry, update its time, rewrite file.
Find an entry, update its time, rewrite file.
Find an entry update its time rewrite file .
def update_entry(self, entry_id, time):
        line = int(entry_id) - 1
        all_data = []
        record = None
        with open(self.track_file, "r") as f:
            for lineno, x in enumerate(f):
                if lineno != line:
                    all_data.append(x)
                else:
                    record = json.loads(x)
        if record is None:
            print("Could not find entry with ID {}. Giving up.".format(entry_id))
            return
        time_add = parse_time(time)
        if time_add == 1:
            print("You must spend at least another minute \
                on this task to update it.")
            return
        record['time'] += time_add
        print("Appending {} minutes to entry {} ({})".format(time_add, entry_id,
                                                            record['project']))
        entry = json.dumps(record) + "\n"
        all_data.insert(line, entry)
        with open(self.track_file, "w") as f:
            for line in all_data:
                f.write(line)
def update_entry ( self , entry_id , time ) : line = int ( entry_id ) - 1 all_data = [ ] record = None with open ( self . track_file , "r" ) as f : for lineno , x in enumerate ( f ) : if lineno != line : all_data . append ( x ) else : record = json . loads ( x ) if record is None : print ( "Could not find entry with ID {}. Giving up." . format ( entry_id ) ) return time_add = parse_time ( time ) if time_add == 1 : print ( "You must spend at least another minute \
                on this task to update it." ) return record [ 'time' ] += time_add print ( "Appending {} minutes to entry {} ({})" . format ( time_add , entry_id , record [ 'project' ] ) ) entry = json . dumps ( record ) + "\n" all_data . insert ( line , entry ) with open ( self . track_file , "w" ) as f : for line in all_data : f . write ( line )
Find an entry, update its time, rewrite file.
Find an entry update its time rewrite file .
"""Find an entry, update its time, rewrite file.""" # identify the line to be updated # read all the data from the log into memory # if after reading everything we didn't find the line, return error # run live timer or parse updated time # check time added was not less than 1 minute # add updated time to total # inject line into data # write data to file
self
entry_id
time