[sync] updated: config based; async loop; Documents adopted to new system

This commit is contained in:
Roman Timashev committed 2017-09-10 22:12:09 +03:00
1 parent b0b518fd8c
commit 06965bebee
23 files changed
+1078 -346

No files matched your search

+5
View File
@@ -3,6 +3,7 @@ from io import BytesIO
import requests
import settings
from utils.fn import combine, lmap
@@ -96,6 +97,10 @@ def upload(file_path, relative_path):
"""
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,
+3 -7
View File
@@ -13,13 +13,9 @@ class FSProvider(Provider):
return open(self.get_abs(path), 'rb')
def scan(self, path):
return lmap(
self.get_rel,
map(
lambda i: i.path,
os.scandir(self.get_abs(path))
)
)
paths = [i.path for i in os.scandir(self.get_abs(path))]
return [self.get_rel(path) for path in paths]
def glob(self, pattr):
return lmap(self.get_rel, glob(self.get_abs(pattr)))
+41
View File
@@ -0,0 +1,41 @@
import aiohttp
import requests
import settings
async def upload(url, path):
"""
:param url:
:param path:
:return:
"""
if not settings.upload_enabled:
return url
# urlf = 'https://static.shlisselburg.org/upload/art{}'
files = {'file': open(path, 'rb')}
r = requests.put(
url=url,
files=files,
# auth=settings.upload_auth
auth=('uploader', '1207690962638465')
)
if r.status_code == 200:
return url
else:
return None
async def get(url):
async with aiohttp.ClientSession as session:
res = session.get(url)
return await res.text()
async def put(url, data):
async with aiohttp.ClientSession as session:
res = session.put(url, data=data)
return await res.text()