Compare commits
No commits in common. "0aea1eb0f16d06f1c062f15ae9ed18c2ed780a59" and "d8672985992d8eb414d73dc55ff685129d2c3a5c" have entirely different histories.
0aea1eb0f1
...
d867298599
1
_deploy/prepare_photos/.gitignore
vendored
1
_deploy/prepare_photos/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
env
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
import os
|
|
||||||
from string import Template
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from natsort import os_sorted
|
|
||||||
from tqdm.auto import tqdm
|
|
||||||
from wand.image import Image
|
|
||||||
|
|
||||||
|
|
||||||
CONFIG_TEMPLATE = Template('{id: uuidv4(), category: "$category", image: "$filename", thumbSize: {w: $width, h: $height}},\n')
|
|
||||||
|
|
||||||
|
|
||||||
def run(gallery_folder, resize_config='400x400>') -> List[str]:
|
|
||||||
"""
|
|
||||||
For each image in given folder, generate the thumbnail and prepare a config string
|
|
||||||
|
|
||||||
@param gallery_folder: Path to gallery folder
|
|
||||||
@param resize_config: Options are described here: https://docs.wand-py.org/en/stable/guide/resizecrop.html#transform-images
|
|
||||||
"""
|
|
||||||
result = []
|
|
||||||
|
|
||||||
for current_dir, dirs, files in os.walk(gallery_folder):
|
|
||||||
with tqdm(os_sorted(files), desc='Processing images', leave=False) as files_pbar:
|
|
||||||
for file in files_pbar:
|
|
||||||
if current_dir.startswith('_'):
|
|
||||||
tqdm.write(f"Skipping: {file} from {current_dir}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Don't go deeper
|
|
||||||
if current_dir != gallery_folder:
|
|
||||||
continue
|
|
||||||
|
|
||||||
file_path = os.path.join(current_dir, file)
|
|
||||||
category = os.path.basename(current_dir)
|
|
||||||
files_pbar.set_postfix({"Working on": file_path})
|
|
||||||
|
|
||||||
# Create thumbnail folder
|
|
||||||
thumbnail_folder = os.path.join(current_dir, "thumbs")
|
|
||||||
os.makedirs(thumbnail_folder, exist_ok=True)
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
with Image(filename=file_path) as img:
|
|
||||||
# Generate thumbnail
|
|
||||||
img.auto_orient()
|
|
||||||
img.transform(resize=resize_config)
|
|
||||||
|
|
||||||
# Save it to file
|
|
||||||
thumbnail_path = os.path.join(thumbnail_folder, file)
|
|
||||||
img.save(filename=thumbnail_path)
|
|
||||||
|
|
||||||
# Use thumbnail size later
|
|
||||||
width = img.width
|
|
||||||
height = img.height
|
|
||||||
except:
|
|
||||||
tqdm.write(f"Failed to open file:{file_path}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Template string
|
|
||||||
config_string = CONFIG_TEMPLATE.substitute(category=category,
|
|
||||||
filename=file,
|
|
||||||
width=width,
|
|
||||||
height=height)
|
|
||||||
|
|
||||||
result.append(config_string)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
config_strings = run('/Users/phzhik/repo/alex-sharoff/public/gallery/interior')
|
|
||||||
with open("result.js", "w") as f:
|
|
||||||
f.writelines(config_strings)
|
|
||||||
|
|
||||||
tqdm.write('Done')
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
natsort==8.4.0
|
|
||||||
tqdm==4.66.5
|
|
||||||
Wand==0.6.13
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
RECAPTCHA_PUBLIC_KEY=""
|
|
||||||
RECAPTCHA_PRIVATE_KEY=""
|
|
||||||
FLASK_APIKEY=""
|
|
||||||
DEPLOY_PATH="/home/c/cn52774/alex-sharoff/public_html/backend"
|
|
||||||
21
backend/config.py
Normal file
21
backend/config.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
# TODO: store keys in env variables
|
||||||
|
RECAPTCHA_PUBLIC_KEY = "RECAPTCHA_PUBLIC_KEY"
|
||||||
|
RECAPTCHA_PRIVATE_KEY = "RECAPTCHA_PRIVATE_KEY-L4DsNDlza17N7dEz36"
|
||||||
|
|
||||||
|
FLASK_APIKEY = "FLASK_APIKEY"
|
||||||
|
|
||||||
|
if 'ALEX_DEBUG' in os.environ:
|
||||||
|
DEPLOY_PATH = '.'
|
||||||
|
else:
|
||||||
|
DEPLOY_PATH = '/home/c/cn52774/alex-sharoff/public_html/backend'
|
||||||
|
|
||||||
|
CONTACT_REQUEST_TEMPLATE = """
|
||||||
|
Обращение через форму обратной связи с сайта alex-sharoff.ru:
|
||||||
|
|
||||||
|
Имя: {name}
|
||||||
|
Контакты: {contacts}
|
||||||
|
-------
|
||||||
|
{message}
|
||||||
|
"""
|
||||||
|
|
@ -9,15 +9,12 @@ import telegram_send
|
||||||
from wtforms import StringField
|
from wtforms import StringField
|
||||||
from wtforms.validators import DataRequired
|
from wtforms.validators import DataRequired
|
||||||
|
|
||||||
from environs import Env
|
import config as cfg
|
||||||
|
|
||||||
env = Env()
|
# Set locale to UTF-8 as server's one is ANSI - this breaks cyrilic loggng
|
||||||
env.read_env()
|
|
||||||
|
|
||||||
# Set locale to UTF-8 as server's one is ANSI - this breaks cyrillic logging
|
|
||||||
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
||||||
|
|
||||||
logging.basicConfig(filename=f'{env.str("DEPLOY_PATH")}/log.log',
|
logging.basicConfig(filename=f"{cfg.DEPLOY_PATH}/log.log",
|
||||||
filemode='a',
|
filemode='a',
|
||||||
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
|
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
|
||||||
datefmt='%H:%M:%S',
|
datefmt='%H:%M:%S',
|
||||||
|
|
@ -27,12 +24,12 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
app.secret_key = env.str("FLASK_APIKEY")
|
app.secret_key = cfg.FLASK_APIKEY
|
||||||
app.config["APPLICATION_ROOT"] = "/api"
|
app.config["APPLICATION_ROOT"] = "/api"
|
||||||
app.config["WTF_CSRF_ENABLED"] = False
|
app.config["WTF_CSRF_ENABLED"] = False
|
||||||
|
|
||||||
app.config["RECAPTCHA_PUBLIC_KEY"] = env.str("RECAPTCHA_PUBLIC_KEY")
|
app.config["RECAPTCHA_PUBLIC_KEY"] = cfg.RECAPTCHA_PUBLIC_KEY
|
||||||
app.config["RECAPTCHA_PRIVATE_KEY"] = env.str("RECAPTCHA_PRIVATE_KEY")
|
app.config["RECAPTCHA_PRIVATE_KEY"] = cfg.RECAPTCHA_PRIVATE_KEY
|
||||||
|
|
||||||
app.config['EXECUTOR_TYPE'] = 'process'
|
app.config['EXECUTOR_TYPE'] = 'process'
|
||||||
app.config['EXECUTOR_PROPAGATE_EXCEPTIONS'] = True
|
app.config['EXECUTOR_PROPAGATE_EXCEPTIONS'] = True
|
||||||
|
|
@ -41,7 +38,7 @@ executor = Executor(app)
|
||||||
|
|
||||||
|
|
||||||
def send_telegram(message, silent=False):
|
def send_telegram(message, silent=False):
|
||||||
telegram_send.send(messages=[message], conf=f'{env.str("DEPLOY_PATH")}/telegram.conf', silent=silent)
|
telegram_send.send(messages=[message], conf=f'{cfg.DEPLOY_PATH}/telegram.conf', silent=silent)
|
||||||
|
|
||||||
|
|
||||||
class ContactForm(FlaskForm):
|
class ContactForm(FlaskForm):
|
||||||
|
|
@ -55,17 +52,8 @@ class ContactForm(FlaskForm):
|
||||||
def contact():
|
def contact():
|
||||||
form = ContactForm(request.form)
|
form = ContactForm(request.form)
|
||||||
|
|
||||||
msg_template = """
|
|
||||||
Обращение через форму обратной связи с сайта alex-sharoff.ru:
|
|
||||||
|
|
||||||
Имя: {name}
|
|
||||||
Контакты: {contacts}
|
|
||||||
-------
|
|
||||||
{message}
|
|
||||||
"""
|
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
text = msg_template.format(
|
text = cfg.CONTACT_REQUEST_TEMPLATE.format(
|
||||||
name=form.name.data,
|
name=form.name.data,
|
||||||
contacts=form.contacts.data,
|
contacts=form.contacts.data,
|
||||||
message=form.message.data
|
message=form.message.data
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
environs==11.0.0
|
|
||||||
Flask==2.3.2
|
|
||||||
Flask-Cors==3.0.10
|
|
||||||
Flask-Executor==1.0.0
|
|
||||||
Flask-WTF==1.1.1
|
|
||||||
telegram-send==0.34
|
|
||||||
WTForms==3.0.1
|
|
||||||
Loading…
Reference in New Issue
Block a user