Skip to content

Instantly share code, notes, and snippets.

@squarepegsys
Created January 25, 2019 17:42
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 squarepegsys/61b7d504967de78ca2e87181a3d20378 to your computer and use it in GitHub Desktop.
Save squarepegsys/61b7d504967de78ca2e87181a3d20378 to your computer and use it in GitHub Desktop.
Quick and dirty script to randomly choose a user from a forum thread at BGG
#!/usr/bin/env python
import xml.etree.ElementTree as ET
from urllib.request import urlopen
import random
import time
def seed():
t = int( time.time() * 1000.0 )
random.seed( ((t & 0xff000000) >> 24) +
((t & 0x00ff0000) >> 8) +
((t & 0x0000ff00) << 8) +
((t & 0x000000ff) << 24) )
thread_id = '2137833'
thread_xml = urlopen('https://api.geekdo.com/xmlapi2/thread?id={}'.format(thread_id))
tree = ET.parse(thread_xml)
root = tree.getroot()
articles_tag = root.find("./articles")
users = []
for art in articles_tag.findall(".//article/."):
user =art.attrib['username']
if user not in ('squarepegsys','jdarnold'):
users.append(user)
seed()
print(random.choice(users))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment