Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #55 from quintindunn/development
Browse files Browse the repository at this point in the history
Added hashed_phone_number to Profile class.
  • Loading branch information
quintindunn authored Nov 11, 2023
2 parents ef3f12d + 11a226f commit a5d285d
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 4 deletions.
10 changes: 10 additions & 0 deletions examples/get_current_user/get_current_user_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

from lapsepy.lapse import Lapse

if __name__ == '__main__':
lapse = Lapse(os.getenv("REFRESH_TOKEN"))

current_user = lapse.get_current_user()

print(current_user)
2 changes: 1 addition & 1 deletion lapsepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Date: 10/22/23
"""

__version__ = '1.0.0'
__version__ = '1.0.1'

from .journal import Journal
from .auth.refresher import refresh
Expand Down
29 changes: 29 additions & 0 deletions lapsepy/journal/factory/profile_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,32 @@ def _render_variables(self):
},
"visibility": self.visibility
}


class CurrentUserGQL(BaseGQL):
def __init__(self):
super().__init__("CurrentUserGraphQLQuery",
"query CurrentUserGraphQLQuery { user { __typename ...UserDetails } }\nfragment UserDetails "
"on User { __typename profile { __typename ...ViewProfileSummaryFragment selectsVideo { "
"__typename media { __typename imageFilename } } } profileSettings { __typename displayName "
"{ __typename displayName lastUpdatedAt { __typename isoString } } username { __typename "
"username lastUpdatedAt { __typename isoString } } emojis { __typename emojis lastUpdatedAt "
"{ __typename isoString } } bio { __typename bio lastUpdatedAt { __typename isoString } } "
"dob { __typename dob { __typename date } visibility lastUpdatedAt { __typename isoString } "
"} } inviteTags { __typename message profileImageUrls mediaPreviewUrls taggedMediaCount } "
"onboardingState { __typename hasCompletedAddFriends hasCompletedInviteFriends "
"hasCompletedLockscreenWidget } invites { __typename requiresInvite "
"additionalInvitesRequested { __typename isoString } inviteCodes { __typename code createdAt "
"{ __typename isoString } sentTo { __typename sent hashedPhoneNumber sentVia } } usedCodes { "
"__typename code usedBy { __typename ...CoreProfileFragment } usedAt { __typename isoString "
"} } inviteCopy { __typename codes score } } }\nfragment ViewProfileSummaryFragment on "
"Profile { __typename ...CoreProfileFragment ...ViewProfileSelectsFragment "
"...ViewProfileMusicFragment bio emojis { __typename emojis } kudos { __typename emoji "
"totalCount lastSentAt { __typename isoString } } tags { __typename type text } }\nfragment "
"CoreProfileFragment on Profile { __typename id displayName profilePhotoName username "
"friendStatus isBlocked blockedMe hashedPhoneNumber joinedAt { __typename isoString } "
"}\nfragment ViewProfileSelectsFragment on Profile { __typename selectsVideo { __typename "
"...CoreRecapVideoFragment } }\nfragment CoreRecapVideoFragment on RecapVideo { __typename "
"id videoFilename totalDuration interval }\nfragment ViewProfileMusicFragment on Profile { "
"__typename music { __typename ...ProfileMusicDetails } }\nfragment ProfileMusicDetails on "
"ProfileMusic { __typename artist artworkUrl duration songTitle songUrl }")
15 changes: 14 additions & 1 deletion lapsepy/journal/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
DarkroomGQL

from lapsepy.journal.factory.profile_factory import SaveBioGQL, SaveDisplayNameGQL, SaveUsernameGQL, SaveEmojisGQL, \
SaveDOBGQL
SaveDOBGQL, CurrentUserGQL

from .structures import Snap, Profile, ProfileMusic, FriendsFeed, FriendNode, DarkRoomMedia, ReviewMediaPartition

Expand Down Expand Up @@ -316,6 +316,18 @@ def get_friends_feed(self, count: int = 10) -> FriendsFeed:

return FriendsFeed(friend_nodes)

def get_current_user(self) -> Profile:
"""
Gets the current user information
:return: dict of current user information
"""
query = CurrentUserGQL().to_dict()
response = self._sync_journal_call(query)
pd = response.get("data", {}).get("user", {}).get("profile", {})
profile = Profile.from_dict(pd)

return profile

def get_profile_by_id(self, user_id: str, album_limit: int = 6, friends_limit: int = 10) -> Profile:
"""
Get a Profile object
Expand Down Expand Up @@ -359,6 +371,7 @@ def generate_profile_object(profile_data: dict) -> Profile:
tags=profile_data.get("tags"),
user_id=profile_data.get('id'),
username=profile_data.get('username'),
hashed_phone_number=pd.get("hashedPhoneNumber"),
profile_music=profile_music
)

Expand Down
5 changes: 4 additions & 1 deletion lapsepy/journal/structures/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def _dt_from_iso(dt_str: str):
class Profile:
def __init__(self, user_id: str, username: str, display_name: str, profile_photo_name: str, bio: str | None,
emojis: list[str], is_friends: bool, blocked_me: bool, kudos: int, tags: list[dict],
is_blocked: bool = False, friends: list["Profile"] = None, profile_music: "ProfileMusic" = None):
hashed_phone_number: str, is_blocked: bool = False, friends: list["Profile"] = None,
profile_music: "ProfileMusic" = None):
if friends is None:
friends = []

Expand All @@ -35,6 +36,7 @@ def __init__(self, user_id: str, username: str, display_name: str, profile_photo
self.kudos = kudos
self.profile_photo_name: str = profile_photo_name
self.tags = tags
self.hashed_phone_number = hashed_phone_number
self.user_id: str = user_id
self.username: str = username
self.media: list[Snap] = []
Expand Down Expand Up @@ -79,6 +81,7 @@ def from_dict(profile_data: dict) -> "Profile":
tags=pd.get("tags"),
user_id=pd.get('id'),
username=pd.get('username'),
hashed_phone_number=pd.get("hashedPhoneNumber"),
profile_music=profile_music
)

Expand Down
7 changes: 7 additions & 0 deletions lapsepy/lapse/lapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ def get_profile_by_id(self, user_id: str, album_limit: int = 6, friends_limit: i
"""
return self.journal.get_profile_by_id(user_id=user_id, album_limit=album_limit, friends_limit=friends_limit)

def get_current_user(self) -> Profile:
"""
Gets the current user information
:return: dict of current user information
"""
return self.journal.get_current_user()

def update_bio(self, bio: str):
"""
Updates your Lapse bio
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = "1.0.0"
VERSION = "1.0.1"
DESCRIPTION = "A Python API wrapper for the social media app Lapse."

with open("README.md", 'r') as f:
Expand Down
Binary file added tests/assets/example_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions tests/tests_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os
import time
import uuid

from lapsepy import Lapse

from unittest import TestCase

lapse = Lapse(os.getenv("LAPSE-TEST-REFRESH"))

test_lapse_profile = lapse.get_current_user()


thought_id = None


class TestFeeds(TestCase):
def test_create_thought_generic(self):
global thought_id

if thought_id is None:
thought_id = f"STATUS_UPDATE:{uuid.uuid4()}"
lapse.create_status_update("This is my generic test for thoughts.", msg_id=thought_id)

def test_create_thought_long(self):
lapse.create_status_update("This is a test for long thoughts, thoughts on Lapse are not supposed to be able to "
"to pass 90 characters, however through sending them directly from the API this can"
"be avoided as of 11/8/2023, not that you care, I just needed something to write for"
"this test...")

def test_delete_thought(self):
msg_id = f"STATUS_UPDATE:{uuid.uuid4()}"
lapse.create_status_update("This is a thought that will be deleted.", msg_id=msg_id)
time.sleep(5) # Let the status update reach Lapse servers.
lapse.remove_status_update(msg_id=msg_id)

def test_react_thought_generic(self):
global thought_id

if thought_id is None:
thought_id = f"STATUS_UPDATE:{uuid.uuid4()}"
lapse.create_status_update("This is my generic test for thoughts.", msg_id=thought_id)

lapse.add_reaction(thought_id, "😀")

def test_react_thought_multiple(self):
global thought_id

if thought_id is None:
thought_id = f"STATUS_UPDATE:{uuid.uuid4()}"
lapse.create_status_update("This is my generic test for thoughts.", msg_id=thought_id)

for _ in range(5):
lapse.add_reaction(thought_id, "😄")

def test_react_thought_text(self):
global thought_id

if thought_id is None:
thought_id = f"STATUS_UPDATE:{uuid.uuid4()}"
lapse.create_status_update("This is my generic test for thoughts.", msg_id=thought_id)

lapse.add_reaction(thought_id, "does this work?")

def test_remove_reaction(self):
global thought_id

if thought_id is None:
thought_id = f"STATUS_UPDATE:{uuid.uuid4()}"
lapse.create_status_update("This is my generic test for thoughts.", msg_id=thought_id)

lapse.add_reaction(thought_id, "😆")
time.sleep(2.5) # Give reaction time for Lapse server to receive reaction
lapse.remove_reaction(thought_id, "😆")
24 changes: 24 additions & 0 deletions tests/tests_fetching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

from lapsepy import Lapse

from unittest import TestCase

lapse = Lapse(os.getenv("LAPSE-TEST-REFRESH"))

test_lapse_profile = lapse.get_current_user()


class TestFetching(TestCase):
def test_current_user(self):
lapse.get_current_user()

def test_get_profile_by_id(self):
user_id = test_lapse_profile.user_id

user_profile = lapse.get_profile_by_id(user_id=user_id)

assert user_profile.username == test_lapse_profile.username

def test_fetch_profile_image(self):
test_lapse_profile.load_profile_picture(quality=100, height=200)
53 changes: 53 additions & 0 deletions tests/tests_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os

from lapsepy import Lapse

from unittest import TestCase

lapse = Lapse(os.getenv("LAPSE-TEST-REFRESH"))


class TestDOB(TestCase):
def test_modify_dob_year_greater_than_current(self):
lapse.update_dob("9999-01-01")

def test_modify_dob_younger_than_thirteen(self):
lapse.update_dob("2023-01-01")

def test_modify_dob_generic(self):
lapse.update_dob("2005-05-05")


class TestUsername(TestCase):
def test_modify_username_generic(self):
lapse.update_username("quintinbot")


class TestBio(TestCase):
def test_bio_generic(self):
lapse.update_bio("Hello, this bio is an automated test using Lapsepy (https://github.com/quintindunn/lapsepy)")


class TestDisplayName(TestCase):
def test_display_name_generic(self):
lapse.update_display_name("Automated DisplayName")

def test_display_name_long(self):
lapse.update_display_name(
"Hello, this bio is another step in of the automated test for my project Lapsepy, more "
"information on this project can be found on my Github profile, at "
"https://github.com/quintindunn/lapsepy, if you have any questions feel free to reach out "
"to me")


class TestEmojis(TestCase):
def test_emojis_generic(self):
lapse.update_emojis(["😀", "😃", "😄", "😁", "😆"])

def test_emojis_n_amount(self):
content = "😀😃😄😁😆"
for i in range(1, 6):
lapse.update_emojis(list(content[:i]))

def test_emojis_text(self):
lapse.update_emojis(["This is a test", "This is also part of the test", "This too", "And this", "Me too!"])
55 changes: 55 additions & 0 deletions tests/tests_uploading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import time
import uuid

from PIL import Image

from lapsepy import Lapse

from unittest import TestCase

lapse = Lapse(os.getenv("LAPSE-TEST-REFRESH"))

test_lapse_profile = lapse.get_current_user()

example_im = Image.open("./assets/example_1.jpg")


im_uuid = None


class TestUploading(TestCase):
def test_upload(self):
global im_uuid

if im_uuid is None:
im_uuid = "01HDBZ" + str(uuid.uuid4()).upper().replace("-", "")[:20]
lapse.upload_photo(im=example_im, develop_in=15, file_uuid=im_uuid)

def test_darkroom_query(self):
global im_uuid

if im_uuid is None:
im_uuid = "01HDBZ" + str(uuid.uuid4()).upper().replace("-", "")[:20]
lapse.upload_photo(im=example_im, develop_in=15, file_uuid=im_uuid)
time.sleep(2.5) # Wait for lapse servers to process image.

lapse.query_darkroom()

def test_review(self):
def generate_drm():
drm_id = "01HDBZ" + str(uuid.uuid4()).upper().replace("-", "")[:20]
lapse.upload_photo(im=example_im, develop_in=15, file_uuid=drm_id)
time.sleep(2.5) # Wait for lapse servers to process image.
return drm_id

[generate_drm() for _ in range(3)]

drm = list(lapse.query_darkroom())

drm[0].archive(lapse)
drm[1].delete(lapse)
drm[2].share(lapse)

def test_upload_instant(self):
test_lapse_profile.send_instant(ctx=lapse, im=example_im, caption="Automated test")

0 comments on commit a5d285d

Please sign in to comment.