From 95eadbb475a4f55d02068835c0734c09f615ff52 Mon Sep 17 00:00:00 2001 From: mrlolethan Date: Wed, 11 Mar 2015 16:46:17 -0230 Subject: [PATCH] Initial commit. --- .gitignore | 60 +++++++++++++++++++++++++++++++++++++++++++++ test.py | 14 +++++++++++ username_to_uuid.py | 25 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 test.py create mode 100644 username_to_uuid.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bcea8a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# Created by https://www.gitignore.io + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + diff --git a/test.py b/test.py new file mode 100644 index 0000000..4582d28 --- /dev/null +++ b/test.py @@ -0,0 +1,14 @@ +from username_to_uuid import UsernameToUUID +import sys + + +print("Please enter a username: ") +username = sys.stdin.readline().rstrip() + +converter = UsernameToUUID(username) +uuid = converter.get_uuid() + +if (uuid is not ""): + print("That player's UUID is: " + uuid) +else: + print("That player was not found.") diff --git a/username_to_uuid.py b/username_to_uuid.py new file mode 100644 index 0000000..eb91780 --- /dev/null +++ b/username_to_uuid.py @@ -0,0 +1,25 @@ +""" Username to UUID + Converts a Minecraft username to it's UUID equivalent. + +Parses http://www.lb-stuff.com/Minecraft-Name-History output to retrieve the UUID + of an old name that's no longer in use. +""" +import http.client + +from bs4 import BeautifulSoup + + +class UsernameToUUID: + def __init__(self, username): + self.username = username + + def get_uuid(self): + """ + Get the UUID of the player. + """ + httpConn = http.client.HTTPConnection("www.lb-stuff.com"); + httpConn.request("GET", "/Minecraft-Name-History?user=" + self.username); + response = httpConn.getresponse().read() + soup = BeautifulSoup(response) + + return soup.body.findAll('p')[1].findAll('code')[1].text