How to use the sdv.app function in sdv

To help you get started, we’ve selected a few sdv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Sketchy502 / SDV-Summary / sdv / imgur.py View on Github external
c=db.cursor()
	state = json.loads(response['state'])
	user_identifier = state['id']
	redir = state['redir']
	if 'error' in response:
		c.execute('UPDATE users SET imgur_json=NULL WHERE imgur_id='+app.app.sqlesc,(user_identifier,))
		db.commit()
		return {'success':False}
	# called at the server redirect when imgur returns the code
	client = ImgurClient(app.app.config['IMGUR_CLIENTID'],app.app.config['IMGUR_SECRET'])
	credentials = client.authorize(response['code'],'authorization_code')
	# print credentials
	if 'access_token' in credentials.keys() and 'refresh_token' in credentials.keys():
		db = app.connect_db()
		c = db.cursor()
		c.execute('UPDATE users SET imgur_json='+app.app.sqlesc+' WHERE imgur_id='+app.app.sqlesc,(json.dumps(credentials),user_identifier))
		db.commit()
		db.close()
		return {'success':True,'redir':redir}
	else:
		c.execute('UPDATE users SET imgur_json=NULL WHERE imgur_id='+app.app.sqlesc,(user_identifier,))
		db.commit()
		return {'success':False}
github Sketchy502 / SDV-Summary / sdv / imgur.py View on Github external
c.execute('UPDATE users SET imgur_json=NULL WHERE imgur_id='+app.app.sqlesc,(user_identifier,))
		db.commit()
		return {'success':False}
	# called at the server redirect when imgur returns the code
	client = ImgurClient(app.app.config['IMGUR_CLIENTID'],app.app.config['IMGUR_SECRET'])
	credentials = client.authorize(response['code'],'authorization_code')
	# print credentials
	if 'access_token' in credentials.keys() and 'refresh_token' in credentials.keys():
		db = app.connect_db()
		c = db.cursor()
		c.execute('UPDATE users SET imgur_json='+app.app.sqlesc+' WHERE imgur_id='+app.app.sqlesc,(json.dumps(credentials),user_identifier))
		db.commit()
		db.close()
		return {'success':True,'redir':redir}
	else:
		c.execute('UPDATE users SET imgur_json=NULL WHERE imgur_id='+app.app.sqlesc,(user_identifier,))
		db.commit()
		return {'success':False}
github Sketchy502 / SDV-Summary / sdv / imageDrone.py View on Github external
import math

from PIL import Image
from flask import Flask

import sdv.sql_commands as sql
from sdv.createdb import database_structure_dict, database_fields
from sdv.farmInfo import regenerateFarmInfo
from sdv.imagegeneration.avatar import generateAvatar
from sdv.imagegeneration.familyportrait import generateFamilyPortrait
from sdv.imagegeneration.farm import generateFarm, generateMinimap
from sdv.imagegeneration.tools import watermark
from sdv.parsers.json import parse_json
from sdv import app, connect_db, legacy_location

sqlesc = app.sqlesc


def save_from_id(save_id, cursor):
    cursor.execute(
            'SELECT ' + database_fields + ' FROM playerinfo WHERE id=(' + sqlesc + ')',
            (save_id,)
    )
    result = cursor.fetchone()
    data = {key: value for key, value in zip(database_fields.split(','), result)}

    data['pantsColor'] = [data[f'pantsColor{i}'] for i in range(4)]
    data['newEyeColor'] = [data[f'newEyeColor{i}'] for i in range(4)]
    data['hairstyleColor'] = [data[f'hairstyleColor{i}'] for i in range(4)]

    return data
github Sketchy502 / SDV-Summary / sdv / imageDrone.py View on Github external
sql.GET_TODO_TASKS,
                (True, 'process_image',)
        )
        tasks = cur.fetchall()
        db.commit()

        if tasks:
            for task in tasks:
                task_id = task[0]
                farm_id = task[2]

                data = save_from_id(farm_id, cur)
                base_subfolder = str(
                        int(math.floor(int(farm_id) / app.config.get('IMAGE_MAX_PER_FOLDER')))
                )
                base_path = os.path.join(app.config.get('IMAGE_FOLDER'), base_subfolder,
                                         data['url'])
                try:
                    os.makedirs(legacy_location(base_path))
                except OSError:
                    pass

                base_path_fmt = os.path.join(base_path, data['url'] + '-{image_type}.png')

                avatar_path = base_path_fmt.format(image_type='a')
                portrait_path = base_path_fmt.format(image_type='p')
                farm_path = base_path_fmt.format(image_type='f')
                map_path = base_path_fmt.format(image_type='m')
                thumb_path = base_path_fmt.format(image_type='t')

                # Main Player Avatar and Portrait
                avatar = generateAvatar(data)
github Sketchy502 / SDV-Summary / sdv / migrateImageDirectory.py View on Github external
import psycopg2
import shutil
import os
import math
from sdv.createdb import database_structure_dict, database_fields
from sdv import app, connect_db, legacy_location
sqlesc = app.sqlesc

def processFile(rowid, original_base_path, original_avatar_path, original_portrait_path, original_farm_path, original_map_path, original_thumb_path, url):
	if url == None:
		return None

	base_subfolder = str(int(math.floor(int(rowid)/app.config.get('IMAGE_MAX_PER_FOLDER'))))
	base_path = os.path.join(app.config.get('IMAGE_FOLDER'), base_subfolder, url)

	if base_path == original_base_path:
		return None

	try:
		os.makedirs(legacy_location(base_path))
	except OSError:
		pass
github Sketchy502 / SDV-Summary / sdv / emailDrone.py View on Github external
def send_email(address, title, body, html):
	with app.app_context():
		msg = Message(title,recipients=[address])
		msg.body = body
		msg.html = html
		mail.send(msg)
github Sketchy502 / SDV-Summary / sdv / imagegeneration / tools.py View on Github external
def watermark(img, mark=None, filename='u.f.png'):
    asset_dir = app.config.get('ASSET_PATH')
    if mark is None:
        mark = Image.open(os.path.join(asset_dir, 'watermarks', filename))
    x = 16
    y = img.size[1] - 16 - mark.size[1]
    if img.mode != 'RGBA':
        img = img.convert('RGBA')

    img.paste(mark, box=(x, y), mask=mark)
    return img.convert('P', palette=Image.ADAPTIVE, colors=255)
github Sketchy502 / SDV-Summary / sdv / imagegeneration / assets.py View on Github external
import os

from PIL import Image
from sdv import app
from sdv.imagegeneration.tools import cropImg

asset_dir = app.config.get('ASSET_PATH')

overlay_layers = {
    'Front',
    'AlwaysFront',
    'Buildings'
}

SEASONS = {
    'spring', 'summer', 'fall', 'winter'
}

outdoor_tile_sheets = {
    season: Image.open(os.path.join(asset_dir, 'farm', f'{season}_outdoorsTileSheet.png'))
    for season in SEASONS
}
github Sketchy502 / SDV-Summary / sdv / migrateImageDirectory.py View on Github external
def processFile(rowid, original_base_path, original_avatar_path, original_portrait_path, original_farm_path, original_map_path, original_thumb_path, url):
	if url == None:
		return None

	base_subfolder = str(int(math.floor(int(rowid)/app.config.get('IMAGE_MAX_PER_FOLDER'))))
	base_path = os.path.join(app.config.get('IMAGE_FOLDER'), base_subfolder, url)

	if base_path == original_base_path:
		return None

	try:
		os.makedirs(legacy_location(base_path))
	except OSError:
		pass

	try:
		connection = connect_db()
		cur = connection.cursor()

		avatar_paths = [original_avatar_path, os.path.join(base_path, url+'-a.png')]
		portrait_paths = [original_portrait_path, os.path.join(base_path, url+'-p.png')]
		farm_paths = [original_farm_path, os.path.join(base_path, url+'-f.png')]