[Sync] cleanup
This commit is contained in:
1 parent
8bf1ea37c8
commit
63796dfab3
6 files changed
+3
-129
No files matched your search
+1
-11
@@ -1,22 +1,12 @@
|
|||||||
import settings
|
import settings
|
||||||
from db import db, collection
|
from db import collection
|
||||||
from sync.album import sync_albums
|
|
||||||
from sync.core import Sync
|
from sync.core import Sync
|
||||||
from sync.core.SyncDocument import SyncDocument
|
from sync.core.SyncDocument import SyncDocument
|
||||||
from sync.data import Provider
|
|
||||||
from sync.core.SyncPage import SyncPage
|
from sync.core.SyncPage import SyncPage
|
||||||
from sync.data.fs import FSProvider
|
from sync.data.fs import FSProvider
|
||||||
from sync.data.yandexdisk import YDProvider
|
from sync.data.yandexdisk import YDProvider
|
||||||
from sync.document import sync_documents
|
|
||||||
from sync.page import sync_pages
|
|
||||||
from sync.person import sync_persons
|
|
||||||
from sync.post import sync_posts
|
|
||||||
from sync.schedule import sync_schedules
|
|
||||||
from utils.fn import lprint_json
|
|
||||||
from utils.image import thumbnail
|
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# create logger with 'spam_application'
|
# create logger with 'spam_application'
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
import os
|
|
||||||
from tempfile import mkstemp
|
|
||||||
|
|
||||||
from utils.image import create_image
|
|
||||||
from utils.image.resize import image_magick_pdf_to_img
|
|
||||||
from utils.text.transform import url_encode_text
|
|
||||||
|
|
||||||
|
|
||||||
class Preview:
|
|
||||||
def __init__(self, provider, url_base, output, sizes):
|
|
||||||
super().__init__()
|
|
||||||
self.provider = provider
|
|
||||||
self.url_base = url_base
|
|
||||||
self.output = output
|
|
||||||
self.sizes = sizes
|
|
||||||
|
|
||||||
def create(self, file):
|
|
||||||
def url(size, ext):
|
|
||||||
return self.url_base.format(id=file, size=size, ext=ext)
|
|
||||||
|
|
||||||
temp_preview_path = self.pdf_to_jpg(file)
|
|
||||||
file = os.path.basename(file)
|
|
||||||
file = url_encode_text(file)
|
|
||||||
img = create_image(temp_preview_path, self.sizes, url, self.output)
|
|
||||||
os.remove(temp_preview_path)
|
|
||||||
return img
|
|
||||||
|
|
||||||
def pdf_to_jpg(self, pdf):
|
|
||||||
_, temp_in = mkstemp(suffix='.pdf')
|
|
||||||
_, temp_out = mkstemp(suffix='.jpg')
|
|
||||||
|
|
||||||
abspdf = self.provider.copy(pdf, temp_in)
|
|
||||||
image_magick_pdf_to_img(abspdf, temp_out)
|
|
||||||
|
|
||||||
os.remove(temp_in)
|
|
||||||
return temp_out
|
|
||||||
@@ -86,27 +86,3 @@ def list_images(provider, path):
|
|||||||
lambda ext: provider.type_filter(path, ext),
|
lambda ext: provider.type_filter(path, ext),
|
||||||
image_types
|
image_types
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
def upload(file_path, relative_path):
|
|
||||||
"""
|
|
||||||
/path/to/file, /url/path -> https://static.shlisselburg.org/art/url/path
|
|
||||||
:param file_path:
|
|
||||||
:param relative_path:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
files = {'file': open(file_path, 'rb')}
|
|
||||||
url = 'https://static.shlisselburg.org/upload/art{}'.format(relative_path)
|
|
||||||
|
|
||||||
if not settings.upload_enabled:
|
|
||||||
return url
|
|
||||||
|
|
||||||
r = requests.put(
|
|
||||||
url=url,
|
|
||||||
files=files,
|
|
||||||
auth=('uploader', '1207690962638465')
|
|
||||||
)
|
|
||||||
if r.status_code == 200:
|
|
||||||
return url
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
@@ -1,48 +1,7 @@
|
|||||||
from db import db
|
from db import db
|
||||||
from settings import image_name_format, image_url_base
|
|
||||||
from utils.fn import lmap
|
from utils.fn import lmap
|
||||||
|
|
||||||
|
|
||||||
# class SyncImage(Sync):
|
|
||||||
# def __init__(self, sizes, save_path, create_url_fn):
|
|
||||||
# super().__init__()
|
|
||||||
# self.sizes = sizes
|
|
||||||
# self.save_path = save_path
|
|
||||||
# self.create_url_fn = create_url_fn
|
|
||||||
# self.collection = db().images
|
|
||||||
#
|
|
||||||
# def create_id(self, document):
|
|
||||||
# id = document['id'] if 'id' in document and document['id'] else None
|
|
||||||
# if not id:
|
|
||||||
# id = 'schedule-{period}-{semester}'.format(**document)
|
|
||||||
# document['id'] = id
|
|
||||||
# return document
|
|
||||||
#
|
|
||||||
# def read(self, document):
|
|
||||||
# return super().read(document)
|
|
||||||
#
|
|
||||||
# def create_hash(self, document):
|
|
||||||
# return {
|
|
||||||
# **document,
|
|
||||||
# 'hash': hash_file(document)
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# def create(self, document):
|
|
||||||
# image = create_image(document, self.sizes, self.create_url_fn, self.save_path)
|
|
||||||
#
|
|
||||||
# return {
|
|
||||||
# 'file': document,
|
|
||||||
# 'hash': self.create_hash(document),
|
|
||||||
# 'data': image['data']
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# def find_or_create(self, document):
|
|
||||||
# i = self.read(document)
|
|
||||||
# if not i:
|
|
||||||
# return self.create(document)
|
|
||||||
# return i
|
|
||||||
|
|
||||||
|
|
||||||
def sync_image(record):
|
def sync_image(record):
|
||||||
if isinstance(record, list):
|
if isinstance(record, list):
|
||||||
return lmap(
|
return lmap(
|
||||||
@@ -59,8 +18,3 @@ def sync_image(record):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def image_create_url(file):
|
|
||||||
url = image_url_base + image_name_format
|
|
||||||
return url.format(file)
|
|
||||||
@@ -1,26 +1,17 @@
|
|||||||
import os
|
|
||||||
import tempfile
|
import tempfile
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
import settings
|
|
||||||
from db import collection
|
from db import collection
|
||||||
from sync.data import scan_subdirs, request
|
from sync.data import request
|
||||||
from sync.models import Model
|
from sync.models import Model
|
||||||
from utils.fn import last_good, lmap
|
|
||||||
from utils.hash import hash_str
|
|
||||||
from utils.image.resize import image_magick_pdf_to_img
|
from utils.image.resize import image_magick_pdf_to_img
|
||||||
from utils.text.transform import url_encode_text, url_encode_file
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from sync.data import upload
|
from utils.image.resize import optimize, thumbnail
|
||||||
from utils.hash import hash_file
|
|
||||||
from utils.image.resize import optimize, thumbnail, orient
|
|
||||||
|
|
||||||
logger = logging.getLogger(settings.name)
|
logger = logging.getLogger(settings.name)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from typing import Optional
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from sync.data import upload
|
|
||||||
from utils.hash import hash_file
|
from utils.hash import hash_file
|
||||||
# from utils.image import resize
|
# from utils.image import resize
|
||||||
from utils.image.resize import optimize, thumbnail, orient
|
from utils.image.resize import optimize, thumbnail, orient
|
||||||
|
|||||||
Reference in new issue
Block a user