Created
July 13, 2021 15:09
-
-
Save oeway/d9e030f545cf843290fe4951ec49b657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<docs lang="markdown"> | |
[TODO: write documentation for this plugin.] | |
</docs> | |
<config lang="json"> | |
{ | |
"name": "DownloadFileWebPython", | |
"type": "web-python", | |
"version": "0.1.0", | |
"description": "[TODO: describe this plugin with one sentence.]", | |
"tags": [], | |
"ui": "", | |
"cover": "", | |
"inputs": null, | |
"outputs": null, | |
"flags": [], | |
"icon": "extension", | |
"api_version": "0.1.8", | |
"env": "", | |
"permissions": [], | |
"requirements": [], | |
"dependencies": [] | |
} | |
</config> | |
<script lang="python"> | |
from js import fetch | |
from imjoy import api | |
async def download_file(url, save_to): | |
''' | |
Download a file and save it in file system | |
Note the URL must support CORS | |
e.g. you can start a server locally with python -m http.server 9000 | |
then access the files from http://127.0.0.1:9000 | |
''' | |
response = await fetch(url) | |
content = await response.arrayBuffer() | |
bytes = content.to_py().tobytes() | |
with open(save_to, 'wb') as f: | |
f.write(bytes) | |
class ImJoyPlugin(): | |
async def setup(self): | |
await download_file("https://sandbox.zenodo.org/api/files/69d1a750-7eb0-4ec8-bb95-2acb8da5f023/rdf.yaml", | |
"/tmp/rdf.yaml") | |
content = open('/tmp/rdf.yaml').read() | |
await api.alert(content) | |
def run(self, ctx): | |
api.alert('hello world.') | |
api.export(ImJoyPlugin()) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment