initial
This commit is contained in:
parent
4571c65be6
commit
8fdb52ba4c
|
|
@ -0,0 +1 @@
|
|||
*.txt
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
import praw
|
||||
import time
|
||||
from getpass import getpass
|
||||
from os.path import exists
|
||||
import sys
|
||||
import datetime
|
||||
from apscheduler.schedulers.blocking import BlockingScheduler
|
||||
|
||||
def test(text):
|
||||
print(f'It is working {text}')
|
||||
|
||||
def e():
|
||||
title = input('What will be the title of your post? ')
|
||||
out_file = open("post.txt", 'w')
|
||||
print('Welcome to the editor. Here you can edit your post. Just start writing and don\'t use linebreaks because RETURN key will save your text.')
|
||||
post = input()
|
||||
out_file.write(post)
|
||||
out_file.close()
|
||||
return title
|
||||
|
||||
def s():
|
||||
subreddit = input('Please type in the subbreddits\' name without \'r/\': ')
|
||||
return subreddit
|
||||
|
||||
def t():
|
||||
post_date = input('Please type in the date you want to post in the format: yyyy MM dd hh mm: ')
|
||||
post_datetime = datetime.datetime(int(post_date.split()[0])
|
||||
, int(post_date.split()[1])
|
||||
, int(post_date.split()[2])
|
||||
, int(post_date.split()[3])
|
||||
, int(post_date.split()[4]))
|
||||
return post_datetime
|
||||
|
||||
def l():
|
||||
if exists('post.txt'):
|
||||
in_file = open('post.txt')
|
||||
print(in_file.read())
|
||||
else:
|
||||
print('First you have to edit your post!')
|
||||
input('Press a button to return to the main menu!')
|
||||
pass
|
||||
|
||||
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!')
|
||||
|
||||
def authenticate(password, user):
|
||||
return praw.Reddit(client_id='iGx0qS8p1vxccA'
|
||||
, client_secret='ThFJk_Gc6wrQhn-2F7riwNOUYk4'
|
||||
, password=password
|
||||
, user_agent='PrawTut'
|
||||
, username=user)
|
||||
|
||||
def cred_input():
|
||||
# username input
|
||||
user = input('Username: ')
|
||||
|
||||
# password input
|
||||
password = getpass('Password: ')
|
||||
|
||||
creds = []
|
||||
|
||||
creds.append(user)
|
||||
creds.append(password)
|
||||
|
||||
return creds
|
||||
|
||||
print('''This is the Reddit scheduler by Koma52
|
||||
Please type in your login credentials''')
|
||||
|
||||
credentials = cred_input()
|
||||
|
||||
# validating credentials
|
||||
while len(credentials[0]) == 0 and len(credentials[1]) == 0:
|
||||
print('The credetials you gave are not valid. Please try again!')
|
||||
credentials = cred_input()
|
||||
|
||||
# making reddit instance
|
||||
reddit = authenticate(credentials[1], credentials[0])
|
||||
|
||||
try:
|
||||
print(f'You\'re logged in as {reddit.user.me()}')
|
||||
except:
|
||||
print('''
|
||||
There was an exception. Maybe you misstyped your credentials or you are using 2FA.
|
||||
In that case please turn off 2FA because it\'s not compatible with this script!
|
||||
''')
|
||||
exit()
|
||||
|
||||
ready = '0'
|
||||
checker = ['0', '0', '0'] # for checking if all neccesary functions have been run
|
||||
|
||||
while ready != '1':
|
||||
print('''
|
||||
Welcome to the main menu. Here are your choices:
|
||||
e -> edit the post you want to schedule-
|
||||
l -> take a look at your scheduled post
|
||||
s -> edit the subreddit you want to post to-
|
||||
t -> edit the time you want to post
|
||||
r -> your are ready to schedule
|
||||
q -> quit the script-
|
||||
''')
|
||||
choice = input('> ')
|
||||
if choice == 'q':
|
||||
exit()
|
||||
elif choice == 't':
|
||||
date_to_post = t()
|
||||
print(date_to_post)
|
||||
checker[0] = '1'
|
||||
elif choice == 'e':
|
||||
title = e()
|
||||
checker[1] = '1'
|
||||
elif choice == 's':
|
||||
subreddit = s()
|
||||
checker[2] = '1'
|
||||
elif choice == 'r':
|
||||
if checker != ['1', '1', '1']:
|
||||
print('First you have to edit your post, give the subreddit and schedule your post')
|
||||
else:
|
||||
ready = '1'
|
||||
elif choice == 'l':
|
||||
l()
|
||||
|
||||
print('Please don\'t exit the script until the scheduled time because in that case it wouldn\'t work!')
|
||||
|
||||
|
||||
sched = BlockingScheduler()
|
||||
sched.add_job(test, 'date', run_date=date_to_post, args=['text'])
|
||||
sched.start()
|
||||
|
||||
# schedule.every().monday.at("17:12").do(uzenet)
|
||||
|
||||
# while True:
|
||||
# schedule.run_pending()
|
||||
# time.sleep(1)
|
||||
Loading…
Reference in New Issue