fixed scheduler

This commit is contained in:
Kónya Márton 2020-07-20 03:00:08 +02:00
parent af2afa040a
commit 63aa05163f
1 changed files with 19 additions and 3 deletions

22
run.py
View File

@ -7,9 +7,19 @@ from os.path import exists
import sys
import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
from prawcore import NotFound
def sub_exists(sub):
exists = True
try:
reddit.subreddits.search_by_name(sub, exact=True)
except NotFound:
exists = False
return exists
def test(text):
print(f'It is working {text}')
print(f'It is working {text}. Please press CTRL+C to close the script!')
def e():
title = input('What will be the title of your post? ')
@ -22,6 +32,8 @@ def e():
def s():
subreddit = input('Please type in the subbreddits\' name without \'r/\': ')
while not sub_exists(subreddit):
subreddit = input('This subreddit doesn\'t exists. Please try another one: ')
return subreddit
def t():
@ -44,7 +56,7 @@ def l():
def post(title, body, subreddit):
reddit.subreddit(subreddit).submit(title, selftext=body)
sys.exit(f'Succesfully posted your text to r/{subreddit}. Thank you for using my script!')
# sys.exit(f'Succesfully posted your text to r/{subreddit}. Thank you for using my script!')
def authenticate(password, user):
return praw.Reddit(client_id='iGx0qS8p1vxccA'
@ -128,7 +140,11 @@ print('Please don\'t exit the script until the scheduled time because in that ca
sched = BlockingScheduler()
sched.add_job(test, 'date', run_date=date_to_post, args=['text'])
sched.start()
try:
sched.start()
except (KeyboardInterrupt):
logging.debug('The script has been closed. Thank you for using!')
# schedule.every().monday.at("17:12").do(uzenet)