Automation library for interacting with Imgflip using Selenium and Requests
Project description
imgbyte
Python module for interaction and actions with the imgflip website using a combination of selenium and requests.
Documentation
Setup
createWindow()
Creates a new window and bot instance.
Usage:driver = createWindow()
The driver object will then be used for all future imgbyte functions.
img_url(driver, page_path)
Sets the driver window to the input url. Useful if you want to do some custom things with the page html on a specific page.
Many of the functions in this module require it, so be aware that use of them will change the window location.
imgbyte functions that require this will be notated with a*
Usage:img_url(driver, 'user/Imgflip')
login(driver, username/email, password)
Logs into the specified account.
Makes use of the get_token function to add the session token to the driver, asdriver.token.
Most functions require being logged into a user account. Ones that do will be notated with a~.
Usage:login(driver, username, password)
get_token(driver)
Returns the current session token as a string. Requires being logged in. Optionally, use
driver.tokeninstead.
Comments
comment_vote(dtiver, vote_type, comment_id) ~
Add or Remove and upvote or downvote from a comment.
vote_type must be 1 to upvote, 0 to downvote, and -1 to remove your current vote.
Usage:comment_vote(driver, 1, 1234)Upvotes the comment with id of 1234
get_comments(driver, post_id) *
Returns a list of comment objects on the post with the given post id.
Comment objects have the attributesidentifier, user, content, postid, user_perm, image
identifier: the comment id
user: username of the user who made the comment
content: the text of the comment
postid: the id of the post the comment is on
user_perm: the permission level of the user. includesglobal-mod, site-mod, stream-mod, normal-user
image: if the comment contains an image, this will be a base64 encoded string of said image
comment_post(driver, post_id, text) ~
Comments on the image with the given post id, with the text as the comment content.
Returns the response code from the server as a string.
Usage:comment_post(driver, '9geor3', 'This is a comment')
comment_reply(driver, post_id, comment_id, text) ~ *
Comments a reply to another comment with the given text.
Identical usage tocomment_post()except it additionally requires the id of the comment to reply to.
The comment id is typicall obtained withget_comments().
del_own_comment(driver, comment_id) ~
Deletes your comment with the given comment id. Unlike the
del_comment()function, it does not require you to be a moderator in the stream the comment is in.
get_basic_comments(driver, post_id) *
Works similarly to the
get_comments()function, but instead of returning objects with attributes, it returns the comments as a list of html objects.
Posts
post_vote(driver, vote_type, post_id) ~
Upvote, downvote, or remove your vote from a post.
vote_type can be 1 for upvote, 0 for downvote, and -1 to remove your current vote.
get_post(driver, post_id) *
Returns the post with the given id as an object. Post objects have the following attributes:
identifier: the post id
author: the creator of the post
title: the post's title
desc: the post's description
tags: the post's tags (list of strings)
stream: the stream the post is currently submitted in
image: base64 encoded string of the post's image
If a given attribute does not exist (e.g. there are no tags) it will return with a string labeled ⊙No.(thing), for example:
⊙No.TagsIf the post owner is unknown, the owner attribute will be⊙anonymous
get_basic_posts(driver, stream, sort) *
Returns all posts on the first page of the given stream as a list of html objects.
Sort can either behotornew. Leave blank for the stream default.
flag_image(driver, post_id, flag_type, text) ~
Flags the image with the given post id.
Text is the note that will be given with the flag.
Valid options for flag_type are:
img-flag-wrong-stream: Violates stream rules that aren't disallowed by site TOS
img-nsfw: NSFW content in image
img-spam: Post contains excessive copypasta spam or advertising
img-abuse: Post violates any other part of the imgflip TOS
create_post(driver, template, stream, title, nsfw, text) ~ *
Create a new post automatically using the imgflip meme generator, and submit it to a specific stream THAT YOU FOLLOW.
the template field is the numerical id of the template you want to use. For your own templates, you can find this by going to your profile, My Templates, and select "view template" on the one you wish to view.
the NSFW field is eitherTrueorFalse.
For text insertion into the template, imgbyte supports 1 text box being filled. Templates you select must have at least 1 text box, and a maxmimum of one text box may be used, which is always the first one listed on the meme generator page.
Usage:create_post(driver, 1, 'fun', 'This is a title', False, 'This is a text box')
Notifications
get_notif_count(driver) ~
Returns an integer with the number of notifcations you currently have.
get_notifications(driver) ~ *
WARNING: Use of this function will clear your notifications when used.
Note that the way the function is currently set up only works for comment notifications. Any other kind of notification will return with broken strings for the attributes. It is for this reason I recommend changing your account settings to only include comment notifications.
Returns a list of notification objects, with the following attributes:
post_id: The id of the post on which the notification occured
com_id: The id of the comment that gave the notification
Memechat
has_chats(driver) ~
Returns either
TrueorFalsewith whether or not there are currently new unread memechats.
get_unread_memechats(driver) ~ *
Returns a list of unread memechats as objects with the following attributes:
user: The username of the user who messaged you
time_waiting: How long ago the user sent the message
text: The message sent in the memechat. If the message is long enough, it won't display the whole thing.
get_all_memechats(driver) ~ *
Unlike the unread version this one displays whether a memechat is read or unread, but it does NOT get the actual message that was sent. The object attributes are as follows:
user: The username of the user who messaged you
time_waiting: How long ago the user sent the message
status: eitherreadorunread. All messages are ordered by most recent.
post_memechat(driver, user, text) ~ *
Sends a memechat message to the given user. The user must be following you for it to work.
Usage:post_memechat(driver, 'Imgflip', 'This is a memechat message')
Moderation
Note: All of these require you to be logged in and be a moderator in the stream you're using them in.
ban_user(driver, user, stream, duration, banType) ~ *
Bans the user for preset hour durations.
banType must be eithercommentorpost
The
durationparameter can be any of the following number of hours: 2, 8, 24, 48, -1 (indefinite)
Usage:ban_user(driver, 'Imgflip', 'fun', 8, post)Post bans the user Imgflip from fun stream for 8 hours
alter_post(driver, post_id, title, tags, nsfw, anonymous) ~
Edits the post with the given post id
title,tags,nsfw, andanonymousare optional
NOTE: It will set all settings to the given field, so leaving the title field blank for example will set the post's current title to an empty string.
nsfwandanonymousmust be either 1 or 0.anonymouswill set the owner of the post to hidden.
Returns the response code from the server
mark_nsfw(driver, post_id) ~ *
Toggles nsfw on the given post. I don't know why you would ever need this, but it's cool that it's here, I guess. It was originally supposed to only set the post TO nsfw, but it doesn't and I'm too lazy to change it.
feature(driver, post_id, action, reason, note) ~ *
Feature or Unfeature a post. Works on flagged images as well.
actioncan be either 'approve' or 'disapprove'
reasoncan be any of the following:
other(default if none specified)
repost
political
spam
harassment
abuse(of TOS)
wrong_stream(stream-specific rules)
wrong_language(if the stream has language reqs
get_comment_flags(driver, stream) ~ *
Gets all flagged comments from the selected stream. Don't use the stream parameter for all streams you moderate.
Returns a list of comment objects with the following attributes:
com_id: the comment's id
post_id: the id of the post the comment is on
content: the content of the comment
flagging_user: the name of the user who flagged the comment
flagged_user: the username of the comment owner
stream: the stream the comment is in
link: the full url link to the comment that was flagged
get_approval_queue(driver, stream) ~ *
Returns a list of post objects from the approval queue of the given stream. Objects have the following attributes:
identifier: the post id of the post to approve
owner: the username of the post's owner
title: the title of the post
tags: the tags on the post
Misc
get_uid(driver, username)
Returns the user id number of the user with the given username. This is required by a few of the functions, and is useful as although users can change their name, their uid never changes.
follow(driver, uid, follow_type) ~
follows the user with the given uid, obtained with
get_uid()
follow type must be 1 for following, and 0 for unfollowing
Imgflip's post ids are actually integers that are encoded in base 36. The two below functions allow conversion between the two, and are used in many functions that require the use of post ids.
base36_encode(num)
After inputting an integer, returns the corresponding imgflip post id.
base36_decode(string)
After inputting an imgflip id, returns the corresponding integer number.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file imgbyte-0.1.0.tar.gz.
File metadata
- Download URL: imgbyte-0.1.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4245a8f40497a12231a32ddbd4ba43032ef20daeb1a70bc8534787fd701b745c
|
|
| MD5 |
021a82f17e339138778dc5ccf8a6ea39
|
|
| BLAKE2b-256 |
08cce3d33e8ba226eac5e2188b3a181aab588878423d2bdff0075d9d81d9b855
|
File details
Details for the file imgbyte-0.1.0-py3-none-any.whl.
File metadata
- Download URL: imgbyte-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38eee29aaf00838c7620b69495f914870d740876d0d68469803f5685719cbefd
|
|
| MD5 |
c3386239e74276234b55e853e4b065bf
|
|
| BLAKE2b-256 |
f0a6ca4ac1747bfa096139ce8c00228e56390e8163464cc05b18a45c0001f985
|