chore: add new requirement, document how to login

Bash as requirement due to how env vars are done
login tested and works
main
CrimsonTome 2022-10-23 23:37:31 +01:00 committed by Rowan Clark
parent ff6d74d09d
commit efe8ebcf32
No known key found for this signature in database
GPG Key ID: F620D51904044094
3 changed files with 30 additions and 10 deletions

View File

@ -1,4 +1,5 @@
# blog-to-cohost
bot using [cohost.py](https://github.com/valknight/Cohost.py) and feedparser to automate posting blog posts to cohost
## System requirements
@ -6,6 +7,7 @@ bot using [cohost.py](https://github.com/valknight/Cohost.py) and feedparser to
- Linux (Windows may work but is not tested)
- Python
- Pip
- Bash
- Docker (optional)
## Quicktstart
@ -28,6 +30,7 @@ bot using [cohost.py](https://github.com/valknight/Cohost.py) and feedparser to
<!-- steps here -->
- `docker build -t blog-to-cohost .`
## Contributing
<!-- TODO Add contributing guidelines -->
@ -38,4 +41,4 @@ blog-to-cohost is licensed under the MIT License. The full license text is inclu
This repo is built off [cohost.py](https://github.com/valknight/Cohost.py), a library for [cohost.org](https://cohost.org/)
No part of this code is approved by [cohost](https://cohost.org/), this uses an **unofficial** API.
No part of this code is approved by [cohost](https://cohost.org/), this uses an **unofficial** API.

View File

@ -1,2 +1,2 @@
cohost
feedparser
feedparser

View File

@ -1,14 +1,31 @@
# import cohost library
from cohost.models.user import User
from cohost.models.block import AttachmentBlock, MarkdownBlock
cookie = 'yourCookie'
# import os for environment variable management
import os
# set cookie in with below line bwlow, you will have to run again when you reload your shell. to get around this run the line below that and then reload your shell
# export COOKIE="YOUR-TOKEN-HERE"
# echo 'export COOKIE="YOUR-TOKEN-HERE"' >> ~/.bashrc
# see https://github.com/valknight/Cohost.py#tokens for how to get your token
# import the cookie
cookie = os.environ.get("COOKIE")
# uncomment for testing purposes
# print(cookie)
#login
user = User.loginWithCookie(cookie)
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))
# project = user.getProject('username') # 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))