Skip to content

Instantly share code, notes, and snippets.

@sandorkazi sandorkazi/bgg-hun-gotw.py
Last active Dec 21, 2018

Embed
What would you like to do?
BGGHunGotW
import requests
from bs4 import BeautifulSoup
from time import sleep
URL_already = 'https://www.boardgamegeek.com/xmlapi/geeklist/213988'
URL_thumbsup = 'https://boardgamegeek.com/geekrecommend.php?action=recspy&itemtype=geeklist&itemid=213988'
URL_user = 'https://www.boardgamegeek.com/xmlapi2/user?name={}&domain=boardgame'
soup = BeautifulSoup(requests.get(URL_already).content, 'xml')
sleep(1)
users_already = [item['username'] for item in soup.findAll('item')]
soup = BeautifulSoup(requests.get(URL_thumbsup).content, 'html.parser')
tipped = soup.find('div', text='Tipped By')
for i in tipped.findAllNext():
i.extract()
tipped.extract()
users_thumbsup = [
i.getText() for i in soup.findAll('div')[-1].findAllNext('a')
]
users_from = set(users_thumbsup) - set(users_already)
print(', '.join(map(lambda x: x, users_from)))
def get_name(user):
soup = BeautifulSoup(requests.get(URL_user.format(user)).content, 'xml')
try:
lastname = soup.find('lastname')['value']
except (TypeError, AttributeError):
lastname = ''
try:
firstname = soup.find('firstname')['value']
except (TypeError, AttributeError):
firstname = ''
return (lastname, firstname)
print('\n'.join([
'{}\t{} {}'.format(str.ljust(user, 15), *get_name(user)) for user in list(users_from)
]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.