Spaces:
Runtime error
Runtime error
File size: 2,395 Bytes
299e542 08a50ee e4a574e 323d7c9 db192d0 69809b7 299e542 d371089 299e542 d371089 299e542 d371089 299e542 d371089 299e542 db192d0 323d7c9 bf55c22 323d7c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | from app_vars import *
from bs4 import BeautifulSoup as bs
import random as r
import requests
from PIL import Image
from io import BytesIO
import binascii
headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
"Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"Cache-Control": "max-age=0",
"Cookie": """mindat=n5e0bck7vvnn6e0o9tkb49fs75; cf_clearance=PMEAfGmJF_UGxZYgB2jsRx5KsiZyNf2plDbXs4HoN5I-1703800389-0-2-d8c97f25.71e5db39.8fc820c5-0.2.1703800389""",
"Dnt": """1""",
"If-Modified-Since": """Sat, 17 Apr 2021 18:41:12 GMT""",
"If-None-Match": "607b2bc8-956c4",
"Prefer": "safe",
"Sec-Ch-Ua": r'"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",}
def get_gallery_image_list_from_rock_id(chosen_rock_id):
system(
f'{curl_invoker} -A "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion" -o "{rs}/app_data/html/index.html" https://www.mindat.org/gm/{chosen_rock_id}'
)
with open(f"{rs}\\app_data\\html\\index.html", "rb") as f:
soup = bs(f, "html.parser")
image_list = []
for i in soup.find_all("img"):
image_list.append("https://www.mindat.org" + i.get("src"))
return image_list
rl = load(open(f"{rs}/app_data/rock_urls_list.json"))
rl_keys = list(rl.keys())
def rand_rock_key():
return r.choice(rl_keys)
def url_of_rock(rock_name):
return r.choice(rl[rock_name])
def get_rock_name_url():
name = rand_rock_key()
url = url_of_rock(name)
# system(f'{curl_invoker} -A "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion" {url}')
img = requests.get(url,headers = headers).content
print(img.decode("ascii"))
return name, Image.open(BytesIO(binascii.unhexlify(img)))
|