How to get personaname with steamid64?

All other Source.Python topics and issues.
l1tSky
Junior Member
Posts: 1
Joined: Sun Jan 23, 2022 5:06 am

How to get personaname with steamid64?

Postby l1tSky » Sun Jan 23, 2022 5:32 am

Hello, i'm very new to Python.

I have a script that reads a logfile and sends messages to a discord channel if it finds certain lines.

The problem is, i get only a SteamID64 from the logfile.
Right now the bot sends the SteamID64, but i want to convert it and send their username to discord instead.

I tried to implement the code i found here https://forums.sourcepython.com/viewtopic.php?t=1303. Having trouble to understand and rewrite it, to use a set SteamID64 instead of SteamID.

In this file i set "SteamID64" for later use with the SteamAPI (tested the var, it contains the SteamID64)

Syntax: Select all

async def connection():
while True:
with open(log, encoding='utf-8', mode='r') as f:
f.seek(0,2)
while True:
line = f.readline()
if(re.search(pconnect, line)):
pname = re.search(pconnect, line).group(1)
with open('csv/connectlog.csv', 'a', newline='', encoding='utf-8') as dl:
curtime = await timenow()
deathup = csv.writer(dl, delimiter=',')
deathup.writerow([curtime, pname, ' connected.'])
print(curtime, pname, ' connected to the Winterfall server.')
steamid64 = pname
await asyncio.sleep(0.2)


This is where i try to implement the code (not working - error: empty var "SteamID")

Syntax: Select all

async def mainloop(file):
await bot.wait_until_ready()
lchannel = bot.get_channel(lchanID)
print('Main loop: init')
try:
testfile = open(file)
testfile.close()
while not bot.is_closed():
with open(file, encoding='utf-8', mode='r') as f:
f.seek(0, 2)
while True:
line = f.readline()
if(re.search(pconnect, line)):
pname = re.search(pconnect, line).group(1)
STEAM_WEB_API_KEY = "XXXXXXXXXXXXXXXXXXXX" # Get your own @ http://steamcommunity.com/dev/apikey
STEAM_GET_PLAYER_SUMMARIES_URL = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={api_key}&steamids={steamid}"
SteamID = steamid64.parse(player.steamid64).to_uint64()
with urlopen(STEAM_GET_PLAYER_SUMMARIES_URL.format(api_key=STEAM_WEB_API_KEY, steamid=steamid64)) as response:
profile_info = json.loads(response.read().decode('utf-8'))['response']['players'][0]
print("Custom URL: {}".format(profile_info['profileurl'])) # Custom URL: http://steamcommunity.com/id/its_iPlayer/
if(re.search(pdeath, line)):
pname = re.search(pdeath, line).group(1)
await lchannel.send(':headstone: **' + pname + '** just died!')
if(re.search(pevent, line)):
eventID = re.search(pevent, line).group(1)
await lchannel.send(':crossed_swords: Random mob event: **' + eventID + '** has occurred')
if(re.search(pconnect, line)):
pname = re.search(pconnect, line).group(1)
await lchannel.send(':white_check_mark: **' + personaname + '** connected to the Winterfall server.')
if(re.search(pdisconnect, line)):
pname = re.search(pdisconnect, line).group(1)
await lchannel.send(':x: **' + personaname + '** disconnected from the Winterfall server.')
await asyncio.sleep(0.2)
except IOError:
print('No valid log found, event reports disabled. Please check config.py')
print('To generate server logs, run server with -logfile launch flag')

Return to “General Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 38 guests