|
@@ -3,7 +3,7 @@ from .__load__ import *
|
|
|
# 提取器
|
|
|
class Parser(object):
|
|
|
|
|
|
- def get(self, id=0, site_id = 0, uid = 0, source_id = 0, source = '', notify='', sync=True, method='json'):
|
|
|
+ def get(self, host = '', id=0, site_id = 0, uid = 0, source_id = 0, source = '', notify='', sync=True, method='json', **kwargs):
|
|
|
extract = Demeter.model('extract')
|
|
|
if int(id) > 0:
|
|
|
extract.id = id
|
|
@@ -12,8 +12,8 @@ class Parser(object):
|
|
|
data = extract.select(type='fetchone')
|
|
|
if not data:
|
|
|
if not source:
|
|
|
- return source
|
|
|
- info = self.getFile(site_id, source)
|
|
|
+ return 'error'
|
|
|
+ info = self.getFile(site_id, source, host)
|
|
|
info['uid'] = uid
|
|
|
info['source_id'] = source_id
|
|
|
info['notify'] = notify
|
|
@@ -25,7 +25,7 @@ class Parser(object):
|
|
|
return self.handle(info, method);
|
|
|
return info['id']
|
|
|
|
|
|
- def getFile(self, site_id, file):
|
|
|
+ def getFile(self, site_id, file, host):
|
|
|
info = {}
|
|
|
(filepath,temp) = os.path.split(file)
|
|
|
(filename,extension) = os.path.splitext(temp)
|
|
@@ -34,6 +34,7 @@ class Parser(object):
|
|
|
info['key'] = self.getKey(site_id, file)
|
|
|
info['ext'] = extension
|
|
|
info['name'] = filename
|
|
|
+ info['host'] = host;
|
|
|
info['file'] = file
|
|
|
info['path'] = filepath
|
|
|
info = self.getLocal(info)
|
|
@@ -45,21 +46,23 @@ class Parser(object):
|
|
|
|
|
|
def getLocal(self, info):
|
|
|
if 'http' in info['source']:
|
|
|
+ # 远程的
|
|
|
day = str(date.today())
|
|
|
day = day.split('-')
|
|
|
- filename = info['key']
|
|
|
+ filename = info['key']
|
|
|
filepath = str(info['site_id']) + '/' + day[0] + '/' + day[1] + '/' + day[2]
|
|
|
+ filepath = File.mkdirs(os.path.join(Demeter.path, 'runtime','files', filepath))
|
|
|
else:
|
|
|
+ # 本地的
|
|
|
filename = info['name']
|
|
|
filepath = info['path']
|
|
|
+ info['host'] = ''
|
|
|
|
|
|
- if 'save' in Demeter.config['setting']:
|
|
|
- filepath = File.mkdirs(os.path.join(Demeter.config['setting']['save'], filepath)) + '/' + filename
|
|
|
- else:
|
|
|
- filepath = File.mkdirs(os.path.join(Demeter.path, 'runtime','files', filepath)) + '/' + filename
|
|
|
+ filepath = File.mkdirs(filepath) + '/' + filename
|
|
|
|
|
|
info['file'] = filepath + info['ext']
|
|
|
info['path'] = filepath + '/'
|
|
|
+
|
|
|
if File.exists(info['file']):
|
|
|
return info
|
|
|
else:
|
|
@@ -100,7 +103,7 @@ class Parser(object):
|
|
|
self.download(info['source'], info['file'])
|
|
|
if True:
|
|
|
File.mkdir(info['path'])
|
|
|
- obj = Demeter.service('loader', 'extract').get(info['file'], {'path':info['path']})
|
|
|
+ obj = Demeter.service('loader', 'extract').get(info['file'], {'path':info['path'], 'host':info['host']})
|
|
|
func = getattr(obj, method)
|
|
|
result = func()
|
|
|
if result and 'page' in result and result['page'] > 0:
|