Created
January 20, 2024 12:50
-
-
Save philipsinnott/4ca35e18b0a39002149ebddb0b7d7cee to your computer and use it in GitHub Desktop.
Enter a users Steam ID and see how many hours they've played games for the past 2 weeks.
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
import requests | |
# Steam ID example: 76561198833313974 | |
api_key = "<REDACTED>" | |
print("Enter Steam ID:") | |
user_steamid = input() | |
user_data = requests.get(f"http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={api_key}&steamids={user_steamid}").json()["response"]["players"][0] | |
user_data_name = user_data["personaname"] | |
game_data = requests.get(f"http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v0001/?key={api_key}&steamid={user_steamid}&format=json").json()["response"]["games"] | |
def get_hours_2weeks(): | |
playtime_2weeks = 0 | |
for item in game_data: | |
minutes = item["playtime_2weeks"] | |
playtime_2weeks += minutes | |
return playtime_2weeks / 60 | |
print(f'{user_data_name } has played for {get_hours_2weeks()} hours the past 2 weeks.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment