def generate(): type = config.get_game_type() if type is None: raise Exception('game_type cannot be null in config file') if type.lower() == 'singles': html_output_location = SinglesImage.write_file_with_config() dest_image_location = str( Path(get_root_dir(), 'singles-thumbnail.png')) screenshot_file(html_output_location, dest_image_location) cutoff_width(dest_image_location, 1150) cutoff_height(dest_image_location, 300) resize(dest_image_location, 1290, 720) convert_to_jpg(dest_image_location, 90) elif type.lower() == 'doubles': DoublesImage.write_file_with_config() else: raise Exception('unknown game type: {}'.format(type))
import json import pystache from os.path import exists, abspath from pathlib import Path from copy import deepcopy from thumbnailgen.models.game import Game from thumbnailgen.models.image import Image from thumbnailgen.models.player import Player from thumbnailgen.util.config import Config from thumbnailgen.util.io import get_file_content from thumbnailgen.util.common import get_root_dir, \ get_web_dir, capitalize_word ROOT_DIR = get_root_dir() OUTPUT_DIR = str(Path(ROOT_DIR, 'resources', 'web', 'output')) TEMPLATE_DIR = str(Path(ROOT_DIR, 'resources', 'web', 'templates')) TEMPLATE_FILE = str(Path(TEMPLATE_DIR, 'singles-thumbnail-template.html')) DEFAULT_OUTPUT_FILE = str(Path(OUTPUT_DIR, 'singles-thumbnail.html')) class SinglesImage(Image): def __init__(self, height=1080, width=1920, background_image=None, foreground_image=None, logo_image=None, filename=DEFAULT_OUTPUT_FILE, game: Game = Game('MELEE', 'SINGLES'), player1: Player = Player(),
def test_get_root_dir(self): actual = get_root_dir() self.assertEqual(self.expected_root_dir, actual)
from sys import argv from pathlib import Path from thumbnailgen.util.config import Config from thumbnailgen.models.singles_image import SinglesImage from thumbnailgen.models.doubles_image import DoublesImage from thumbnailgen.util.common import get_root_dir from thumbnailgen.util.screenshoter import screenshot_file from thumbnailgen.util.image_util import cutoff_width, \ cutoff_height, convert_to_jpg, resize config = Config() if __name__ == '__main__': type = config.get_game_type() if type is None: raise Exception('game_type cannot be null in config file') if type.lower() == 'singles': html_output_location = SinglesImage.write_file_with_config() dest_image_location = str(Path(get_root_dir(), 'singles-thumbnail.png')) screenshot_file(html_output_location, dest_image_location) cutoff_width(dest_image_location, 1150) cutoff_height(dest_image_location, 300) resize(dest_image_location, 1290, 720) convert_to_jpg(dest_image_location, 90) elif type.lower() == 'doubles': DoublesImage.write_file_with_config() else: raise Exception('unknown game type: {}'.format(type))
import json import pystache from configparser import ConfigParser from pathlib import Path from os.path import exists, isabs, abspath from thumbnailgen.util.common import get_root_dir CONFIG_DIR = Path(get_root_dir(), 'config') CONFIG_FILE = str(Path(CONFIG_DIR, 'config.ini')) CONFIG_TEMPLATE = str(Path(CONFIG_DIR, 'config.template.ini')) class Config(object): def __init__(self, file=CONFIG_FILE): file = file if isabs(file) else abspath(file) if not exists(file): raise Exception('config file does not exist: {}'.format(file)) self.file = file self.config = ConfigParser() self.config.read(self.file) def get_image_height(self) -> int: return int(self.config.get('IMAGE', 'height')) def get_image_width(self) -> int: return int(self.config.get('IMAGE', 'width')) def get_image_background(self): return str(self.config.get('IMAGE', 'background_image')) def get_image_foreground(self):