For now, you have to manually download the bereal/
folder and add it to your project to use the API.
git clone https://github.com/othema/bereal-python.git
)bereal/
folder to your projectAll functions of the API are rooted in the BeReal()
class. To start, instantiate it somewhere in your code.
from bereal import BeReal
bereal = BeReal()
To use any functions of the API you must login first. There are two ways of doing this.
You would use this method if you haven't already logged in.
from bereal import BeReal
bereal = BeReal()
bereal.login.send_code("<your phone number>")
bereal.login.verify_code(input("Enter verification code: "))
You would use this method if you have already logged in the user and you don't want to send another verification code.
from bereal import BeReal
bereal = BeReal()
bereal.login.with_tokens(
"<your token>",
"<your refresh token>"
)
Your token and refresh token can be accessed through the client after a successful login like this:
from bereal import BeReal
bereal = BeReal()
bereal.token
bereal.refresh_token
To make a post, you must pass in two file paths to images with one being the front camera image, and one being the back camera image.
from bereal import BeReal
bereal = BeReal()
# [Login]
new_post = bereal.post_bereal("[front_image].jpg", "[back_image].jpg") # Returns a Post() object
new_post.post_id
Your profile data can be accessed using the me()
method. Here is an example how:
from bereal import BeReal
bereal = BeReal()
# [Login]
me = bereal.me()
me.user_id
me.username
me.profile_picture # URL to your profile picture
me.full_name
me.phone_number
me.birthday # A datetime object
me.realmojis # Array of Realmoji() objects saved to your account
As you may know, there are two feeds in BeReal. The friend feed and the discovery feed.
from bereal import BeReal
bereal = BeReal()
# [Login]
friend_feed = bereal.feed.friends()
discovery_feed = bereal.feed.discovery()
Each function returns a list of Post()
objects.
After a while, a login token can expire. To overcome this, you can call the refresh()
method to generate a new login and refresh token without having to send another verification code.
from bereal import BeReal
bereal = BeReal()
# [Login]
bereal.refresh()
bereal.token
bereal.refresh_token
You should save these tokens in a file if you want to allow the user to stay logged in throughout multiple uses of the program.
Post()
objectsPost objects can be returned from a feed retrieval and they contain data about a post.
post = friend_feed[0]
# Methods
post.add_comment("<body>") # Adds a comment to the post from the logged in user
# Attributes
post.post_id
post.back_camera
post.front_camera
post.caption # The caption associated with the post
post.user # A User() object of the user who posted
post.creation_time # A datetime object
post.realmojis # An array of Realemoji() objects
post.is_public # If the post is viewable on the discovery feed
post.retakes # Amount of retakes
post.comments # An array of Comment() objects
Comment()
objectsTODO: Add deletion of comments through a delete()
method
comment = post.comments[0]
# Attributes
comment.comment_id
comment.user # The author of the comment
comment.creation_time # A datetime object
comment.body # The comment text
Realmoji()
objectsRealmojis are reactions to a BeReal. A realmoji is an image of a user posing as one of 5 emojis:
You can have saved realmojis on your account.
from bereal import BeReal
bereal = BeReal()
# [Login]
saved_realmoji = bereal.me().realmojis[0]
saved_realmoji.url # URL of the realmoji image
saved_realmoji.emoji # š, š, š², š or š
realmoji = post.realmojis[0]
realmoji.emoji # š, š, š², š or š
realmoji.url # URL of the realmoji image
realmoji.user # User who reacted with that realmoji
realmoji.time # Datetime the post was reacted with the realmoji