This repository has been archived on 2024-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
marsho-alpha/util.py
2024-09-17 20:20:31 +08:00

17 lines
548 B
Python

import random
import os
import aiohttp
import httpx
from pathlib import Path
BGIMAGE_PATH=Path('/home/asankilp/biography/User/RavenSenorita/sayings')
def choose_random():
randomfile = random.choice(list(BGIMAGE_PATH.iterdir()))
randomurl = str(randomfile)
return randomurl
async def download_file(url):
async with httpx.AsyncClient() as client:
response = await client.get(url)
response.raise_for_status() # 确保请求成功
with open("./azureaipic.png", 'wb') as f:
f.write(response.content)