def main():
    import argparse

    parser = argparse.ArgumentParser("A watcher for ping")
    parser.add_argument("--testing", action="store_true")

    args = parser.parse_args()

    logging.basicConfig(level=logging.DEBUG if args.testing else logging.INFO)
    client = ActivityWatchClient("aw-watcher-network", testing=args.testing)

    bucketname = "{}_{}".format(client.client_name, client.client_hostname)
    eventtype = "ping"
    client.create_bucket(bucketname, eventtype)
    logger.info("Starting to log ping")


    while True:
        t = datetime.utcnow()
        sleeptime = 60 - (t.second + t.microsecond/1000000.0)
        sleep(sleeptime)
        timestamp = datetime.now(pytz.utc)
        wifiname = Wireless().current()
        try:
            out = ping(30)
            client.send_events(bucketname, createEvents(out,timestamp,wifiname))
            logger.info("Sent events")
                
        except Exception as e:
            import sys, traceback
            traceback.print_exc()
            logger.error("Exception thrown while pinging {}".format(e))
예제 #2
0
def main():
    import argparse

    parser = argparse.ArgumentParser("A watcher for ping")
    parser.add_argument("--testing", action="store_true")

    args = parser.parse_args()

    logging.basicConfig(level=logging.DEBUG if args.testing else logging.INFO)
    client = ActivityWatchClient("aw-watcher-network", testing=args.testing)

    bucketname = "{}_{}".format(client.client_name, client.client_hostname)
    eventtype = "ping"
    client.create_bucket(bucketname, eventtype)
    logger.info("Starting to log ping")

    while True:
        t = datetime.utcnow()
        sleeptime = 60 - (t.second + t.microsecond / 1000000.0)
        sleep(sleeptime)
        timestamp = datetime.now(pytz.utc)
        wifiname = Wireless().current()
        try:
            out = ping(30)
            client.send_events(bucketname,
                               createEvents(out, timestamp, wifiname))
            logger.info("Sent events")

        except Exception as e:
            import sys, traceback
            traceback.print_exc()
            logger.error("Exception thrown while pinging {}".format(e))
예제 #3
0
class ClientTest(unittest.TestCase):
    def setUp(self):
        self.client = ActivityWatchClient("unittest", testing=True)
        self.client.setup_bucket("test", "testevents")
        self.client.connect()

    def test_send_event(self):
        self.client.send_event("test",
                               Event(timestamp=datetime.now(), label="test"))

    def test_send_events(self):
        self.client.send_events("test", [
            Event(timestamp=datetime.now(), label="test"),
            Event(timestamp=datetime.now(), label="test2"),
        ])
예제 #4
0
def send_to_activitywatch(events):
    print("Sending events to ActivityWatch...")

    hostname = "macos-screentime-test"

    # NOTE: 'aw-watcher-android' string is only there for aw-webui to detect it as a mobile device
    bucket = f"aw-watcher-android_aw-import-screentime_{hostname}"

    aw = ActivityWatchClient(client_name="aw-import-screentime")
    aw.client_hostname = hostname

    # buckets = aw.get_buckets()
    # if bucket in buckets.keys():
    #     ans = input("Bucket already found, overwrite? (y/N): ")
    #     if ans == "y":
    #         aw.delete_bucket(bucket, force=True)

    aw.create_bucket(bucket, "currentwindow")
    aw.send_events(bucket, events)