Skip to content

Commit

Permalink
Finished
Browse files Browse the repository at this point in the history
  • Loading branch information
kalle hålldén committed Aug 21, 2019
1 parent 53d73a5 commit b69d751
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 0 additions & 2 deletions activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ def _get_specific_times(self):
self.seconds = self.seconds % 60

def serialize(self):
print(self.total_time)
return {
'start_time' : self.start_time.strftime("%Y-%m-%d %H:%M:%S"),
'end_time' : self.end_time.strftime("%Y-%m-%d %H:%M:%S"),
'total_time' : self.total_time.strftime("%Y-%m-%d %H:%M:%S"),
'days' : self.days,
'hours' : self.hours,
'minutes' : self.minutes,
Expand Down
Binary file modified activity.pyc
Binary file not shown.
33 changes: 22 additions & 11 deletions autotimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,33 @@
start_time = datetime.datetime.now()
activeList = AcitivyList([])
first_time = True


def url_to_name(url):
string_list = url.split('/')
return string_list[2]

try:
activeList.initialize_me()
except Exception:
print('No json')


try:
while True:
previous_site = ""
new_window_name = (NSWorkspace.sharedWorkspace()
.activeApplication()['NSApplicationName'])

if new_window_name == 'Google Chrome':
textOfMyScript = """tell app "google chrome" to get the url of the active tab of window 1"""
s = NSAppleScript.initWithSource_(NSAppleScript.alloc(), textOfMyScript)
results, err = s.executeAndReturnError_(None)
new_window_name = url_to_name(results.stringValue())

if active_window_name != new_window_name:
active_window_name = new_window_name
print(active_window_name)
if active_window_name == 'Google Chrome':
textOfMyScript = """tell app "google chrome" to get the url of the active tab of window 1"""
s = NSAppleScript.initWithSource_(NSAppleScript.alloc(), textOfMyScript)
results, err = s.executeAndReturnError_(None)
print(results.stringValue())
activity_name = results.stringValue()
else:
activity_name = active_window_name
activity_name = active_window_name

if not first_time:
end_time = datetime.datetime.now()
Expand All @@ -48,9 +55,13 @@
activity = Activity(activity_name, [time_entry])
activeList.activities.append(activity)
with open('activities.json', 'w') as json_file:
json.dump(activeList.serialize(), json_file)
json.dump(activeList.serialize(), json_file, indent=4, sort_keys=True)
first_time = False
active_window_name = new_window_name


time.sleep(10)
except KeyboardInterrupt:
with open('activities.json', 'w') as json_file:
json.dump(activeList.serialize(), json_file)
json.dump(activeList.serialize(), json_file, indent=4, sort_keys=True)

0 comments on commit b69d751

Please sign in to comment.