Coder Social home page Coder Social logo

mat-1 / repl-talk-api Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 6.0 216 KB

Allows you to do various things with the slightly unofficial Repl.it Repl Talk API

Home Page: https://pypi.org/project/repltalk/

License: MIT License

Python 100.00%
repl-talk replit

repl-talk-api's Introduction

Examples

# Getting the newest posts on Repl Talk and printing their titles
async for post in client.boards.all.get_posts():
	print(post.title)

API Reference

How to use the repltalk lib for Python. The functions are pretty self explanatory but I've added a short description for each of them.


The following functions are all coroutines unless specifically specified because asyncio is cool

Client

class repltalk.Client()

  • await login(username, password) Logs in to Repl.it with your username and password. Your bot must be verified in order to use this function.
  • await get_post(post_id) Gets the post with that id. returns Post
  • await get_comment(comment_id) Gets the comment with that id. returns Comment
  • await post_exists(post_id) Returns whether or not the post exists.
  • await get_leaderboard(limit=30) Gets the top users from the Repl Talk leaderboard. returns list of Users
  • await get_all_comments() Gets all the recent comments from Repl Talk. *returns list of Comments
  • await get_user(username) Gets the user with that username. returns User
  • await get_reports(resolved=False) Gets a list of reports. Only works for moderators or admins. See Report List
  • boards See Board.

Board

class client.boards


  • all The All board on Repl Talk.
  • share The Share board on Repl Talk.
  • ask The Ask board on Repl Talk.
  • announcements The Announcements board on Repl Talk.
  • challenge The Challenge board on Repl Talk.
  • learn The Learn board on Repl Talk.

  • async for post in get_posts(sort='top', search='') Gets the most recent posts from that board. Sort is the sorting order (top|hot|new) and search is the search query. returns AsyncPostList

RichBoard

A board that contains all the information from Board, and more. You can get this by doing await client.boards.get(board_name) (NOT YET ADDED)

  • name The name of the board.
  • title_cta Title call to action
  • body_cta Body call to action
  • button_cta Button call to action
  • repl_required Whether a Repl is required to be submitted.

Post

  • id The post ID.
  • title The post title.
  • content The post content.
  • board The board the post was made on.
  • votes The amount of upvotes the post has.
  • author The post author. Will be a User object.
  • timestamp The time the post was created at. (datetime.datetime object)
  • url The post url in Repl Talk.
  • repl The repl attached to the post.
  • language The Language that the Repl attached to the post uses.
  • show_hosted Indicates whether the post has a hosted repl linked to it.
  • is_announcement Whether the post is marked as an announcement.
  • pinned Whether the post has been pinned to the top of the board.
  • can_edit Indicates if the user can edit the post. This will be False unless you created the post.
  • can_comment If the user can comment on the post.
  • can_vote Indicates if the user can upvote the post.
  • has_voted Indicates if the user has already voted on the post.
  • is_locked Indicates if the post is locked.
  • can_answer Whether or not the user can answer the post.
  • answered If the post has been answered (will always be False if it's not a question).
  • comment_count The amount of comments the post has
  • await get_comments() Gets the comments on the post.
  • await post_comment(content) Posts a comment on the post.
  • await report(reason) Report the post
  • await delete() Delete the Post

Comment

  • id The comment ID.
  • content The comment body.
  • timestamp The time the comment was created at. (datetime.datetime object)
  • can_edit Indicates if the user can edit the comment.
  • can_comment Whether or not the user can post a comment.
  • url The comment's url.
  • votes Gets the amount of upvotes the comment has.
  • can_vote Indicates if the user can vote on the comment.
  • has_voted Indicates if the user has already upvoted the post.
  • author The User for the author of the post.
  • post The post that the comment was made on.
  • replies A list of replies that the comment received.
  • parent The parent comment, if any.
  • await reply(content) Replies to the comment with the content.
  • await report(reason) Report the comment
  • await delete() Delete the comment

User

  • id The user ID. Pretty useless since you can't get the user from their id.
  • name The user's username.
  • avatar The user's avatar url.
  • url The user's profile link.
  • cycles The amount of cycles/karma that user has.
  • roles The roles the user has set on their profile.
  • bio The short description written by a user on their profile.
  • first_name What the user set as their first name in their profile
  • last_name What the user set as their last name in their profile
  • languages The Languages that the user uses most often.
  • timestamp The time when the user account was created. (datetime.datetime object)
  • is_hacker Whether the user has the hacker plan
  • await get_comments(limit=30, order='new') Get a list of up to 1100 of the users comments. See Comment
  • await get_posts(limit=30, order='new') Get a list of up to 100 of the user's posts. See Post
  • await ban(reason) Ban the user

PostList/AsyncPostList

Acts like a normal list, except you can iterate over it

  • await next() Gets the next page of posts. Not present in AsyncPostList because it's done automatically.
  • board Gets the board of the repls it's getting from

Repl

  • id The Repl ID.
  • embed_url The url for embedding the Repl on a web page.
  • url The url of the Repl.
  • title The title of the Repl.
  • language The Language of the Repl.

Language

Represents a programming language on Repl.it.

  • id Gets the ID of the language (ie python3).
  • display_name Gets the display name of the language (ie Python).
  • icon Gets the url for the language icon.
  • category Gets the category that the language is listed as.
  • is_new Whether the language was recently added to Repl.it.
  • tagline A short description of the language.

Report List

List of reports. see Report If linked post/comment is deleted is lazy report, See lazyReport

  • for report in get_reports Cycles through the reports, with lazy posts/comments.
  • async for report in get_reports Cycles through the reports with full posts, if there is a post.

Report

A report on a comment or post

  • id The report id
  • type The type of the report. ('post' or 'comment')
  • reason Why the report was made
  • timestamp When the report was created
  • creator Who created the report
  • await get_attached() Get the attached post/comment

Lazy Report

A less complete report

  • id The report id
  • reason Why the report was made
  • creator Who created the report

Lazy Post

A less complete post

  • url The url to the post
  • id The post's id
  • author The post's author
  • content The post's content
  • title The post's title
  • await delete() Delete the post
  • await get_full_post() Returns the full post

Lazy Comment

A less complete comment

  • url The url to the comment
  • id The comment's id
  • author The comment's author
  • content The comment's content
  • await delete() Delete the comment
  • await get_full_comment() Returns the full comment

repl-talk-api's People

Contributors

coding-cactus avatar mat-1 avatar potentialstyx avatar techpixel avatar wbourne0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

repl-talk-api's Issues

get_user failing

I had this code working for some time to get the avatar of the repl owner (for which my repl is running in)

from repltalk import Client
import asyncio


async def get_repl_avatar(user_name):
    user = await Client().get_user(user_name)
    return user.avatar


def main():
    # replit avatar
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    global repl_avatar
    repl_avatar = loop.run_until_complete(get_repl_avatar(os.environ['REPL_OWNER']))

Essentially await Client().get_user(user_name) never completes.

Today it stopped working. Any idea why or do know a better way to get the avatar url?

Support for the AMA board

Even though it isn't known if the AMA board will stay up/active forever, it would be nice for it to be accessible through the API.

get_comments() not working as expected

The get_comments() function for a user object doesn't work and returns a Traceback error stating that 'type' object is not iterable.

Traceback:

  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/__init__.py", line 814, in get_comments
    _comments = await client._get_user_comments(
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/__init__.py", line 1182, in _get_user_comments
    return await self.perform_graphql(
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/__init__.py", line 966, in perform_graphql
    'query': str(query)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/graphql.py", line 89, in __str__
    output = 'query ' + str(self.field)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/graphql.py", line 67, in __str__
    value = builtin_to_graphql(value)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/graphql.py", line 7, in builtin_to_graphql
    value = str(item)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/graphql.py", line 72, in __str__
    output += str(value)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/graphql.py", line 53, in __str__
    output += str(item)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/graphql.py", line 72, in __str__
    output += str(value)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/graphql.py", line 67, in __str__
    value = builtin_to_graphql(value)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/graphql.py", line 7, in builtin_to_graphql
    value = str(item)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/graphql.py", line 65, in __str__
    for field in item:
TypeError: 'type' object is not iterable

Code snippet that led to error:

replit = repltalk.Client()
try:
	user = await replit.get_user(name)
	posts = await user.get_posts(limit=5, order='new')
	comments = await user.get_posts(limit=5, order='new')
except Exception as e:
        print(e)

Repl Spotlight/Apps Support

Add support for

  • Reading/writing comments on spotlight

  • Reading/adding reactions on spotlight

  • Getting repl description, maybe cover image

  • Read hashtags on spotlight

  • View all repls in a specific topic (hashtag)

  • Get the list of "Replit Picks"

Also will whitelisted_bots be fixed?

get_reports() ReportList not getting reset before loop

When doing async for report in await client.get_reports(resolved=False): multiple times, the get_reports() does not reset its list of reports for each loop, this results in an outdated and duplicated reports list being returned.

This is what I'm talking about:
image
As you can see, for each loop, the length of the list being returned by get_reports() increases by 4 (the number of actual unresolved reports). Btw the lst variable is getting reset correctly each loop.

Feature Request: Get Upvotes On Post

Feature Request: Get Upvotes On Post

So, this isn't an issue more like a feature request. There should be a async function on posts to get the people that upvoted the post and it should return like an array of people that upvoted. I will try to make a pull request for this if I can get it to work but do you think you can add this to the repl-talk-api? @mat-1

Error in get_all_comments()

I have the code:

import repltalk, asyncio

client = repltalk.Client()

async def getComments():
	for comment in await client.get_all_comments(order='new'):
		print(comment)

print(asyncio.run(getComments()))

And when i run it, I get the error:

Traceback (most recent call last):
  File "main.py", line 9, in <module>
    print(asyncio.run(getComments()))
  File "/usr/lib/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "main.py", line 6, in getComments
    for comment in await client.get_all_comments(order='new'):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/repltalk/__init__.py", line 1232
, in get_all_comments
    for c in _comments['items']:
TypeError: list indices must be integers or slices, not str

I don't know if I am just doing it wrong or it is an error on your end. Can you have a look please.

docstring + type hinting

Add doc strings + type hinting,

I can do this sometime

REEEEEE

checklist:

  • docstring main classes + functions
  • add type hinting
  • add docstring to custom exceptions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.