diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 1f86901..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,19 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/docker-existing-dockerfile -{ - "name": "Existing Dockerfile", - - // Sets the run context to one level up instead of the .devcontainer folder. - "context": "..", - - // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. - "dockerFile": "../Dockerfile", - - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "ms-python.python" - ], - - // Install OS dependencies - "postCreateCommand": "apt-get update && apt -qq install -y sox && apt-get install -y libsox-fmt-all" -} diff --git a/.gitignore b/.gitignore index 1c28a20..9a8b2b2 100644 --- a/.gitignore +++ b/.gitignore @@ -153,22 +153,91 @@ dmypy.json cython_debug/ # PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -.idea/ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser assets/ out .DS_Store .setup-done-before -assets/ results/* -.env reddit-bot-351418-5560ebc49cac.json /.idea *.pyc /video_creation/data/videos.json -utils/envUpdate.py.old -envVars.txt \ No newline at end of file +/video_creation/data/envvars.txt diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 0d2e482..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Main.py", - "type": "python", - "request": "launch", - "program": "${workspaceFolder}/main.py", - "console": "integratedTerminal", - "justMyCode": true - } - ] -} \ No newline at end of file diff --git a/main.py b/main.py index bfb3ba3..6f478b1 100755 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ from os import getenv, name from reddit.subreddit import get_subreddit_threads from utils.cleanup import cleanup from utils.console import print_markdown, print_step -from utils.envUpdate import envUpdate +from utils.checker import envUpdate from video_creation.background import download_background, chop_background_video from video_creation.final_video import make_final_video from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts diff --git a/utils/checker.py b/utils/checker.py new file mode 100644 index 0000000..0372514 --- /dev/null +++ b/utils/checker.py @@ -0,0 +1,62 @@ +import os +import subprocess +import tempfile +from os import path +from sys import platform + +ACCEPTABLE_TO_BE_LEFT_BLANK = ['RANDOM_THREAD', 'TIMES_TO_RUN'] + + +def envUpdate(): + if path.exists(".env.template"): # if .env.template exists and .env does not exist + if platform == "win32" or platform == "cygwin": + runPS('utils/scripts/FileGrabber.ps1') + with open(".\\video_creation\\data\\envvars.txt", "rb") as f: + envTemplate = f.read() + elif platform == "darwin" or platform == "linux": + envTemplate = subprocess.check_output("awk -F '=' 'NF {print $1}' .env.template | grep --regexp=^[a-zA-Z]", + shell=True, ) + else: + raise OSError("Unsupported platform") + elif path.exists(".env"): + if platform == "win32" or platform == "cygwin": + runPS('utils/scripts/FileGrabberenv.ps1') + with open(".\\video_creation\\data\\envvars.txt", "rb") as f: + envTemplate = f.read() + elif platform == "darwin" or platform == "linux": + envTemplate = subprocess.check_output("awk -F '=' 'NF {print $1}' .env | grep --regexp=^[a-zA-Z]", + shell=True, ) + else: + raise OSError("Unsupported platform") + else: + raise FileNotFoundError("No .env or .env.template file found") + tempEnv = tempfile.TemporaryFile() + tempEnv.write(envTemplate) + tempEnv.seek(0) + envVars = tempEnv.readlines() + + + missing = [] + isMissingEnvs = False + for env in envVars: + try: + env = env.decode("utf-8").strip() + except AttributeError: + env = env.strip() + + if env not in os.environ: + if str(env) in ACCEPTABLE_TO_BE_LEFT_BLANK: + continue + isMissingEnvs = True + missing.append(env) + + if isMissingEnvs: + printstr = '' + [printstr + str(var) for var in missing] + print(f"The following environment variables are missing: {printstr}. Please add them to the .env file.") + exit(-1) + + +def runPS(cmd): + completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True) + return completed diff --git a/utils/envUpdate.py b/utils/envUpdate.py deleted file mode 100644 index f225419..0000000 --- a/utils/envUpdate.py +++ /dev/null @@ -1,48 +0,0 @@ -import os -import subprocess -import tempfile -import logging - -from os import path -from sys import platform, stderr - -log = logging.getLogger(__name__) - -def envUpdate(): - if path.exists(".env.template"): - if platform == "win32" or platform == "cygwin": - runPS('utils\envUpdateWin.ps1') - f = open("envVars.txt", "rb") - envTemplate = f.read() - elif platform == "darwin" or platform == "linux": - envTemplate = subprocess.check_output( - "awk -F '=' 'NF {print $1}' .env.template | grep --regexp=^[a-zA-Z]", - shell=True, - ) - return - tempEnv = tempfile.TemporaryFile() - tempEnv.write(envTemplate) - tempEnv.seek(0) - envVars = tempEnv.readlines() - - missing = [] - isMissingEnvs = False - for env in envVars: - try: - env = env.decode("utf-8").strip() - except AttributeError: - env = env.strip() - - if env not in os.environ: - isMissingEnvs = True - missing.append(env) - - if isMissingEnvs: - log.error( - f"[ERROR] The following environment variables are missing: {missing}.)" - ) - exit(-1) - -def runPS(cmd): - completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True) - return completed \ No newline at end of file diff --git a/utils/scripts/FileGrabber.ps1 b/utils/scripts/FileGrabber.ps1 new file mode 100644 index 0000000..a820d2e --- /dev/null +++ b/utils/scripts/FileGrabber.ps1 @@ -0,0 +1,9 @@ +$envFile = Get-Content ".\.env.template" + +$envFile -split "=" | Where-Object {$_ -notmatch '\"'} | Set-Content ".\envVarsbefSpl.txt" +Get-Content ".\envVarsbefSpl.txt" | Where-Object {$_ -notmatch '\#'} | Set-Content ".\envVarsN.txt" +Get-Content ".\envVarsN.txt" | Where-Object {$_ -ne ''} | Set-Content ".\video_creation\data\envvars.txt" +Remove-Item ".\envVarsbefSpl.txt" +Remove-Item ".\envVarsN.txt" + +Write-Host $nowSplit diff --git a/utils/envUpdateWin.ps1 b/utils/scripts/FileGrabberenv.ps1 similarity index 77% rename from utils/envUpdateWin.ps1 rename to utils/scripts/FileGrabberenv.ps1 index 1eb8f64..ffb021b 100644 --- a/utils/envUpdateWin.ps1 +++ b/utils/scripts/FileGrabberenv.ps1 @@ -1,9 +1,9 @@ -$envFile = Get-Content ".\.env.template" +$envFile = Get-Content ".\.env" $envFile -split "=" | Where-Object {$_ -notmatch '\"'} | Set-Content ".\envVarsbefSpl.txt" Get-Content ".\envVarsbefSpl.txt" | Where-Object {$_ -notmatch '\#'} | Set-Content ".\envVarsN.txt" -Get-Content ".\envVarsN.txt" | Where-Object {$_ -ne ''} | Set-Content ".\envVars.txt" +Get-Content ".\envVarsN.txt" | Where-Object {$_ -ne ''} | Set-Content ".\video_creation\data\envvars.txt" Remove-Item ".\envVarsbefSpl.txt" Remove-Item ".\envVarsN.txt" -Write-Host $nowSplit \ No newline at end of file +Write-Host $nowSplit diff --git a/video_creation/data/.gitignore b/video_creation/data/.gitignore deleted file mode 100644 index a8731e5..0000000 --- a/video_creation/data/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -videos.json - #todo add videos on github