Skip to content

Instantly share code, notes, and snippets.

@dgnsrekt
Created December 8, 2021 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgnsrekt/a3efae6d252a1db0eaa35ea705694091 to your computer and use it in GitHub Desktop.
Save dgnsrekt/a3efae6d252a1db0eaa35ea705694091 to your computer and use it in GitHub Desktop.
quick_wine_script.py
from requests_html import HTMLSession
import pydantic
class WineModel(pydantic.BaseModel):
name: str
price: str
varietal: str
description: str
session = HTMLSession()
import random
URL = "https://www.wines.com/wine-varietals/"
response = session.get(URL)
varietals = [varietal.text for varietal in response.html.find("h5")]
URL = "https://top100.winespectator.com/lists/"
response = session.get(URL)
for row in response.html.find("tbody", first=True).find("tr"):
wine_details = row.find(".wineName", first=True)
wine_name = wine_details.find("span.sort-text", first=True).text
*location, year, extra = wine_details.text.split(" ")
price = row.find(".price", first=True).text.replace("$", "")
note = row.find(".tabel-note", first=True).text.split("\n")
note.pop()
details = "\n".join(note)
if year.isdigit() is False:
continue
if price.isdigit() is False:
continue
location = " ".join(location).replace(wine_name, "").strip()
price = "$" + price
varietal = random.choice(varietals)
wine = WineModel(
name=wine_name, price=price, varietal=varietal, description=details
)
# print(wine.json())
URL = "https://papaplatoon-wine-api.herokuapp.com/api/wines/"
response = session.post(URL, data=wine.json())
print(response.status_code)
print(response.json())
# print(wine_name, location, year, price)
# print(varietal)
# print(details)
# print()
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment