Changed to use "Request" to download files.
Added a example image.
This commit is contained in:
parent
4aec6e000b
commit
4f08105ba4
3 changed files with 13 additions and 9 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
Anvil extension that downloads an image and sets it as the background.
|
Anvil extension that downloads an image and sets it as the background.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +15,7 @@ pipx install git+https://moli-git.zapto.org/moli/aecpic.git
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
|
|
||||||
on inside Anvil.
|
On inside Anvil.
|
||||||
|
|
||||||
```
|
```
|
||||||
aecpic https://moli-green.xyz/img.webp
|
aecpic https://moli-green.xyz/img.webp
|
||||||
|
|
BIN
example.webp
Normal file
BIN
example.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
|
@ -1,10 +1,9 @@
|
||||||
'''
|
'''
|
||||||
get a picture at some url in use curl, then open new anvil window and set the picture to background picture on to the window.
|
It download an image useing HTTP or HTTPS protocol, Download the image file from URL, and set it as background of Anvil Editor window.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import json
|
import json
|
||||||
import click
|
import click
|
||||||
|
@ -45,18 +44,21 @@ def download(url):
|
||||||
>>> assert r != ''
|
>>> assert r != ''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
cr = subprocess.run(['curl', url], capture_output = True)
|
r = requests.get(url)
|
||||||
if cr.returncode != 0:
|
suffix = getSuffix(r.content)
|
||||||
raise RuntimeError('Downlad failed.')
|
|
||||||
|
#cr = subprocess.run(['curl', url], capture_output = True)
|
||||||
|
#if cr.returncode != 0:
|
||||||
|
# raise RuntimeError('Downlad failed.')
|
||||||
|
#
|
||||||
|
#suffix = getSuffix(cr.stdout)
|
||||||
|
|
||||||
suffix = getSuffix(cr.stdout)
|
|
||||||
filename = None
|
filename = None
|
||||||
|
|
||||||
with tempfile.NamedTemporaryFile(
|
with tempfile.NamedTemporaryFile(
|
||||||
mode='wb',
|
mode='wb',
|
||||||
delete=False,
|
delete=False,
|
||||||
suffix=suffix) as f:
|
suffix=suffix) as f:
|
||||||
f.write(cr.stdout)
|
f.write(r.content)
|
||||||
filename = f.name
|
filename = f.name
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue