From efe8ebcf3281113b56e0744b665898af65658b14 Mon Sep 17 00:00:00 2001 From: CrimsonTome Date: Sun, 23 Oct 2022 23:37:31 +0100 Subject: [PATCH] chore: add new requirement, document how to login Bash as requirement due to how env vars are done login tested and works --- README.md | 5 ++++- requirements.txt | 2 +- scripts/main.py | 33 +++++++++++++++++++++++++-------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2185b8e..4828fa0 100644 --- a/README.md +++ b/README.md @@ -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 - `docker build -t blog-to-cohost .` + ## Contributing @@ -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. diff --git a/requirements.txt b/requirements.txt index 14a18c0..b381150 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ cohost -feedparser +feedparser \ No newline at end of file diff --git a/scripts/main.py b/scripts/main.py index 6188cc0..8a5154c 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -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)) \ No newline at end of file +# 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)) \ No newline at end of file