fixed scheduler
This commit is contained in:
parent
af2afa040a
commit
63aa05163f
22
run.py
22
run.py
|
|
@ -7,9 +7,19 @@ from os.path import exists
|
||||||
import sys
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
from apscheduler.schedulers.blocking import BlockingScheduler
|
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):
|
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():
|
def e():
|
||||||
title = input('What will be the title of your post? ')
|
title = input('What will be the title of your post? ')
|
||||||
|
|
@ -22,6 +32,8 @@ def e():
|
||||||
|
|
||||||
def s():
|
def s():
|
||||||
subreddit = input('Please type in the subbreddits\' name without \'r/\': ')
|
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
|
return subreddit
|
||||||
|
|
||||||
def t():
|
def t():
|
||||||
|
|
@ -44,7 +56,7 @@ def l():
|
||||||
|
|
||||||
def post(title, body, subreddit):
|
def post(title, body, subreddit):
|
||||||
reddit.subreddit(subreddit).submit(title, selftext=body)
|
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):
|
def authenticate(password, user):
|
||||||
return praw.Reddit(client_id='iGx0qS8p1vxccA'
|
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 = BlockingScheduler()
|
||||||
sched.add_job(test, 'date', run_date=date_to_post, args=['text'])
|
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)
|
# schedule.every().monday.at("17:12").do(uzenet)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue