Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(examples): wrapped example in
if __name__ == '__main__'
- Loading branch information
Showing
1 changed file
with
12 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
# NOTE: Might not treat timezones correctly. | ||
|
||
from datetime import datetime, time, timedelta | ||
import aw_client | ||
import socket | ||
|
||
# Set this to your AFK bucket | ||
bucket_id = f"aw-watcher-afk_{socket.gethostname()}" | ||
import aw_client | ||
|
||
if __name__ == "__main__": | ||
# Set this to your AFK bucket | ||
bucket_id = f"aw-watcher-afk_{socket.gethostname()}" | ||
|
||
daystart = datetime.combine(datetime.now().date(), time()) | ||
dayend = daystart + timedelta(days=1) | ||
daystart = datetime.combine(datetime.now().date(), time()) | ||
dayend = daystart + timedelta(days=1) | ||
|
||
awc = aw_client.ActivityWatchClient("testclient") | ||
events = awc.get_events(bucket_id, start=daystart, end=dayend) | ||
events = [e for e in events if e.data["status"] == "not-afk"] | ||
total_duration = sum((e.duration for e in events), timedelta()) | ||
print(f"Total time spent on computer today: {total_duration}") | ||
awc = aw_client.ActivityWatchClient("testclient") | ||
events = awc.get_events(bucket_id, start=daystart, end=dayend) | ||
events = [e for e in events if e.data["status"] == "not-afk"] | ||
total_duration = sum((e.duration for e in events), timedelta()) | ||
print(f"Total time spent on computer today: {total_duration}") |