Changed to use "Request" to download files.

Added a example image.
This commit is contained in:
Shinya Koyano 2025-04-10 16:09:54 +09:00
parent 4aec6e000b
commit 4f08105ba4
Signed by: moli
GPG key ID: 61EDE6AC103CC456
3 changed files with 13 additions and 9 deletions

View file

@ -2,6 +2,8 @@
Anvil extension that downloads an image and sets it as the background.
![Example](example.webp)
----
@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View file

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