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.
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
|
||||
|
@ -13,7 +15,7 @@ pipx install git+https://moli-git.zapto.org/moli/aecpic.git
|
|||
|
||||
# Run
|
||||
|
||||
on inside Anvil.
|
||||
On inside Anvil.
|
||||
|
||||
```
|
||||
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 os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import json
|
||||
import click
|
||||
|
@ -45,18 +44,21 @@ def download(url):
|
|||
>>> assert r != ''
|
||||
'''
|
||||
|
||||
cr = subprocess.run(['curl', url], capture_output = True)
|
||||
if cr.returncode != 0:
|
||||
raise RuntimeError('Downlad failed.')
|
||||
r = requests.get(url)
|
||||
suffix = getSuffix(r.content)
|
||||
|
||||
#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
|
||||
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode='wb',
|
||||
delete=False,
|
||||
suffix=suffix) as f:
|
||||
f.write(cr.stdout)
|
||||
f.write(r.content)
|
||||
filename = f.name
|
||||
return filename
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue