Skip to content

Commit

Permalink
Release 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xriskon committed Jul 25, 2021
1 parent 9548706 commit df076dd
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 70 deletions.
4 changes: 4 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## [0.1](https://github.com/#)
**Initial Realese**
38 changes: 17 additions & 21 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ def print_logo():


def command_list():
print("[propic]\tDownload profile picture")
print("[info]\t\tDisplay summary of user")
print("[friends]\tDisplay all friends")
print("[recpl]\t\tDisplay recently played games")
print("[games]\t\tDisplay all owned games")
print("[list]\t\tShow command list")
print("[quit]\t\tExit program")
print("[target]\tchange target user")
print("[info]\t\tdisplay summary of user")
print("[friends]\tdisplay all friends")
print("[games]\t\tdisplay all owned games")
print("[list]\t\tshow command list")
print("[quit]\t\texit program")
print("[FILE=y]\tenable saving to file")
print("[FILE=n]\tdisable saving to file")


def _quit():
Expand All @@ -33,30 +34,25 @@ def _quit():
api = Steam(args.get("id"), args.get("output"))

commands = {
'list': command_list,
'help': command_list,
'quit': _quit,
'exit': _quit,
'propic': api.get_profile_picture,
'info': api.get_info,
'friends': api.get_friends_list,
"recpl": api.get_recently_played,
'games': api.get_owned_games
'TARGET': api.change_target,
'LIST': command_list,
'HELP': command_list,
'QUIT': _quit,
'EXIT': _quit,
'INFO': api.get_info,
'FRIENDS': api.get_friends_list,
'GAMES': api.get_owned_games
}


print_logo()
api.print_banner()
while True:
cmd = input("New command:")
cmd = input("New command:").upper()
_cmd = commands.get(cmd)

if _cmd:
_cmd()
elif cmd.upper() == "FILE=Y":
api.set_write_file(True)
elif cmd.upper() == "FILE=Y":
api.set_write_file(False)
elif cmd == "":
print("")
else:
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
argparse~=1.4.0
requests~=2.25.1
requests~=2.25.1
xmltodict~=0.12.0
xlsxwriter~=1.4.4
prettytable~=2.1.0
147 changes: 99 additions & 48 deletions src/steam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from src import config
import xlsxwriter
from prettytable import PrettyTable
import xmltodict
# import xlsxwriter
import requests
import json
import sys


Expand All @@ -15,33 +16,49 @@ class Steam:
def __init__(self, user, write_file):
self.api = config.get_api_key()
self.write_file = write_file
# response = requests.get("")
# if response.status_code != 200:
# print(f"Error contancting with steam API\nStatus Code: {response.status_code}")
# sys.exit(1)

# workbook = xlsxwriter.Workbook("output/info.xlsx")
# worksheet = workbook.add_worksheet()
# worksheet.set_column('A:A', 20)
# bold = workbook.add_format({'bold': True})
# worksheet.write('A1', 'Hello')
# worksheet.write('B2', 'World', bold)
# worksheet.write(2, 0, 123)
# worksheet.write(3, 0, 123.456)
# workbook.close()

# self.steamID = data["steamID"]
# self.steamID64 = data["steamID64"]
# self.is_private = data["is_private"]
# self.write_file = write_file

def __search_user(self, user):
data = self.__search_user(user)
if not data["found"]:
print("Error")
sys.exit(1)

self.steamID = data["steamID"]
self.steamID64 = data["steamID64"]
self.is_private = data["is_private"]
self.write_file = write_file

@staticmethod
def __search_user(target):
result = {
"steamID": None,
"steamID64": None,
"is_private": True,
"found": False
}

response = requests.get(f"https://steamcommunity.com/profiles/{target}/?xml=1")
data = xmltodict.parse(response.content)
if "response" in data:
response = requests.get(f"http://steamcommunity.com/id/{target}/?xml=1")
data = xmltodict.parse(response.content)
if not ("response" in data):
result["steamID"] = data["profile"]["steamID"]
result["steamID64"] = data["profile"]["steamID64"]
if data["profile"]['privacyState'] == "public":
result["is_private"] = False
else:
result["is_private"] = True
result["found"] = True
else:
result["found"] = False
else:
result["steamID"] = data["profile"]["steamID"]
result["steamID64"] = data["profile"]["steamID64"]
if data["profile"]['privacyState'] == "public":
result["is_private"] = False
else:
result["is_private"] = True
result["found"] = True

return result

def print_banner(self):
Expand All @@ -55,36 +72,70 @@ def change_target(self):
data = self.__search_user(_user)
if data.get("found"):
self.set_target(data)

def set_target(self, target):
_user = input("New target: ")
data = self.__search_user(_user)
if data.get("found"):
self.steamID = data.get("steamID")
self.steamID64 = data.get("steamID64")
self.is_private = data.get("is_private")
else:
print(f'User "{_user}" not found')

def set_write_file(self, flag):
if flag:
print("Write to File: ENABLED")
else:
print(r"Write to File: DISABLED")
print("User was not found")

self.write_file = flag
def set_target(self, data):
self.steamID = data.get("steamID")
self.steamID64 = data.get("steamID64")
self.is_private = data.get("is_private")

def get_info(self):
pass

def get_recently_played(self):
pass
response = requests.get(f"https://steamcommunity.com/profiles/{self.steamID64}/?xml=1")
data = xmltodict.parse(response.content)["profile"]
if not ("customURL" in data):
data["customURL"] = "None"
if not ("realname" in data):
data["realname"] = "None"
if not ("location" in data):
data["location"] = "None"
if not ("memberSince" in data):
data["memberSince"] = "None"
result = f"SteamID64: {data['steamID64']}\nCustomURL: {data['customURL']}\nUsername: {data['steamID']}\nReal Name: {data['realname']}\n" \
f"Location: {data['location']}\nVac Ban: {data['vacBanned']}\nTrade Ban: {data['tradeBanState']}\nOnline State: {data['onlineState']}\n" \
f"Privacy State: {data['privacyState']}\nMemberSince: {data['memberSince']}"
print(result)

def get_friends_list(self):
pass
response = requests.get(f"http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key={self.api}&steamid={self.steamID64}&relationship=friend")
data = response.json()
table = PrettyTable()
table.field_names = ["Steam ID", "Username", "Profile State", "Friends Since"]
for friend in data["friendslist"]["friends"]:
friendResponse = requests.get("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s" % (self.api, friend["steamid"]))
_user = friendResponse.json()
state = _user["response"]["players"][0]["personastate"]
if state == 1:
_user["response"]["players"][0]["personastate"] = "Online"
elif state == 2:
_user["response"]["players"][0]["personastate"] = "Invisible"
elif state == 3:
_user["response"]["players"][0]["personastate"] = "Away"
else:
_user["response"]["players"][0]["personastate"] = "Offline"

table.add_row([friend["steamid"], _user["response"]["players"][0]["personaname"],
_user["response"]["players"][0]["personastate"], friend["friend_since"]])

print(table)

def get_owned_games(self):
pass

def get_profile_picture(self):
pass
response = requests.get(f"http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key={self.api}&steamid={self.steamID64}&format=json&include_appinfo=true")
data = response.json()["response"]["games"]
table = PrettyTable()
table.field_names = ["App ID", "Title", "Playtime"]
for game in data:
table.add_row([game["appid"], game["name"], game["playtime_forever"]])
print(table)

# TODO: ADD ABILITY TO EXPORT DATA IN EXCEL FILE
# Sample code below
# workbook = xlsxwriter.Workbook("output/info.xlsx")
# worksheet = workbook.add_worksheet()
# worksheet.set_column('A:A', 20)
# bold = workbook.add_format({'bold': True})
# worksheet.write('A1', 'Hello')
# worksheet.write('B2', 'World', bold)
# worksheet.write(2, 0, 123)
# worksheet.write(3, 0, 123.456)
# workbook.close()

0 comments on commit df076dd

Please sign in to comment.