Skip to content

Commit

Permalink
fix(examples): wrapped example in if __name__ == '__main__'
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jul 13, 2022
1 parent 9555528 commit e353cc0
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions examples/time_spent_today.py
@@ -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}")

0 comments on commit e353cc0

Please sign in to comment.