3 Commits

4 changed files with 69 additions and 15 deletions

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
CCTVCrawl*
devscrape*
*.log*
OLD_devscrape*
*.log
__pycache__

View File

@ -1,2 +1,12 @@
# TranstarArchive
Python application intended to store an archive of live camera feeds from Houston Transtar
## requirements
python 3.6 or later
the requests and wget Python modules, installed with pip (if others aren't found on your system, they can be easily viewed in the source code c:)
## what does this program do?
retrives images from live and valid camera image feeds from Houston Transtar. normally these can be viewed on their website [here](https://traffic.houstontranstar.org/cctv/transtar/), or a very very lightweight version (intended for mobile or older devices, that i prefer) can be found [here](http://traffic.houstontranstar.org/mobile/transtar_cctv.aspx), stores them in a folder/local archive on the system you run it on
## why?
i have no idea

13
TranstarArchive_Loop.bat Normal file
View File

@ -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

57
main.py
View File

@ -2,27 +2,29 @@ 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 = "2022.9.28"
# Configure logging
logging.basicConfig(filename="TransArchive.log",
format='%(asctime)s %(message)s',
format='%(asctime)s %(levelname)s %(message)s',
filemode='a')
log = logging.getLogger()
log.setLevel(logging.DEBUG)
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").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}')
@ -33,7 +35,7 @@ csvfile = (f"TransArchive_{curdate}.csv") # mainly for debugging but to show sta
csvfields = ['time','camera_id', 'status'] # ^
# very important var: where we get everything
cctvurl = (f'https://www.houstontranstar.org/snapshots/cctv/') # Last updated Sep-2022
cctvurl = (f'https://www.houstontranstar.org/snapshots/cctv/') # Last updated Sep-6-2022
# very important var: list of valid camera feeds generated by devs (likely included and updated in repo)
vftxt = open("valid_feed_list.txt", "r")
vfdata = vftxt.read()
@ -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/")
@ -54,7 +60,7 @@ def initFolder():
log.warning("archive folder for todays date doesn't exist (expected LOL), creating it")
os.makedirs(f"archive/{curdate}")
elif not os.path.exists(f"TransstarArchive_{curdate}.csv"):
log.error("csv file doesn't exist. creating it for today")
log.warning("csv file doesn't exist. creating it for today")
with open(csvfile, 'a') as listfile:
csvwrite = csv.writer(listfile)
csvwrite.writerow(csvfields)
@ -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,36 @@ 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:
# print(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: # unrecognized arguments are passed (which is oki)
# log.debug("no args were passed!")
# log.debug("unrecognized args were passed!")
initFolder("normal")
MainMenu()
# noticed an issue where this doesn't run standalone anymore. maybe this will fix it. idk
if len(arglist) == 0:
# log.debug("no args were passed!")
initFolder("noarg")
MainMenu()
# 09/28/22- ok this will semi work for now. if any arg other than the ones defined above are passed it'll ignore them and run like none were passed