Unofficial Python API wrapper for Cohost.org - the fourth website!
Project description
Cohost.py
A python library for Cohost!
Hyperstart
pip install cohost
Quickstart
pip install cohost
from cohost.models.user import User
from cohost.models.block import AttachmentBlock, MarkdownBlock
cookie = 'yourCookie'
user = User.loginWithCookie(cookie)
# Alternatively: use a username/password combo
# import os
# user = User.login(os.getenv("COHOST_USER"), os.getenv("COHOST_PASS"))
for project in user.editedProjects:
print(project) # Print all pages you have edit permissions for
project = user.getProject('vallerie') # will retrieve the page I have edit writes for with handle @vallerie
blocks = [
AttachmentBlock('pybug.png'), # References image file pybug.png
MarkdownBlock('**Hello from Python!**') # Example of markdown / text block
]
newPost = project.post('Title of python post!', blocks, tags=['cohost.py', 'python'])
print('Check out your post at {}'.format(newPost.url))
Getting started
- Have an activated Cohost.org account. This entire library will probably explode if you use it with an unactivated account, and it defo isn't some bypass.
- Install library with
pip install cohost
- Log in with a cookie or a username/password
- Import data models you require, and go from there!
Terminology
Some things are different on the API, and on the UI, and for the most part this library will match the API's terminology. Some key concepts:
- A user is minimal - it will contain authentication, email, and some other key details but not much else
- All the pages you can edit are referred to as "projects"
- Each post is made up content "Blocks"
Retrieving your cookie
One way to login is to use an authentication token for Cohost. This can be retrieved by:
- Open Developer Tools in your browser
- Go to "Storage"
- Find the "Cookies" entry
- Copy the data for "
connect.sid
". - Use this in the library
What's working? (allegedly)
- Logging in as a user (using either a cookie or a username/password)
- Retrieving projects of a user (and of other people when you got a post to go with it)
- Retrieving posts of a page
- Posting to a page
- Attaching images to a post (with alt-text support!)
- Editing posts
- Retrieving notifications with pagination
What's not done but needs to be done?
- Retrieving single posts - currently have to read entire projects
- Retrieving a project's drafts
- Retrieving a projects of others without a post inbetween
- Sharing posts (with comment)
- Editing profiles
- Deleting posts
- Likely a whole bunch of other things I haven't thought about
- Better docs
What's not implemented intentionally?
Some features I intend not to add. These features aren't impossible to build, but, they could be detrimental to the Cohost experience for other users, send mass notifications without an account being activated, or pose security issues. This is designed to deter low effort malicious bots, to reduce the workload on Cohost's staff.
These include:
- Editing a user's password
- Accepting follow requests
- Sharing a post without a comment
- Creating new projects
If you implement these features, please keep them private for your projects. If you think one of these should be implemented, please file a GitHub issue with your case as to why.
Support Cohost
Follow me on Cohost!
Thanks
- cohost.js - provided a good point to start looking at how to go about this, and how cohost works in fundamental aspects. also has a working login thing which i need to properly understand at some point
- cohost.org - home of eggbug
- requests - i would be lost in python if it weren't for requests, my beloved
- the random tumblr anon who sent me an activation link - thanks
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
File details
Details for the file cohost-0.5.1.tar.gz
.
File metadata
- Download URL: cohost-0.5.1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69152549e3e4a77b3f315f4d5f816e524f57f9e09415bd0c17f00978ab14f5f9 |
|
MD5 | 6015f5140c9e4a0c48b898e4cd697ca0 |
|
BLAKE2b-256 | a2be376d32a79ac085dab3f55c8154cdf6ac331f577afbba8f8dfd058bb335b2 |
File details
Details for the file cohost-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: cohost-0.5.1-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bbe22c113712697372043d008a4b22b0570e7dbb575eacf6641e4ef8b20ce25 |
|
MD5 | d5f17d3c3b18e8aca688ce041badbda4 |
|
BLAKE2b-256 | 86dc13c1b5616dd30c61df527ca87d295d8b6dfcc0486cd521989580422cf161 |