From 187d12f10c45a69d83099d571401e128fd6d3771 Mon Sep 17 00:00:00 2001 From: Georg Krause Date: Sun, 24 May 2020 08:40:05 +0200 Subject: [PATCH] Add main function + command line option to run once (#19) --- youtube2peertube.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/youtube2peertube.py b/youtube2peertube.py index 2b3d698..04960e8 100644 --- a/youtube2peertube.py +++ b/youtube2peertube.py @@ -1,5 +1,7 @@ #!/usr/bin/python3 +import sys +import getopt import pafy import feedparser as fp from urllib.request import urlretrieve @@ -322,5 +324,24 @@ def run(run_once=True): run_steps(conf) sleep(poll_frequency) + +def main(argv): + run_once=False + try: + opts, args = getopt.getopt(argv,"ho",["help","once"]) + except: + print("youtube2peertube.py [-o|--once]") + sys(exit(2)) + + for opt, arg in opts: + if opt == '-h': + print("youtube2peertube.py [-o|--once]") + sys.exit() + elif opt in ("-o", "--once"): + run_once = True + + run(run_once) + + if __name__ == "__main__": - run(run_once=False) + main(sys.argv[1:])