Add some docker shit
This commit is contained in:
		
							
								
								
									
										12
									
								
								.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								.dockerignore
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					__pycache__
 | 
				
			||||||
 | 
					*.pyc
 | 
				
			||||||
 | 
					*.pyo
 | 
				
			||||||
 | 
					*.pyd
 | 
				
			||||||
 | 
					downloads/
 | 
				
			||||||
 | 
					*.7z
 | 
				
			||||||
 | 
					VERSION
 | 
				
			||||||
 | 
					*.json
 | 
				
			||||||
 | 
					.git
 | 
				
			||||||
 | 
					.gitignore
 | 
				
			||||||
 | 
					.env.example
 | 
				
			||||||
 | 
					.env
 | 
				
			||||||
							
								
								
									
										3
									
								
								.env.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.env.example
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					API_KEY = "asdf1234"
 | 
				
			||||||
 | 
					CHECK_INTERVAL = 86400
 | 
				
			||||||
 | 
					DOWNLOAD_PATH = "./downloads"
 | 
				
			||||||
							
								
								
									
										7
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					FROM python:3.11.9-alpine
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Set the working directory
 | 
				
			||||||
 | 
					WORKDIR /app
 | 
				
			||||||
 | 
					COPY . /app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CMD ["python", "download.py"]
 | 
				
			||||||
							
								
								
									
										7
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					version: "3"
 | 
				
			||||||
 | 
					services:
 | 
				
			||||||
 | 
					  xedit-mirror:
 | 
				
			||||||
 | 
					    image: xedit-mirror
 | 
				
			||||||
 | 
					    build:
 | 
				
			||||||
 | 
					      context: .
 | 
				
			||||||
 | 
					      dockerfile: Dockerfile
 | 
				
			||||||
							
								
								
									
										28
									
								
								download.py
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								download.py
									
									
									
									
									
								
							@@ -5,7 +5,26 @@ from urllib.request import Request, urlopen, build_opener
 | 
				
			|||||||
BASE_URL = "https://api.nexusmods.com"
 | 
					BASE_URL = "https://api.nexusmods.com"
 | 
				
			||||||
API_VERSION = "v1"
 | 
					API_VERSION = "v1"
 | 
				
			||||||
API_URL = f"{BASE_URL}/{API_VERSION}/games"
 | 
					API_URL = f"{BASE_URL}/{API_VERSION}/games"
 | 
				
			||||||
from env import API_KEY
 | 
					
 | 
				
			||||||
 | 
					# Read in environment variables (takes precedence over .env file)
 | 
				
			||||||
 | 
					API_KEY = os.environ.get("API_KEY")
 | 
				
			||||||
 | 
					if not API_KEY:
 | 
				
			||||||
 | 
					    raise ValueError("API_KEY environment variable must be set")
 | 
				
			||||||
 | 
					CHECK_INTERVAL = os.environ.get("CHECK_INTERVAL")
 | 
				
			||||||
 | 
					if not CHECK_INTERVAL:
 | 
				
			||||||
 | 
					    CHECK_INTERVAL = 60 * 60 * 24  # 24 hours
 | 
				
			||||||
 | 
					DOWNLOAD_PATH = os.environ.get("DOWNLOAD_PATH")
 | 
				
			||||||
 | 
					if not DOWNLOAD_PATH:
 | 
				
			||||||
 | 
					    DOWNLOAD_PATH = "./downloads"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Read in dot env file
 | 
				
			||||||
 | 
					file = open(".env", "r")
 | 
				
			||||||
 | 
					lines = file.readlines()
 | 
				
			||||||
 | 
					for line in lines:
 | 
				
			||||||
 | 
						key, value = line.split("=")
 | 
				
			||||||
 | 
						key = key.strip()
 | 
				
			||||||
 | 
						if os.environ.get(key) is None:
 | 
				
			||||||
 | 
							os.environ[key] = value.strip()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Docs: https://app.swaggerhub.com/apis-docs/NexusMods/nexus-mods_public_api_params_in_form_data/1.0
 | 
					# Docs: https://app.swaggerhub.com/apis-docs/NexusMods/nexus-mods_public_api_params_in_form_data/1.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -89,7 +108,7 @@ def download_file(edit):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	# Create directories if they don't exist
 | 
						# Create directories if they don't exist
 | 
				
			||||||
	filename = f"{edit['name']} {edit['version']}.7z"
 | 
						filename = f"{edit['name']} {edit['version']}.7z"
 | 
				
			||||||
	path = f"./downloads/{edit['name']}/{filename}"
 | 
						path = f"{DOWNLOAD_PATH}/{edit['name']}/{filename}"
 | 
				
			||||||
	if not os.path.exists(os.path.dirname(path)):
 | 
						if not os.path.exists(os.path.dirname(path)):
 | 
				
			||||||
		os.makedirs(os.path.dirname(path))
 | 
							os.makedirs(os.path.dirname(path))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -104,9 +123,10 @@ def download_file(edit):
 | 
				
			|||||||
		with open(path, "wb") as file:
 | 
							with open(path, "wb") as file:
 | 
				
			||||||
			file.write(response.read())
 | 
								file.write(response.read())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while True:
 | 
				
			||||||
for edit in xEdits:
 | 
						for edit in xEdits:
 | 
				
			||||||
		print(f"Downloading {edit}...")
 | 
							print(f"Downloading {edit}...")
 | 
				
			||||||
		download_file(xEdits[edit])
 | 
							download_file(xEdits[edit])
 | 
				
			||||||
		# Wait 1 second between downloads, to prevent rate limiting
 | 
							# Wait 1 second between downloads, to prevent rate limiting
 | 
				
			||||||
		time.sleep(1)
 | 
							time.sleep(1)
 | 
				
			||||||
 | 
						time.sleep(CHECK_INTERVAL)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1 +0,0 @@
 | 
				
			|||||||
API_KEY = ""
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user