chore: add loop and wait period, yet to be tested

main
CrimsonTome 2022-10-24 20:17:15 +01:00 committed by Rowan Clark
parent 01da0f8f4d
commit c31952eaa6
No known key found for this signature in database
GPG Key ID: F620D51904044094
1 changed files with 65 additions and 54 deletions

View File

@ -8,56 +8,61 @@ import sys
from time import sleep
import feedparser as fp
# get number of posts
try:
while True:
"""
check local count with remote count
if remote is greater than local count post
sleep(x time)
"""
# get number of posts
try:
feedLength = environ.get("LENGTH")
except KeyError:
except KeyError:
print ('Please set the environment variable LENGTH with export LENGTH="NUMBER-OF-POSTS"')
sys.exit(1)
feedLength = int(feedLength)
# print (feedLength)
feedLength = int(feedLength)
# print (feedLength)
# fetch and parse the feed
data = fp.parse("https://crimsontome.com/feed/feed.xml") # replace with your feed url
# extract title, url and date from most recent post (0)
title = data.entries[0].title
url = data.entries[0].link
date = data.entries[0].updated.split("T", 1)[0] # cut off date after yyyy-mm-dd - US date...
# extract number of posts from the feed. this is used to compare our local value, to check if there has been a post since we last posted to cohost
postNum = len(data.entries)
# print (title, url, date, postNum)
# 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
# fetch and parse the feed
data = fp.parse("https://crimsontome.com/feed/feed.xml") # replace with your feed url
# extract title, url and date from most recent post (0)
title = data.entries[0].title
url = data.entries[0].link
date = data.entries[0].updated.split("T", 1)[0] # cut off date after yyyy-mm-dd - US date...
# extract number of posts from the feed. this is used to compare our local value, to check if there has been a post since we last posted to cohost
postNum = len(data.entries)
# print (title, url, date, postNum)
# 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
# try import the cookie, tells the user to set it if it does not exist
try:
# try import the cookie, tells the user to set it if it does not exist
try:
cookie = environ.get("COOKIE")
except KeyError:
except KeyError:
print ('Please set the environment variable COOKIE with export COOKIE="YOUR-TOKEN-HERE"')
sys.exit(1)
# uncomment for testing purposes
# print(cookie)
# uncomment for testing purposes
# print(cookie)
#login
user = User.loginWithCookie(cookie)
#login
user = User.loginWithCookie(cookie)
# for project in user.editedProjects:
# print(project) # Print all pages you have edit permissions for
project = user.getProject('crimsontome427') # replace with your project name
#if there's a new post on the blog and not on cohost already
if postNum > feedLength:
# for project in user.editedProjects:
# print(project) # Print all pages you have edit permissions for
project = user.getProject('crimsontome427') # replace with your project name
#if there's a new post on the blog and not on cohost already
if postNum > feedLength:
blocks = [
# AttachmentBlock('pybug.png'), # References image file pybug.png
# fill in some post data
@ -73,3 +78,9 @@ if postNum > feedLength:
file1 = open("/home/ctome/.bashrc", "a") # append mode, replace with your bashrc location
file1.write('export LENGTH="'+str(feedLength)+'"')
file1.close()
else:
print("no change")
# wait another 5 mins before trying again
sleep(300)