Example #1
0
def main():

    #added global variables
    global active_window_name
    global first_time
    global start_time
    global keystrokes
    global clicks

    try:
        while True:

            previous_site = ""
            if sys.platform not in ['linux', 'linux2']:
                new_window_name = get_active_window()
                if 'Google Chrome' in new_window_name:
                    new_window_name = url_to_name(get_chrome_url())
            if sys.platform in ['linux', 'linux2']:
                new_window_name = l.get_active_window_x()
                if 'Google Chrome' in new_window_name:
                    new_window_name = l.get_chrome_url_x()

            #changed to form a new entry in JSON every time

            if active_window_name != new_window_name:

                print(active_window_name)
                activity_name = active_window_name

                if not first_time:
                    end_time = datetime.datetime.now()
                    time_entry = TimeEntry(start_time, end_time, 0, 0, 0, 0)
                    time_entry._get_specific_times()

                    exists = False

                    if not exists:
                        #print new message to terminal window
                        print("num of keystrokes: " + str(keystrokes))
                        print("num of clicks: " + str(clicks))
                        #adding a comment in the program thats running
                        activity = Activity(activity_name, [time_entry],
                                            keystrokes, int(clicks / 2))
                        activeList.activities.append(activity)
                        #resetting the clicks and keystrokes based of window switching
                        clicks = 0
                        keystrokes = 0

                    #do not sort the keys
                    with open('activities.json', 'w') as json_file:
                        json.dump(activeList.serialize(),
                                  json_file,
                                  indent=4,
                                  sort_keys=False)
                        start_time = datetime.datetime.now()
                first_time = False
                active_window_name = new_window_name

            time.sleep(1)
    except KeyboardInterrupt:

        with open('activties.json', 'w') as json_file:
            json.dump(activeList.serialize(),
                      json_file,
                      indent=4,
                      sort_keys=True)
Example #2
0
    activeList.initialize_me()
except Exception:
    print('No json')


try:
    while True:
        previous_site = ""
        if sys.platform not in ['linux', 'linux2']:
            new_window_name = get_active_window()
            if 'Google Chrome' in new_window_name:
                new_window_name = url_to_name(get_chrome_url())
        if sys.platform in ['linux', 'linux2']:
            new_window_name = l.get_active_window_x()
            if 'Google Chrome' in new_window_name:
                new_window_name = l.get_chrome_url_x()

        
        if active_window_name != new_window_name:
            print(active_window_name)
            activity_name = active_window_name

            if not first_time:
                end_time = datetime.datetime.now()
                time_entry = TimeEntry(start_time, end_time, 0, 0, 0, 0)
                time_entry._get_specific_times()

                exists = False
                for activity in activeList.activities:
                    if activity.name == activity_name:
                        exists = True
Example #3
0
    def start_timer(self, project_name):

        try:
            self.activeList = self.activeList.initialize_me(project_name)
        except Exception:
            print('No JSON DATA FOUND')

        try:
            print('Tracking Time on Project: ' + project_name)

            first_time = True
            # Main Code
            while True:
                previous_site = ""
                if sys.platform not in ['linux', 'linux2']:
                    new_window_name = get_active_window()
                    if 'Google Chrome' in new_window_name:
                        new_window_name = url_to_name(get_chrome_url())
                if sys.platform in ['linux', 'linux2']:
                    new_window_name = l.get_active_window_x()
                    for browser in settings.BROWSERS:
                        if browser in new_window_name:
                            new_window_name = l.get_chrome_url_x()
                            break

                if self.active_window_name != new_window_name:
                    print(self.active_window_name)
                    self.activity_name = self.active_window_name

                    if not first_time:
                        end_time = datetime.datetime.now()
                        time_entry = TimeEntry(self.start_time, end_time, 0, 0,
                                               0, 0)
                        time_entry._get_specific_times()

                        # Activities
                        if self.output['activities']:
                            exists = False
                            for activity in self.activeList.activities:
                                if activity.name == self.activity_name:
                                    exists = True
                                    activity.time_entries.append(time_entry)
                                    # index =self.activeList.overview.index({'name': activity.name})
                                    # print(self.activeList.overview[index])
                            if not exists:
                                activity = Activity(self.activity_name,
                                                    [time_entry])
                                self.activeList.activities.append(activity)

                        #OverView
                        if self.output['overview']:
                            overview_exists = False
                            for over in self.activeList.overview:
                                if over.name == self.activity_name:
                                    overview_exists = True
                                    'Already exists an entry here'
                                    over.time_entries[
                                        0].total_time = over.time_entries[
                                            0]._total_time_ + (end_time -
                                                               self.start_time)
                                    over.time_entries[0].end_time = end_time
                                    over.time_entries[0]._get_specific_times()
                            if not overview_exists:
                                activity = Activity(self.activity_name,
                                                    [time_entry])
                                self.activeList.overview.append(activity)

                        # Log
                        if self.output['logs']:
                            activity_log = Activity(self.activity_name,
                                                    [time_entry])
                            self.activeList.logs.append(activity_log)

                        with open(f'projects/{project_name}.json',
                                  'w') as json_file:
                            json.dump(self.activeList.serialize(),
                                      json_file,
                                      indent=4,
                                      sort_keys=True)
                            self.start_time = datetime.datetime.now()
                    first_time = False
                    self.active_window_name = new_window_name

                time.sleep(1)

        except KeyboardInterrupt:
            with open(f'projects/{project_name}.json', 'w') as json_file:
                json.dump(self.activeList.serialize(),
                          json_file,
                          indent=4,
                          sort_keys=True)
            for i in range(len(args_handler.runningProjects)):
                project = args_handler.runningProjects[i]
                if project['name'] == project_name:
                    del args_handler.runningProjects[i]
                    return args_handler.save_project_info()