Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract UUID of users, get avatars using UUID (also fixes #29) #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions mclogalyzer/mclogalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
REGEX_IP = "(\d+)\.(\d+)\.(\d+)\.(\d+)"

REGEX_LOGIN_USERNAME = re.compile("\[Server thread\/INFO\]: ([^]]+)\[")
REGEX_UUID_USERNAME = re.compile("UUID of player ([^ ]+) is ([^ ]+)")
REGEX_LOGOUT_USERNAME = re.compile("\[Server thread\/INFO\]: ([^ ]+) lost connection")
REGEX_LOGOUT_USERNAME2 = re.compile(
"\[Server thread\/INFO\]:.*GameProfile.*name='?([^ ,']+)'?.* lost connection")
Expand Down Expand Up @@ -99,6 +100,7 @@ def capitalize_first(str):
class UserStats:
def __init__(self, username=""):
self._username = username
self._uuid = None
self._logins = 0

self._active_days = set()
Expand Down Expand Up @@ -298,6 +300,17 @@ def grep_login_username(line):
return username.decode("ascii", "ignore").encode("ascii", "ignore")



def grep_uuid(line):
search = REGEX_UUID_USERNAME.search(line)
if not search:
return ""
username = search.group(1).lstrip().rstrip()
uuid = search.group(2).lstrip().rstrip()
return username, uuid



def grep_logout_username(line):
search = REGEX_LOGOUT_USERNAME.search(line)
if not search:
Expand Down Expand Up @@ -443,6 +456,14 @@ def parse_logs(logdir, since=None, whitelist_users=None):
achievement_user = users[achievement_username]
achievement_user._achievement_count += 1
achievement_user._achievements.append(achievement)
elif "UUID of player" in line:
uuid_username, uuid = grep_uuid(line)
if not uuid_username or uuid_username.startswith("/"):
continue
if uuid_username not in users:
continue
user = users[uuid_username]
user._uuid = uuid
else:
death_username, death_type = grep_death(line)
death_time = grep_log_datetime(today, line)
Expand Down
6 changes: 3 additions & 3 deletions mclogalyzer/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h4>Columns</h4>
<td class="c-place"></td>
<td>
<a class="js-link" data-page="page-players-{{ user.username }}" href="#players-{{ user.username }}">
<img class="avatar" src="http://avatars.mapcrafter.org/head/{{ user.username }}/4" />{{ user.username }}
<img class="avatar" src="https://crafatar.com/avatars/{{ user._uuid }}?size=40" />{{ user.username }}
</a>
</td>
<td class="col c-time-played">{{ user.time }}</td>
Expand Down Expand Up @@ -241,7 +241,7 @@ <h4>Columns</h4>
{% for user in users %}
<div id="page-players-{{ user.username }}" class="page page-player row">
<div class="col-md-8">
<h4>Player Statistics for {{user.username }}</h4>
<h4>Player Statistics for {{user.username }} ({{user._uuid}})</h4>
<table class="table table-striped table-bordered">
<tr>
<th>Time Played:</th>
Expand Down Expand Up @@ -327,7 +327,7 @@ <h4>Player Statistics for {{user.username }}</h4>
</table>
</div>
<div class="col-md-4" style="text-align: center">
<img style="margin-top: 100px" src="http://avatars.mapcrafter.org/body/{{ user.username }}/8" />
<img style="margin-top: 100px" src="https://crafatar.com/renders/body/{{ user._uuid }}" />
</div>
</div>
{% endfor %}
Expand Down