Created
January 25, 2019 17:42
-
-
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
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
#!/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