From ccec7d8416b12736e0255f35db0de4366114d03e Mon Sep 17 00:00:00 2001 From: iRaven <44326347+iRaven4522@users.noreply.github.com> Date: Thu, 8 Sep 2022 04:08:09 -0500 Subject: [PATCH] adding argument functionality for looping the main app with a script --- .gitignore | 3 ++- TranstarArchive_Loop.bat | 13 +++++++++++++ main.py | 40 ++++++++++++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 TranstarArchive_Loop.bat diff --git a/.gitignore b/.gitignore index 81a71a4..d6cbb35 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ CCTVCrawl* devscrape* -*.log* +*.log +__pycache__ diff --git a/TranstarArchive_Loop.bat b/TranstarArchive_Loop.bat new file mode 100644 index 0000000..11ea72d --- /dev/null +++ b/TranstarArchive_Loop.bat @@ -0,0 +1,13 @@ +@echo off +title TranstarArchive Looping Test (for Windows) +echo %cd% +set /p confirm=This will create a loop for archiving files from transtar, delayed every few minutes, are you sure? +if %confirm% == yes goto loop +if %confirm% == no goto :eof +goto :eof + +:loop +echo Starting to loop @ %date% %time% +python.exe %cd%\main.py -archive +timeout 17 +goto loop diff --git a/main.py b/main.py index 185b25f..77c17c0 100644 --- a/main.py +++ b/main.py @@ -2,16 +2,17 @@ import logging import os import wget import time -import datetime +import sys import requests import csv import threading + # TranstarArchive Main PY # author: iRaven (https://iravenhome.net) # Started 9/6/22. -#version = "0.1" +#version = "2021.9.8" # Configure logging logging.basicConfig(filename="TransArchive.log", @@ -23,6 +24,7 @@ logging.getLogger("requests").setLevel(logging.WARNING) #define local vars +arglist = sys.argv[1:] #time initcurtime = time.localtime() # currtime = (f'{initcurtime.tm_hour}-{initcurtime.tm_min}-{initcurtime.tm_sec}') @@ -45,8 +47,12 @@ vftxt.close() ######## Core functions # initialize folder -def initFolder(): - log.info(f'TranstarArchive was started') +def initFolder(startmode): + if startmode == "script": + log.info(f'TranstarArchive was likely started non-standalone with a script or from a command line') + else: + log.info(f'TranstarArchive was started') + if not os.path.exists("archive/"): log.info("archive folder doesn't exist. creating it") os.makedirs("archive/") @@ -86,7 +92,7 @@ def imageDownload(url): # for vals in invlog: # invlog.write(f'invalid feeds found at archive {curdate} at {curtime}:\n{vals}\n#### END END END ####\n either transstar is having issues or has reconfigured feed numbers, open an issue in the repo: https://github.com/iraven4522/TranstarArchive\n') -# loops the download function every like 3 or so mins +# loops the download function every like 3 or so mins (may not work?) def imgDownloadLoop(secs): log.info(f'delay loop was called for {secs}, starting now') threading.Timer(f'{secs}.0', imgDownloadLoop).start() @@ -106,13 +112,27 @@ def MainMenu(): menuin1 = input("If you want to continue please type the phrase \"startrans\" (without quotes) or type no: ") if menuin1 == "startrans": imageDownload(cctvurl) - log.info("returned to menu for delay") - imgDownloadLoop(195) + # log.info("returned to menu for delay") + # imgDownloadLoop(195) else: exit() else: exit() -# Run the shit (finally) -initFolder() # check folder and csv file first (send log start message) -MainMenu() +# Run the shit (finally) -- phased out due to arguments +# initFolder() # check folder and csv file first (send log start message) +# MainMenu() + +# Arguments +for arg in arglist: + if arg in ("-archive"): + # print("Archive was passed") # debugging + initFolder("script") + imageDownload(cctvurl) + elif arg in ("-testarg"): # debugging, left to test arguments + print("test arg was passed") + log.debug("Test arg was passed -- not running") + else: # no arguments are passed, just running the file from a folder (which is oki) + # log.debug("no args were passed!") + initFolder("normal") + MainMenu() \ No newline at end of file