fixing cookie things, more or less

This commit is contained in:
Gaël
2024-07-03 17:01:29 +02:00
parent d2b39db82e
commit f17cd92f90
9 changed files with 1170 additions and 9 deletions

View File

@@ -11,6 +11,9 @@ import re
from logging.handlers import RotatingFileHandler
import random
import pyvirtualdisplay
from substack import Api
from substack.post import Post
@@ -45,10 +48,11 @@ class RSSfeed():
self.youtube = yt
class SubStackTask:
def __init__(self, login, password, account, feeds):
def __init__(self, login, password, cookies_path, account, feeds):
self.api = Api(
email=login,
password=password,
cookies_path=cookies_path,
publication_url=account,
)
@@ -95,11 +99,11 @@ class SubStackTask:
formatted_date = formatted_date.replace(en, fr)
return formatted_date
async def run_daily_at_6_am(self):
async def run_daily_at_11_am(self):
while True:
now = datetime.datetime.now()
# Calculate the time until 6 AM next day
next_run = (now + datetime.timedelta(days=1)).replace(hour=6, minute=5, second=0, microsecond=0)
next_run = (now + datetime.timedelta(days=1)).replace(hour=11, minute=0, second=0, microsecond=0)
sleep_seconds = (next_run - now).total_seconds()
while sleep_seconds > 0:
@@ -237,7 +241,12 @@ async def main(login, password, account):
ff = r'/data/feeds.txt'
if os.path.isfile(ff) is False:
ff = r'x:\substack\feeds.txt'
ff = r'feeds.txt'
cookies_path = r'/data/cookies.json'
if os.path.isfile(cookies_path) is False:
cookies_path = r'cookies.json'
with open(ff) as file:
lines = [line.rstrip() for line in file]
@@ -245,10 +254,10 @@ async def main(login, password, account):
youtube = "youtube" in line
feeds.append(RSSfeed(line, youtube))
task = SubStackTask(login, password, account, feeds)
task = SubStackTask(login, password, cookies_path, account, feeds)
LOG.info("Starting bot")
await task.run_daily_at_6_am()
await task.run_daily_at_11_am()
#await task.daily_task()