-
Notifications
You must be signed in to change notification settings - Fork 15
/
manage_gallery.py
51 lines (46 loc) · 1.48 KB
/
manage_gallery.py
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
import argparse
import subprocess
import sys
from server.models import (
Tyne,
db,
)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--tyne_file_name",
help="Filename, i.e. bit after /-/ in the url",
type=str,
required=True,
)
parser.add_argument(
"--screenshot",
help="Path to screenshot to upload to this tyne",
type=str,
default=None,
)
parser.add_argument("--set_in_gallery", action=argparse.BooleanOptionalAction)
args = parser.parse_args()
if not args.screenshot.endswith(".jpg") and not args.screenshot.endswith(".jpeg"):
print("Screenshot must be a jpeg file")
sys.exit(1)
with db.sessionmaker() as session:
tynes = session.query(Tyne).filter(Tyne.file_name == args.tyne_file_name).all()
if not tynes:
print(f"No tyne found with file_name {args.tyne_file_name}")
sys.exit(1)
tyne = tynes[0]
tyne.in_gallery = args.set_in_gallery
if args.screenshot:
tyne.screenshot_url = f"https://storage.googleapis.com/neptyne-screenshots/{tyne.file_name}.jpg"
subprocess.run(
[
"gsutil",
"cp",
args.screenshot,
f"gs://neptyne-screenshots/{tyne.file_name}.jpg",
],
check=True,
)
session.add(tyne)
session.commit()