Last active
May 22, 2020 14:01
-
-
Save orangepeelbeef/357ebe94a0251bca7e1812982cc732d7 to your computer and use it in GitHub Desktop.
Collect sony ps now games and show which ones have local / online co-op
This file contains hidden or 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
#!/usr/bin/python3 | |
import bs4 | |
import requests | |
import urllib | |
COUCH_COOP = [] | |
NET_COOP = [] | |
def print_output(collection): | |
for _c in collection: | |
print("Title: {}\tSystem: {}\tPlayers: {}".format(_c['title'], _c['system'], _c['players'])) | |
def check_cooptimus(title): | |
r = requests.get("http://api.co-optimus.com/games.php?search=true&name={}".format( | |
urllib.parse.quote(title))) | |
soup = bs4.BeautifulSoup(r.text, 'html.parser') | |
for _g in soup.find_all('game'): | |
# we only want results that are exact matches | |
if title == _g.title.get_text(): | |
# we only want results that are ps3 or ps4 | |
if _g.system.get_text() == 'Playstation 3' or \ | |
_g.system.get_text() == 'Playstation 4': | |
# if <local> > 0 add to couch_coop array | |
if int(_g.local.get_text()) > 0: | |
COUCH_COOP.append({ 'title': _g.title.get_text(), 'system': _g.system.get_text(), | |
'players': _g.local.get_text() | |
} ) | |
# if <online> > 0 add to net_coop array | |
if int(_g.online.get_text()) > 0: | |
NET_COOP.append({ 'title': _g.title.get_text(), 'system': _g.system.get_text(), | |
'players': _g.online.get_text() | |
}) | |
r = requests.get('https://www.playstation.com/en-us/explore/psnow/games/') | |
soup = bs4.BeautifulSoup(r.text, 'html.parser') | |
for _title in soup.find_all("li", class_="game-title"): | |
if _title: | |
check_cooptimus(_title.get_text()) | |
print("COUCH Co-OP") | |
print_output(COUCH_COOP) | |
print("ONLINE Co-OP") | |
print_output(NET_COOP) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment