The integrated Python has integrated with some modules. But there is always needs to use custom modules. Here is a script to upload the .py
file to a table and load it as a module.
Appreciate to share other solutions, eg. a folder to upload custom script?
"""
The script is attached to a table '_lib' which contains Python module files.
Columns of table "_lib":
module: text
file: file
Upload the Python module file to the table and define a module name.
Use `load(module_name)` to load the module file. The file will be downloaded to
Python running folder, and named as the module name defined in the table.
"""
# Init SeaTable API
from seatable_api import Base, context
server_url = context.server_url
api_token = context.api_token
base = Base(api_token, server_url)
base.auth()
def main():
Seatable = load('module_name')
# Code goes here
return None
def load(module, lib = '_lib'):
import importlib
mod = base.query(f"SELECT * from {lib} WHERE module = '{module}'")
url = mod[0]['file'][0]['url']
base.download_file(url, f"{module}.py")
return importlib.import_module(module)
main()