Skip to content

Instantly share code, notes, and snippets.

@ariankordi
Last active August 30, 2017 05:26
Show Gist options
  • Save ariankordi/c866e241e1fbf66f3c8604f40b13acec to your computer and use it in GitHub Desktop.
Save ariankordi/c866e241e1fbf66f3c8604f40b13acec to your computer and use it in GitHub Desktop.
Yet another script to get someone's info from Miiverse BUT THEN returning as JSON
#!/usr/bin/python
from lxml import html
import urllib.request, urllib.error, sys, json
if not len(sys.argv) > 1:
print('Usage: %s [username]' % sys.argv[0])
sys.exit(1)
username = sys.argv[1]
try:
req = urllib.request.urlopen('https://miiverse.nintendo.net/users/{}/favorites?locale.lang=en-US'.format(username))
except urllib.error.HTTPError as error:
print('HTTP err ' + str(error.code))
sys.exit(1)
ftree = html.fromstring(req.read().decode())
username = ftree.xpath('//*[@id="sidebar-profile-body"]/p/text()')[0]
name = ftree.xpath('//*[@id="sidebar-profile-body"]/a/text()')[0]
mii = ftree.xpath('//*[@id="sidebar-profile-body"]/div/a/img/@src')[0]
comment = ftree.xpath('//*[@id="sidebar"]/div[3]/div[1]/p/text()')
banned = True if comment == 'Profile comment hidden by admin.' else False
followers = ftree.xpath('//*[@id="sidebar"]/div[2]/div/a[1]/span[2]/span/text()')[0]
posts = ftree.xpath('//*[@id="sidebar"]/div[2]/div/a[1]/span[2]/span/text()')[0]
yeahs = ftree.xpath('//*[@id="sidebar"]/div[2]/div/a[2]/span[2]/span/text()')[0]
print(json.dumps(
{
'username': username,
'name': name,
'mii': mii,
'happy': mii.replace('normal', 'happy'),
'comment': comment[0] if comment else "",
'posts': int(posts),
'yeahs': int(yeahs),
'followers': int(followers),
'banned': banned,
}
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment