From 9c968fe66cb30ce1bfe0f9b6f79a2f17a73ec3ae Mon Sep 17 00:00:00 2001 From: Askill Date: Sat, 13 Jul 2024 14:44:38 +0200 Subject: [PATCH] added doc string to watch(); added requirements.txt --- prod.py | 4 ++++ requirements.txt | 1 + src/Watcher.py | 12 +++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 prod.py create mode 100644 requirements.txt diff --git a/prod.py b/prod.py new file mode 100644 index 0000000..688b247 --- /dev/null +++ b/prod.py @@ -0,0 +1,4 @@ +from src.Watcher import Watcher + +if __name__ == "__main__": + Watcher("./sites.txt", "./keywords.txt").watch() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2f7a821 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +deepdiff \ No newline at end of file diff --git a/src/Watcher.py b/src/Watcher.py index 6db3e79..e6c9db9 100644 --- a/src/Watcher.py +++ b/src/Watcher.py @@ -19,7 +19,14 @@ class Watcher: with open(path) as f: return f.read().splitlines() - def watch(self, sleep): + def watch(self, sleep=-1): + """start the watcher with the given interval + + :param arg: seconds between runs, -1 for single run + :type arg: int + :return: None + :rtype: None + """ while True: keywords = self.read_txt_file(self.keywords_source_path) sites = self.read_txt_file(self.sites_source_path) @@ -38,6 +45,9 @@ class Watcher: for url, c in content.items(): matches.append(self.search_sites(url, c, keywords)) print(matches) + + if sleep == -1: + return time.sleep(sleep) @staticmethod