-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshell.py
More file actions
64 lines (52 loc) · 1.59 KB
/
Copy pathshell.py
File metadata and controls
64 lines (52 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os, datetime
import sys, subprocess, jinja2
def download_dataset(count, to):
FILE_PER_CURL = 50
i = 0
while count > 0:
request_for = min(count, FILE_PER_CURL)
subprocess.run(
[
"curl",
f"https://unsample.net/archive?count={request_for}&width=1920&height=1080",
"--output",
f"{to}/a{i}.zip",
])
subprocess.run(
["unzip", "-d", f"{to}/a{i}", f"{to}/a{i}.zip"],
)
count -= FILE_PER_CURL
i += 1
def get_paths(root_dir):
output = []
files = os.listdir(root_dir)
for file in files:
if os.path.isfile(root_dir + "/" + file):
output += [f"{root_dir}/{file}"]
else:
output += get_paths(root_dir + "/" + file)
return output
args = sys.argv[1:]
media_dir = args[args.index("-media-dir") + 1]
download_data = "-init-dataset" in args
if download_data:
download_dataset(int(args[args.index("-init-dataset") + 1]), media_dir)
templateLoader = jinja2.FileSystemLoader(searchpath=".")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "template.html"
template = templateEnv.get_template(TEMPLATE_FILE)
pictures = get_paths(media_dir)
if "-prefix" in args:
prefix = args[args.index("-prefix") + 1]
pictures = [
{"key": picture.replace(media_dir + "/", prefix)}
for picture in pictures
]
outputText = template.render({"pictures": pictures})
with open("index.html", "w") as f:
f.write(outputText)
subprocess.run([
"mv",
"index.html",
media_dir
])