Package ByteAPI
Expand source code
__all__ = ["PublicProfile", "PublicPost", "ByteAPI", "Community", "DraftPost", "Conversation"]
from ByteAPI.ByteAPIClient import ByteAPI
from ByteAPI.PublicProfile import PublicProfile
from ByteAPI.Post import PublicPost, DraftPost
from ByteAPI.Conversation import Conversation
Sub-modules
ByteAPI.ByteAPIClient
ByteAPI.Comment
ByteAPI.Community
ByteAPI.Post
Classes
class ByteAPI (token)
-
Create a new ByteAPI Client instance from
token
Expand source code
class ByteAPI: def __init__(self, token): """Create a new ByteAPI Client instance from `token`""" self.__token = token self.__rsess = requests.Session() self.user_info = self.__accountInfo() self.username = self.user_info["username"] """Username of the Authenticated user""" self.user_id = self.user_info["id"] """UserID of the Authenticated user""" self.following = self.__accountFollowing() self.following_count = self.user_info["followingCount"] self.follower = self.__accountFollowing() self.follower_count = self.user_info["followerCount"] self.loop_count = self.user_info["loopCount"] self.consumed_loops_count = self.user_info["loopsConsumedCount"] self.profile_backgroundColor = self.user_info["backgroundColor"] self.profile_foregroundColor = self.user_info["foregroundColor"] self.conversations = self.__conversations() def __conversations(self): ret = [] res = self.__rsess.post("https://api.byte.co/dm-get-conversations", headers={ "Authorization": self.__token }, json={}).json() for conversation in res["data"]["conversations"]: ret.append(Conversation(self.__rsess, self.__token, conversation["id"], conversation["messages"], conversation["members"])) return ret def __accountInfo(self): res = self.__rsess.get("https://api.byte.co/account/me", headers={"Authorization": self.__token}) handleResponseError(self, res) return res.json()["data"] def __accountFollowing(self): res = self.__rsess.get("https://api.byte.co/account/me/following", headers={"Authorization": self.__token}) handleResponseError(self, res) return res.json()["data"] def __accountFollowers(self): res = self.__rsess.get("https://api.byte.co/account/me/followers", headers={"Authorization": self.__token}) handleResponseError(self, res) return res.json()["data"] def findAccount(self, account_id: str) -> PublicProfile: """Get a `PublicProfile` object by account_id""" profile = PublicProfile(self.__rsess, self.__token, account_id) return profile def findPost(self, post_id: str) -> PublicPost: """Get a `PublicPost` object by post_id""" post = PublicPost(self.__rsess, post_id, self.__token) return post def changeUsername(self, username: str): """Change your own username""" res = self.__rsess.put("https://api.byte.co/account/me", headers={ "Authorization": self.__token }, json={ "username": str(username) }) return handleResponseError(self, res) def changeDisplayname(self, display_name: str): """Change your own displayname""" res = self.__rsess.put("https://api.byte.co/account/me", headers={ "Authorization": self.__token }, json={ "displayName": str(display_name) }) return handleResponseError(self, res) def changeColorScheme(self, color_scheme: int): """ Change your profiles color scheme. `color_scheme` has to be one of the existing color schemes which can be fetched with `colorSchemes(self)` """ if int(color_scheme) in range(0, len(self.colorSchemes()["colors"])): res = self.__rsess.put("https://api.byte.co/account/me", headers={ "Authorization": self.__token }, json={ "colorScheme": int(color_scheme) }) return handleResponseError(self, res) raise APIError("Unknown Color scheme ("+str(color_scheme)+")") def colorSchemes(self): """Get a list of available color schemes which can be used to set your user profiles color scheme.""" res = self.__rsess.get("https://api.byte.co/account/me/colors", headers={ "Authorization": self.__token }) handleResponseError(self, res) return res.json()["data"] def postComment(self, post_id, text: str): """Post a comment under a post by post_id with the contents of text""" res = self.__rsess.post(("https://api.byte.co/post/id/"+str(post_id)+"/feedback/comment"), headers={ "Authorization": self.__token }, json={ "postID": str(post_id), "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}", "body": str(text)}) handleResponseError(self, res) return res.json()["data"] def deleteComment(self, comment_id): """Delete a existing comment by comment_id""" res = self.__rsess.post(("https://api.byte.co/feedback/comment/id/" + str(comment_id)), headers={ "Authorization": self.__token }, json={ "commentID": str(comment_id) }) return handleResponseError(self, res) def likeComment(self, comment_id): """Like a comment by comment_id""" res = self.__rsess.put(("https://api.byte.co/feedback/comment/id/"+str(comment_id)+"/feedback/like"), headers={ "Authorization": self.__token }) return handleResponseError(self, res) def dislikeComment(self, comment_id): """Dislike a comment by comment_id""" res = self.__rsess.delete(("https://api.byte.co/feedback/comment/id/"+str(comment_id)+"/feedback/like"), headers={ "Authorization": self.__token }) return handleResponseError(self, res) def postCommentReply(self, comment_id, text: str): """Reply to a existing comment by comment_id""" res = self.__rsess.post(("https://api.byte.co/feedback/comment/id/"+str(comment_id)+"/feedback/comment"), headers={ "Authorization": self.__token }, json={ "postID": str(comment_id).split("-")[0], "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}", "body": str(text)}) handleResponseError(self, res) return res.json()["data"]
Instance variables
var user_id
-
UserID of the Authenticated user
var username
-
Username of the Authenticated user
Methods
def changeColorScheme(self, color_scheme: int)
-
Change your profiles color scheme.
color_scheme
has to be one of the existing color schemes which can be fetched withcolorSchemes(self)
Expand source code
def changeColorScheme(self, color_scheme: int): """ Change your profiles color scheme. `color_scheme` has to be one of the existing color schemes which can be fetched with `colorSchemes(self)` """ if int(color_scheme) in range(0, len(self.colorSchemes()["colors"])): res = self.__rsess.put("https://api.byte.co/account/me", headers={ "Authorization": self.__token }, json={ "colorScheme": int(color_scheme) }) return handleResponseError(self, res) raise APIError("Unknown Color scheme ("+str(color_scheme)+")")
def changeDisplayname(self, display_name: str)
-
Change your own displayname
Expand source code
def changeDisplayname(self, display_name: str): """Change your own displayname""" res = self.__rsess.put("https://api.byte.co/account/me", headers={ "Authorization": self.__token }, json={ "displayName": str(display_name) }) return handleResponseError(self, res)
def changeUsername(self, username: str)
-
Change your own username
Expand source code
def changeUsername(self, username: str): """Change your own username""" res = self.__rsess.put("https://api.byte.co/account/me", headers={ "Authorization": self.__token }, json={ "username": str(username) }) return handleResponseError(self, res)
def colorSchemes(self)
-
Get a list of available color schemes which can be used to set your user profiles color scheme.
Expand source code
def colorSchemes(self): """Get a list of available color schemes which can be used to set your user profiles color scheme.""" res = self.__rsess.get("https://api.byte.co/account/me/colors", headers={ "Authorization": self.__token }) handleResponseError(self, res) return res.json()["data"]
def deleteComment(self, comment_id)
-
Delete a existing comment by comment_id
Expand source code
def deleteComment(self, comment_id): """Delete a existing comment by comment_id""" res = self.__rsess.post(("https://api.byte.co/feedback/comment/id/" + str(comment_id)), headers={ "Authorization": self.__token }, json={ "commentID": str(comment_id) }) return handleResponseError(self, res)
def dislikeComment(self, comment_id)
-
Dislike a comment by comment_id
Expand source code
def dislikeComment(self, comment_id): """Dislike a comment by comment_id""" res = self.__rsess.delete(("https://api.byte.co/feedback/comment/id/"+str(comment_id)+"/feedback/like"), headers={ "Authorization": self.__token }) return handleResponseError(self, res)
def findAccount(self, account_id: str) ‑> ByteAPI.PublicProfile.PublicProfile
-
Get a
PublicProfile
object by account_idExpand source code
def findAccount(self, account_id: str) -> PublicProfile: """Get a `PublicProfile` object by account_id""" profile = PublicProfile(self.__rsess, self.__token, account_id) return profile
def findPost(self, post_id: str) ‑> PublicPost
-
Get a
PublicPost
object by post_idExpand source code
def findPost(self, post_id: str) -> PublicPost: """Get a `PublicPost` object by post_id""" post = PublicPost(self.__rsess, post_id, self.__token) return post
def likeComment(self, comment_id)
-
Like a comment by comment_id
Expand source code
def likeComment(self, comment_id): """Like a comment by comment_id""" res = self.__rsess.put(("https://api.byte.co/feedback/comment/id/"+str(comment_id)+"/feedback/like"), headers={ "Authorization": self.__token }) return handleResponseError(self, res)
def postComment(self, post_id, text: str)
-
Post a comment under a post by post_id with the contents of text
Expand source code
def postComment(self, post_id, text: str): """Post a comment under a post by post_id with the contents of text""" res = self.__rsess.post(("https://api.byte.co/post/id/"+str(post_id)+"/feedback/comment"), headers={ "Authorization": self.__token }, json={ "postID": str(post_id), "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}", "body": str(text)}) handleResponseError(self, res) return res.json()["data"]
def postCommentReply(self, comment_id, text: str)
-
Reply to a existing comment by comment_id
Expand source code
def postCommentReply(self, comment_id, text: str): """Reply to a existing comment by comment_id""" res = self.__rsess.post(("https://api.byte.co/feedback/comment/id/"+str(comment_id)+"/feedback/comment"), headers={ "Authorization": self.__token }, json={ "postID": str(comment_id).split("-")[0], "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}", "body": str(text)}) handleResponseError(self, res) return res.json()["data"]
class Conversation (session: requests.sessions.Session, token: str, conversation_id: str, messages: list, members: list)
-
This represents a direct-message conversation between two users
Expand source code
class Conversation: def __init__(self, session: requests.Session, token: str, conversation_id: str, messages: list, members: list): """This represents a direct-message conversation between two users""" self.__token = token self.__rsess = session self.id = conversation_id self.messages = [] for message in messages: self.messages.append(Message(self.__rsess, self.__token, message["id"], message["conversationID"], message["authorID"], message["body"])) self.members = [] for member in members: self.members.append(PublicProfile(self.__rsess, self.__token, member))
class DraftPost (session: requests.sessions.Session, thumbnail_upload_id: str, video_upload_id: str, allow_remix: bool, caption: str, duration: float, token: str)
-
Used to create/publish posts within the API
Expand source code
class DraftPost: def __init__(self, session: requests.Session, thumbnail_upload_id: str, video_upload_id: str, allow_remix: bool, caption: str, duration: float, token: str): """Used to create/publish posts within the API""" try: self.__rsess = session self.__token = token self.thumbnail_upload_id = thumbnail_upload_id self.video_upload_id = video_upload_id self.allow_remix = allow_remix self.caption = caption self.duration = duration except Exception as err: raise Exception("Unable to create draft ("+str(err)+")") def publish(self): """Publishes the data saved in the Used DraftPost instance and returns `PublicPost` for the published Post""" res = self.__rsess.post("https://api.byte.co/post", headers={ "Authorization": self.__token }, json={ "thumbUploadID": self.thumbnail_upload_id, "allowRemix": self.allow_remix, "soundTitle": None, "videoUploadID": self.video_upload_id, "composition": { "text": [], "footageTypes": [], "imageCount": 0, "clips": [ { "isFromCameraRoll": False, "duration":self.duration, "isFrontFacingCamera": False }, { "isFromCameraRoll": False, "duration": self.duration, "isFrontFacingCamera": False } ] }, "caption": self.caption, "soundArtworkUploadID":None, "soundParentID":None }).json() if res["success"] == 1: return PublicPost(self.__rsess, res["data"]["id"], self.__token)
Methods
def publish(self)
-
Publishes the data saved in the Used DraftPost instance and returns
PublicPost
for the published PostExpand source code
def publish(self): """Publishes the data saved in the Used DraftPost instance and returns `PublicPost` for the published Post""" res = self.__rsess.post("https://api.byte.co/post", headers={ "Authorization": self.__token }, json={ "thumbUploadID": self.thumbnail_upload_id, "allowRemix": self.allow_remix, "soundTitle": None, "videoUploadID": self.video_upload_id, "composition": { "text": [], "footageTypes": [], "imageCount": 0, "clips": [ { "isFromCameraRoll": False, "duration":self.duration, "isFrontFacingCamera": False }, { "isFromCameraRoll": False, "duration": self.duration, "isFrontFacingCamera": False } ] }, "caption": self.caption, "soundArtworkUploadID":None, "soundParentID":None }).json() if res["success"] == 1: return PublicPost(self.__rsess, res["data"]["id"], self.__token)
class PublicPost (session: requests.sessions.Session, post_id: str, token: str)
-
Returned when fetching posts
Expand source code
class PublicPost: def __init__(self, session: requests.Session, post_id: str, token: str): """Returned when fetching posts""" try: self.__rsess = session self.__token = token self.post_data = self.__rsess.get("https://api.byte.co/post/id/" + str(post_id), headers={ "Authorization": self.__token }).json()["data"] self.id = post_id self.type = int(self.post_data["type"]) self.caption = str(self.post_data["caption"]) self.author = PublicProfile(self.__rsess, self.__token, self.post_data["authorID"]) self.curation_allowed = bool(self.post_data["allowCuration"]) self.remix_allowed = bool(self.post_data["allowRemix"]) self.date = int(self.post_data["date"]) self.video_source = str(self.post_data["videoSrc"]) self.thumbnail_source = str(self.post_data["thumbSrc"]) self.comment_count = int(self.post_data["commentCount"]) self.like_count = int(self.post_data["likeCount"]) self.liked_by_me = bool(self.post_data["likedByMe"]) self.loop_count = int(self.post_data["loopCount"]) self.rebyted_by_me = bool(self.post_data["rebytedByMe"]) self.rebyte_count = int(self.post_data["rebyteCount"]) self.share_url = str(self.post_data["shareURL"]) if "animatedThumbnail" in self.post_data: self.animated_thumbnail_source = str(self.post_data["animatedThumbnail"]) if "watermarkedVideo" in self.post_data: self.watermarked_video_source = str(self.post_data["watermarkedVideo"]) self.media = PostMedia(self.__rsess, self.id, self.__token) if "category" in self.post_data: self.category = str(self.post_data["category"]) self.community = Community(self.__rsess, self.post_data["community"]["id"], self.__token) except Exception as err: raise Exception("Unable to find post (ID: "+str(post_id)+")") def like(self): """Like the post""" res = self.__rsess.put(("https://api.byte.co/post/id/"+str(self.id)+"/feedback/like"), headers={ "Authorization": self.__token }, json={ "_context": { "isZenMode": False }, "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}", "postID": str(self.id) }).json() if "success" in res: if res["success"] == 1: self.__init__(self.__rsess, self.id, self.__token) def dislike(self): """Dislike the post""" res = self.__rsess.delete(("https://api.byte.co/post/id/"+str(self.id)+"/feedback/like"), headers={ "Authorization": self.__token }, json={ "_context": { "isZenMode": False }, "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}", "postID": str(self.id) }).json() if "success" in res: if res["success"] == 1: self.__init__(self.__rsess, self.id, self.__token) def similar(self): """Find similar posts""" res = self.__rsess.post("https://api.byte.co/post/id/"+str(self.id)+"/similar", headers={ "Authorization": self.__token }, json={ "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}" }) print(res.json()["data"]) def rebyte(self): """Rebyte the post""" res = self.__rsess.post("https://api.byte.co/rebyte", headers={ "Authorization": self.__token }, json={ "postID": str(self.id), "metadata": "{\"source\":\"feed:your_mix::collection:popularThisMonth\"}" }).json() if res["success"] == 0: if res["error"]["code"] == 2002: self.__init__(self.__rsess, self.id, self.__token) return True def unrebyte(self): """Un-rebyte the post""" res = self.__rsess.delete(("https://api.byte.co/post/id/"+str(self.id)+"/rebyte"), headers={ "Authorization": self.__token }).json() if res["success"] == 1: self.__init__(self.__rsess, self.id, self.__token) return True
Methods
def dislike(self)
-
Dislike the post
Expand source code
def dislike(self): """Dislike the post""" res = self.__rsess.delete(("https://api.byte.co/post/id/"+str(self.id)+"/feedback/like"), headers={ "Authorization": self.__token }, json={ "_context": { "isZenMode": False }, "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}", "postID": str(self.id) }).json() if "success" in res: if res["success"] == 1: self.__init__(self.__rsess, self.id, self.__token)
def like(self)
-
Like the post
Expand source code
def like(self): """Like the post""" res = self.__rsess.put(("https://api.byte.co/post/id/"+str(self.id)+"/feedback/like"), headers={ "Authorization": self.__token }, json={ "_context": { "isZenMode": False }, "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}", "postID": str(self.id) }).json() if "success" in res: if res["success"] == 1: self.__init__(self.__rsess, self.id, self.__token)
def rebyte(self)
-
Rebyte the post
Expand source code
def rebyte(self): """Rebyte the post""" res = self.__rsess.post("https://api.byte.co/rebyte", headers={ "Authorization": self.__token }, json={ "postID": str(self.id), "metadata": "{\"source\":\"feed:your_mix::collection:popularThisMonth\"}" }).json() if res["success"] == 0: if res["error"]["code"] == 2002: self.__init__(self.__rsess, self.id, self.__token) return True
def similar(self)
-
Find similar posts
Expand source code
def similar(self): """Find similar posts""" res = self.__rsess.post("https://api.byte.co/post/id/"+str(self.id)+"/similar", headers={ "Authorization": self.__token }, json={ "metadata": "{\"source\":\"feed:your_mix::collection:popularNow\"}" }) print(res.json()["data"])
def unrebyte(self)
-
Un-rebyte the post
Expand source code
def unrebyte(self): """Un-rebyte the post""" res = self.__rsess.delete(("https://api.byte.co/post/id/"+str(self.id)+"/rebyte"), headers={ "Authorization": self.__token }).json() if res["success"] == 1: self.__init__(self.__rsess, self.id, self.__token) return True
class PublicProfile (session: requests.sessions.Session, token: str, user_id: str)
-
Returned when fetching a public profile using
ByteAPI.account(<Account ID>)
Expand source code
class PublicProfile(): """Returned when fetching a public profile using `ByteAPI.account(<Account ID>)`""" def __init__(self, session: requests.Session, token: str, user_id: str): try: self.__rsess = session self.__token = token self.user_data = self.__rsess.get("https://api.byte.co/account/id/" + str(user_id), headers={ "Authorization": self.__token }).json()["data"] self.user_id = self.user_data["id"] self.username = self.user_data["username"] """Username of the target user""" self.display_name = self.user_data["displayName"] """Displayname of the target user""" if "avatarURL" in self.user_data: self.avatar_url = self.user_data["avatarURL"] """URL to the users avatar (if exists)""" if "bio" in self.user_data: self.bio = self.user_data["bio"] """Biography of the user (if exists)""" if "preferences" not in self.user_data: self.is_following = self.user_data["isFollowing"] self.is_followed = self.user_data["isFollowed"] self.is_blocked = self.user_data["isBlocked"] self.can_message = self.user_data["canMessage"] except: raise Exception("Unable to find user (ID: "+str(user_id)+")") def follow(self): """Follow the account""" res = self.__rsess.put("https://api.byte.co/account/id/"+str(self.user_id)+"/follow", headers={ "Authorization": self.__token }) print(res.json()) self.__init__(self.__rsess,self.user_id, self.__token) def unfollow(self): """Unfollow the account""" res = self.__rsess.delete("https://api.byte.co/account/id/"+str(self.user_id)+"/follow", headers={ "Authorization": self.__token }) self.__init__(self.__rsess,self.user_id, self.__token) def rebytes(self): """Get all rebytes of the account""" res = self.__rsess.get(("https://api.byte.co/account/id/"+str(self.user_id)+"/rebytes"), headers={ "Authorization": self.__token }).json() return res["data"] def posts(self): """Get all posts of the account""" res = self.__rsess.get(("https://api.byte.co/account/id/"+str(self.user_id)+"/posts"), headers={ "Authorization": self.__token }).json() return res["data"]
Methods
def follow(self)
-
Follow the account
Expand source code
def follow(self): """Follow the account""" res = self.__rsess.put("https://api.byte.co/account/id/"+str(self.user_id)+"/follow", headers={ "Authorization": self.__token }) print(res.json()) self.__init__(self.__rsess,self.user_id, self.__token)
def posts(self)
-
Get all posts of the account
Expand source code
def posts(self): """Get all posts of the account""" res = self.__rsess.get(("https://api.byte.co/account/id/"+str(self.user_id)+"/posts"), headers={ "Authorization": self.__token }).json() return res["data"]
def rebytes(self)
-
Get all rebytes of the account
Expand source code
def rebytes(self): """Get all rebytes of the account""" res = self.__rsess.get(("https://api.byte.co/account/id/"+str(self.user_id)+"/rebytes"), headers={ "Authorization": self.__token }).json() return res["data"]
def unfollow(self)
-
Unfollow the account
Expand source code
def unfollow(self): """Unfollow the account""" res = self.__rsess.delete("https://api.byte.co/account/id/"+str(self.user_id)+"/follow", headers={ "Authorization": self.__token }) self.__init__(self.__rsess,self.user_id, self.__token)