Skip to content

Commit

Permalink
edit_profile, get_profile_data methods. Dependencies version rang…
Browse files Browse the repository at this point in the history
…es. v0.6.0
  • Loading branch information
somespecialone committed Aug 18, 2024
1 parent 557125f commit f28200d
Show file tree
Hide file tree
Showing 6 changed files with 683 additions and 505 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ poetry add aiosteampy[all]
AIOSTEAMPY use [aiohttp](https://github.com/aio-libs/aiohttp) underneath to do asynchronous requests to steam servers,
with modern async/await syntax.

## Key features
## Key features

- **Stateless**: low-middle layer API wrapper of some steam services and methods like market,
tradeoffers, confirmations, steamguard, etc.
Expand All @@ -98,7 +98,7 @@ with modern async/await syntax.
- Get apps, packages.
- All, that need connection to CM.
- Interact with game servers (inspect CS2 (ex. CSGO) items, ...).
- Edit profile, social interaction(groups, clans). **(changes planned!)**
- Social interaction(groups, clans).
- Handle entities (listings, items, tradeoffers) lifecycle for easy if you need to store it.

<!--intro-end-->
Expand All @@ -124,13 +124,14 @@ but not otherwise.

- [x] Listings, items, offers pagination/iteration
- [x] Get single item from inventory as browser does
- [ ] Change client username method
- [x] Change client username method

### v0.7.0

- [x] Remove storage methods. Caching entities must be user responsibility
- [x] Rename `fetch_...` methods to `get_...` to remove annoying methods symantic mess
- [ ] Web browser mechanism to fetch trade offers from `Steam`, avoiding `Steam Web Api`
- [ ] Edit profile privacy settings

### v0.8.0

Expand Down
2 changes: 2 additions & 0 deletions aiosteampy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ async def prepare(self, api_key_domain: str = None, *, force=False):
self.country = wallet_info["wallet_country"]
self.currency = Currency(wallet_info["wallet_currency"])

# TODO change privacy settings (inventory, profile)

async def get_wallet_info(self) -> WalletInfo:
"""
Fetch wallet info from inventory page.
Expand Down
88 changes: 86 additions & 2 deletions aiosteampy/mixins/profile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from urllib.parse import quote
from re import search as re_search
from json import loads as jloads

from yarl import URL

from ..constants import STEAM_URL
from ..exceptions import EResultError
from ..constants import STEAM_URL, EResult
from ..typed import ProfileData
from ..utils import to_int_boolean
from .login import LoginMixin


Expand All @@ -27,6 +31,12 @@ def trade_url(self) -> URL | None:
def profile_url(self) -> URL:
return STEAM_URL.COMMUNITY / f"profiles/{self.steam_id}"

async def get_profile_url_alias(self) -> URL:
"""Get profile url alias like `https://steamcommunity.com/id/alias`"""

r = await self.session.get(STEAM_URL.COMMUNITY / "my", allow_redirects=False)
return URL(r.headers["Location"])

async def register_new_trade_url(self) -> URL:
"""Register new trade url. Cache token."""

Expand All @@ -49,4 +59,78 @@ async def get_trade_token(self) -> str | None:
self.trade_token = search["token"] if search else None
return self.trade_token

# TODO change nickname method
async def get_profile_data(self, profile_alias: URL = None) -> ProfileData:
"""Fetch profile settings data"""

if profile_alias is None:
profile_alias = await self.get_profile_url_alias()
r = await self.session.get(profile_alias / "edit/info")
rt = await r.text()

return jloads(re_search(r"data-profile-edit=\"(.+)\" data-profile-badges", rt)[1].replace("&quot;", '"'))

async def edit_profile(
self,
*,
persona_name: str = None,
real_name: str = None,
summary: str = None,
country: str = None,
state: str = None,
city: str = None,
custom_url: str = None,
hide_profile_award: bool = None,
):
"""
Edit profile data
:param persona_name: nickname
:param real_name: real name of the user
:param summary: profile summary
:param country:
:param state:
:param city:
:param custom_url: custom url `ALIAS` (`https://steamcommunity.com/id/ALIAS`)
:param hide_profile_award:
:raises EResultError: for ordinary reasons
"""

args = [persona_name, real_name, summary, country, state, city, custom_url, hide_profile_award]
if all(map(lambda x: x is None, args)):
raise ValueError("You need to pass at least one value")

profile_alias = await self.get_profile_url_alias()
profile_data = await self.get_profile_data(profile_alias)

# https://github.com/DoctorMcKay/node-steamcommunity/blob/1067d4572ee9d467e8f686951901c51028c5c995/components/profile.js#L56
data = {
"sessionID": self.session_id,
"type": "profileSave",
"hide_profile_awards": "0",
"json": 1,
"weblink_1_title": "",
"weblink_1_url": "",
"weblink_2_title": "",
"weblink_2_url": "",
"weblink_3_title": "",
"weblink_3_url": "",
# attr below
"personaName": persona_name if persona_name is not None else profile_data["strPersonaName"],
"real_name": real_name if real_name is not None else profile_data["strRealName"],
"hide_profile_award": to_int_boolean(hide_profile_award)
if hide_profile_award is not None
else profile_data["ProfilePreferences"]["hide_profile_awards"],
"summary": summary if summary is not None else profile_data["strSummary"],
"country": country if country is not None else profile_data["LocationData"]["locCountryCode"],
"state": state if state is not None else profile_data["LocationData"]["locStateCode"],
"city": city if city is not None else profile_data["LocationData"]["locCity"],
"customURL": custom_url if custom_url is not None else profile_data["strCustomURL"],
}
r = await self.session.post(profile_alias / "edit/", data=data)
rj = await r.json()
success = EResult(rj.get("success"))
if success is not EResult.OK:
raise EResultError(rj.get("message", "Failed to edit profile"), success, rj)

# async def set_privacy_settings(self):
# pass
44 changes: 44 additions & 0 deletions aiosteampy/typed.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,47 @@ class JWTToken(TypedDict):
per: int
ip_subject: str
ip_confirmer: str


class LocationData(TypedDict):
locCity: str
locCityCode: int
locCountry: str
locCountryCode: str
locState: str
locStateCode: str


class ProfilePrivacySettings(TypedDict):
PrivacyFriendsList: int
PrivacyInventory: int
PrivacyInventoryGifts: int
PrivacyOwnedGames: int
PrivacyPlaytime: int
PrivacyProfile: int


class ProfilePrivacy(TypedDict):
PrivacySettings: ProfilePrivacySettings
eCommentPermission: int


class ProfilePreferences(TypedDict):
hide_profile_awards: int


class ProfileData(TypedDict):
strPersonaName: str
strCustomURL: str
strRealName: str
strSummary: str
strAvatarHash: str
rtPersonaNameBannedUntil: str
rtProfileSummaryBannedUntil: str
rtAvatarBannedUntil: str
LocationData: LocationData
# ActiveTheme
ProfilePreferences: ProfilePreferences
# rgAvailableThemes
# rgGoldenProfileData
Privacy: ProfilePrivacy
Loading

0 comments on commit f28200d

Please sign in to comment.