Skip to content

Instantly share code, notes, and snippets.

@mihalt
Created November 6, 2024 07:58
Show Gist options
  • Save mihalt/3ebdc2cd4770a82542cab625064d26fe to your computer and use it in GitHub Desktop.
Save mihalt/3ebdc2cd4770a82542cab625064d26fe to your computer and use it in GitHub Desktop.
mutual_contacts_finding
from typing import List
from skpy import SkypeUtils, SkypeConnection, Skype as OriginalSkype
from skpy.user import SkypeContacts, SkypeUser as OriginalSkypeUser
@SkypeUtils.initAttrs
class SkypeUser(OriginalSkypeUser):
attrs = OriginalSkypeUser.attrs + ('mutual_friend_count',)
defaults = dict(OriginalSkypeUser.defaults, mutual_friend_count=0)
@classmethod
def rawToFields(cls, raw=None):
raw = raw or {}
fields = super().rawToFields(raw)
fields['mutual_friend_count'] = raw.get('mutual_friend_count', 0)
return fields
class SkypeContactsExtended(SkypeContacts):
@SkypeUtils.cacheResult
def search(self, query) -> List[SkypeUser]:
results = self.skype.conn("GET", "https://skypegraph.skype.com/v2.0/search",
auth=SkypeConnection.Auth.SkypeToken,
params={"searchString": query, "requestId": "Query0", "locale": "ru-RU",
"sessionId": self.skype.conn.endpoints.get('main').id.strip(
"{}")}).json().get("results", [])
users = []
for json in results:
raw = json.get("nodeProfileData", {})
mutual_friend_count = json.get('nodeConnectionData', {}).get('mutualFriendCount', 0)
raw['mutual_friend_count'] = mutual_friend_count
users.append(SkypeUser.fromRaw(self.skype, raw))
return users
class Skype(OriginalSkype):
def __init__(self, user=None, pwd=None, tokenFile=None, connect=True):
super().__init__(user, pwd, tokenFile, connect)
self.contacts = SkypeContactsExtended(self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment