[sync] updated post events
This commit is contained in:
1 parent
10dd3d6316
commit
b98a809543
8 files changed
+41
-37
No files matched your search
@@ -26,16 +26,17 @@ class SyncPost(Sync):
|
||||
return document
|
||||
|
||||
def create_hash(self, document):
|
||||
hash_images = lmap(
|
||||
files = sorted(document['images'])
|
||||
hashes = lmap(
|
||||
self.provider.hash,
|
||||
lmap(
|
||||
lambda i: os.path.join(document['folder'], i),
|
||||
document['images']
|
||||
files
|
||||
)
|
||||
)
|
||||
|
||||
document['hash'] = hash_str(
|
||||
combine([hash_str(document)] + hash_images)
|
||||
combine([hash_str(document)] + hashes)
|
||||
)
|
||||
|
||||
return document
|
||||
@@ -54,10 +55,9 @@ class SyncPost(Sync):
|
||||
images = []
|
||||
for img in post_html.cssselect('img'):
|
||||
src = img.get('src')
|
||||
img_path = os.path.abspath(
|
||||
os.path.join(document['folder'], src)
|
||||
)
|
||||
relative_image_path = os.path.join(document['folder'], src)
|
||||
|
||||
img_path = self.provider.get_local(relative_image_path)
|
||||
if os.path.exists(img_path):
|
||||
img_id = url_encode_text(os.path.splitext(src)[0])
|
||||
url_fn = lambda size, ext: self.image_url_base.format(
|
||||
|
||||
@@ -38,6 +38,9 @@ class Provider:
|
||||
rel = os.path.relpath(path, self.root)
|
||||
return rel
|
||||
|
||||
def get_local(self, path):
|
||||
return path
|
||||
|
||||
def is_dir(self, path):
|
||||
return False
|
||||
|
||||
|
||||
@@ -44,3 +44,5 @@ class FSProvider(Provider):
|
||||
def is_dir(self, path):
|
||||
return os.path.isdir(self.get_abs(path))
|
||||
|
||||
def get_local(self, path):
|
||||
return self.get_abs(path)
|
||||
@@ -3,6 +3,8 @@ import os
|
||||
import re
|
||||
|
||||
import io
|
||||
from tempfile import mkstemp
|
||||
|
||||
import requests
|
||||
|
||||
from sync.data import Provider
|
||||
@@ -61,3 +63,8 @@ class YDProvider(Provider):
|
||||
def is_dir(self, path):
|
||||
res = self.api.get_content(self.get_abs(path))
|
||||
return res.type == 'dir'
|
||||
|
||||
def get_local(self, path):
|
||||
ext = os.path.splitext(path)[1]
|
||||
_, temp_in = mkstemp(suffix=ext)
|
||||
return self.copy(path, temp_in)
|
||||
+1
-10
@@ -1,21 +1,12 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
from glob import glob
|
||||
|
||||
import lxml.html
|
||||
|
||||
import settings
|
||||
from sync.data import list_images
|
||||
from db import db
|
||||
from sync import create_date_and_title_from_folder_name, create_post_from_image_list, create_date, images_from_html, \
|
||||
synced_images_ids, untouched
|
||||
from sync.core.post import SyncPost
|
||||
from sync.image import sync_image
|
||||
from utils.fn import combine, lmap, map_cases, first, lprint, key_mapper, lprint_json, lmapfn, constant
|
||||
from utils.hash import hash_file, hash_str
|
||||
from utils.image import create_image
|
||||
from utils.fn import lmap, map_cases, first, key_mapper, lmapfn, constant
|
||||
from utils.io import read_yaml_md
|
||||
from utils.text.transform import url_encode_text
|
||||
|
||||
|
||||
def get_manifest(provider, path):
|
||||
|
||||
Reference in new issue
Block a user