Skip to content

Commit

Permalink
Update py config like js
Browse files Browse the repository at this point in the history
  • Loading branch information
FongMi committed Dec 11, 2023
1 parent 866e0bd commit d9c64e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ private void init(Context context) {
}

@Keep
public Spider spider(Context context, String name, String api) {
public Spider spider(Context context, String key, String api) {
if (app == null) init(context);
PyObject obj = app.callAttr("init_py", cache, name, api);
PyObject obj = app.callAttr("init_py", cache, key, api);
return new Spider(app, obj);
}
}
19 changes: 10 additions & 9 deletions pyramid/src/main/python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@ def redirect(url):
return rsp


def download_file(name, ext):
if ext.startswith('http'):
write_file(name, redirect(ext).content)
def download_file(name, api):
if api.startswith('http'):
write_file(name, redirect(api).content)
else:
write_file(name, str.encode(ext))
write_file(name, str.encode(api))


def init_py(path, name, ext):
py_name = path + '/' + name + '.py'
download_file(py_name, ext)
return SourceFileLoader(name, py_name).load_module().Spider()
def init_py(cache, key, api):
name = os.path.basename(api)
path = cache + '/' + name
download_file(path, api)
return SourceFileLoader(name, path).load_module().Spider()


def str2json(content):
return json.loads(content)


def init(ru, extend):
ru.init([""])
ru.init(extend)


def homeContent(ru, filter):
Expand Down

0 comments on commit d9c64e9

Please sign in to comment.