Created
June 4, 2018 20:54
-
-
Save turnipsoup/164519143f234d04530c6e43f5711ba4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# In[5]: | |
import requests # Requesting HTML | |
import bs4 as bs # Parsing HTML | |
import json | |
import time | |
# In[6]: | |
ticket_object = {} # Instantiates ticket object | |
price_list = ["$1", "$2", "$3", "$5", "$10", "$20", "$30"] # Price of all tickets you wish to see | |
def ticketGetter(price): # This fuction makes an object of all tickets and their prizes remaining | |
ticket_object[price] = {} | |
url = "https://www.walottery.com/Scratch/TopPrizesRemaining.aspx?price=" + price | |
r = requests.get(url) # Queries site | |
soup = bs.BeautifulSoup(r.text, "lxml") | |
time.sleep(5) # We do this so we dont annoy the sysadmins of the lottery site | |
for item in soup.find_all("div", {"class": "prizes-remaining-item"}): | |
ticket_title = item.find("img").get("alt") # Gets title of ticket | |
ticket_object[price][ticket_title] = {} | |
ticket_object[price][ticket_title]["id"] = item.find("p").text.split("| ")[1] # Gets game ID for queries later | |
ticket_object[price][ticket_title]["image"] = item.find("img").get("src") # gets img source of ticket | |
ticket_object[price][ticket_title]["prizes"] = {} | |
time.sleep(10) | |
#total_ticket_getter(ticket_title, ticket_object[price][ticket_title]["id"]) | |
for row in item.find("table").find_all("tr"): | |
if (row.find("td")): | |
for value in row.find("td"): | |
ticket_object[price][ticket_title]["prizes"][value] = {} # This somehow gets the dollar value out... | |
row_list = row.find_all("td") | |
ticket_object[price][ticket_title]["prizes"][value]["total_prizes"] = row_list[1].text | |
ticket_object[price][ticket_title]["prizes"][value]["prizes_paid"] = row_list[2].text | |
ticket_object[price][ticket_title]["prizes"][value]["prizes_left"] = row_list[3].text | |
# In[8]: | |
for item in price_list: | |
ticketGetter(item) | |
# In[10]: | |
ticket_clone = ticket_object | |
# In[59]: | |
for item in ticket_object: | |
for ticket in ticket_object[item]: | |
for prize in ticket_object[item][ticket]["prizes"]: | |
percent_left = int(ticket_object[item][ticket]["prizes"][prize]["prizes_left"].replace(",", "")) / int(ticket_object[item][ticket]["prizes"][prize]["total_prizes"].replace(",", "")) | |
ticket_object[item][ticket]["prizes"][prize]["percent_left"] = percent_left * 100 | |
# In[65]: | |
ticket_list = [] | |
for item in ticket_object: | |
cost = item | |
for ticket in ticket_object[item]: | |
prize_list = [] | |
for prize in ticket_object[item][ticket]["prizes"]: | |
prize_list.append(ticket_object[item][ticket]["prizes"][prize]["percent_left"]) | |
if all(i >= 30 for i in prize_list) == True: | |
print("<img src='" + ticket_object[item][ticket]["image"] + "'>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment