Add screenshots
This commit is contained in:
parent
7180d96567
commit
71ca47846d
|
@ -1,4 +1,5 @@
|
||||||
import gi
|
import gi
|
||||||
|
import requests
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import inspect
|
import inspect
|
||||||
|
@ -27,8 +28,8 @@ def acceptedGame(app):
|
||||||
'Game' in app.get_categories() and \
|
'Game' in app.get_categories() and \
|
||||||
not [x for x in badCategories if x in app.get_categories()]
|
not [x for x in badCategories if x in app.get_categories()]
|
||||||
|
|
||||||
def getScreenshot(app):
|
def getScreenshots(app):
|
||||||
return [images.get_source() for images in app.get_screenshots]
|
return [images.get_source() for images in app.get_screenshots()]
|
||||||
|
|
||||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||||
parentdir = os.path.dirname(currentdir)
|
parentdir = os.path.dirname(currentdir)
|
||||||
|
@ -36,6 +37,8 @@ sys.path.insert(0,parentdir)
|
||||||
|
|
||||||
from app.models import *
|
from app.models import *
|
||||||
from app.utils import make_flask_login_password
|
from app.utils import make_flask_login_password
|
||||||
|
from app.utils.image import get_image_size
|
||||||
|
from app.utils import randomString
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Generate HTML files from an Appimage and mako templates.')
|
parser = argparse.ArgumentParser(description='Generate HTML files from an Appimage and mako templates.')
|
||||||
parser.add_argument("-p", '--appstream_path', help='specify the path of the appstream file')
|
parser.add_argument("-p", '--appstream_path', help='specify the path of the appstream file')
|
||||||
|
@ -51,14 +54,14 @@ session=db.session
|
||||||
licenses = { x.name : x for x in License.query.all() }
|
licenses = { x.name : x for x in License.query.all() }
|
||||||
tags = { x.name : x for x in Tag.query.all() }
|
tags = { x.name : x for x in Tag.query.all() }
|
||||||
admin_user = User.query.filter_by(username="appstream").first()
|
admin_user = User.query.filter_by(username="appstream").first()
|
||||||
#print("Users: ", users)
|
if not admin_user:
|
||||||
#admin_user = User("appstream")
|
admin_user = User("appstream")
|
||||||
#admin_user.is_active = True
|
admin_user.is_active = True
|
||||||
#admin_user.password = make_flask_login_password("appstream")
|
admin_user.password = make_flask_login_password("appstream")
|
||||||
#admin_user.github_username = "appstream"
|
admin_user.github_username = "appstream"
|
||||||
#admin_user.forums_username = "appstream"
|
admin_user.forums_username = "appstream"
|
||||||
#admin_user.rank = UserRank.ADMIN
|
admin_user.rank = UserRank.ADMIN
|
||||||
#session.add(admin_user)
|
session.add(admin_user)
|
||||||
|
|
||||||
|
|
||||||
for app in apps:
|
for app in apps:
|
||||||
|
@ -68,7 +71,7 @@ for app in apps:
|
||||||
print("APPLICATION: ",app.get_name())
|
print("APPLICATION: ",app.get_name())
|
||||||
game1 = Package()
|
game1 = Package()
|
||||||
game1.state = PackageState.APPROVED
|
game1.state = PackageState.APPROVED
|
||||||
game1.name = app.get_id()
|
game1.name = app.get_id().replace('.','_')
|
||||||
game1.title = app.get_name()
|
game1.title = app.get_name()
|
||||||
game1.type = PackageType.GAME
|
game1.type = PackageType.GAME
|
||||||
game1.license = licenses["MIT"]
|
game1.license = licenses["MIT"]
|
||||||
|
@ -89,5 +92,25 @@ for app in apps:
|
||||||
game1.desc = app.get_description()
|
game1.desc = app.get_description()
|
||||||
session.add(game1)
|
session.add(game1)
|
||||||
|
|
||||||
|
for i,screenshot in enumerate(screenshots):
|
||||||
|
ss = PackageScreenshot()
|
||||||
|
ss.package = game1
|
||||||
|
ss.title = "Untitled"
|
||||||
|
url = screenshot.get_url()
|
||||||
|
r = requests.get(url)
|
||||||
|
filename = randomString(10) + "." + "png"
|
||||||
|
filepath = os.path.join("/var/cdb/uploads", filename)
|
||||||
|
with open(filepath,"wb") as f:
|
||||||
|
f.write(r.content)
|
||||||
|
|
||||||
|
ss.url = "uploads/" + filename
|
||||||
|
ss.approved = True
|
||||||
|
ss.order = i
|
||||||
|
ss.width, ss.height = get_image_size(filepath)
|
||||||
|
session.add(ss)
|
||||||
|
session.commit()
|
||||||
|
game1.cover_image = ss
|
||||||
|
session.commit()
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue