人生轨迹代码初始化
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import os
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
import ssl
|
||||
|
||||
# Configuration
|
||||
RESOURCES = [
|
||||
{
|
||||
"url": "https://grainy-gradients.vercel.app/noise.svg",
|
||||
"filename": "noise.svg",
|
||||
"dir": "src/assets"
|
||||
}
|
||||
]
|
||||
|
||||
def download_file(url, directory, filename):
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
filepath = os.path.join(directory, filename)
|
||||
|
||||
print(f"Downloading {url} to {filepath}...")
|
||||
|
||||
try:
|
||||
# Create a request with a User-Agent
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
data=None,
|
||||
headers={
|
||||
'User-Agent': 'Mozilla/5.0'
|
||||
}
|
||||
)
|
||||
|
||||
# Bypass SSL verification
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
|
||||
with urllib.request.urlopen(req, context=ctx, timeout=10) as response:
|
||||
with open(filepath, 'wb') as f:
|
||||
f.write(response.read())
|
||||
|
||||
print(f"Success: {filepath}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Error downloading {url}: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
print("Starting static resource download...")
|
||||
|
||||
success_count = 0
|
||||
for res in RESOURCES:
|
||||
if download_file(res["url"], res["dir"], res["filename"]):
|
||||
success_count += 1
|
||||
|
||||
print(f"\nDownload complete. {success_count}/{len(RESOURCES)} files downloaded.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user