dotenv does not working

This commit is contained in:
Kónya Márton 2020-07-20 10:29:10 +02:00
parent 399f8d8fa1
commit 2b5d100b7e
1 changed files with 19 additions and 13 deletions

32
run.py
View File

@ -1,12 +1,13 @@
# by Koma52
import os
import praw
import time
from getpass import getpass
from os.path import exists
import sys
import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.schedulers.background import BackgroundScheduler
import logging
from prawcore import NotFound
from dotenv import load_dotenv
@ -58,16 +59,15 @@ def l():
def post(title, body, subreddit):
try:
reddit.subreddit(subreddit).submit(title, selftext=body)
print(f'Please press CTRL+C to close the script!')
pass
except:
print(f'Something went wrong. Maybe you don\'t have permission to post in r/{subreddit}. Please press CTRL+C to close the script!')
pass
# 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='BeyDq1uf14_vfQ'
, client_secret='ogpfdmBvy4T67UYmE6w-2PeIhnU'
def authenticate(password, user, user_secret, secret2):
return praw.Reddit(client_id=user_secret
, client_secret=secret2
, password=password
, user_agent='PrawTut'
, username=user)
@ -97,7 +97,10 @@ while len(credentials[0]) == 0 and len(credentials[1]) == 0:
credentials = cred_input()
# making reddit instance
reddit = authenticate(credentials[1], credentials[0])
load_dotenv('creds.env')
USER_SECRET = str(os.getenv('USERSECRET'))
SECRET = str(os.getenv('SECRET2'))
reddit = authenticate(credentials[1], credentials[0], USER_SECRET, SECRET)
try:
print(f'You\'re logged in as {reddit.user.me()}')
@ -109,9 +112,6 @@ In that case please turn off 2FA because it\'s not compatible with this script!
exit()
reddit.validate_on_submit = True
load_dotenv('creds.env')
USER_SECRET = os.getenv('USERSECRET')
SECRET = os.getenv('SECRET2')
ready = '0'
checker = ['0', '0', '0'] # for checking if all neccesary functions have been run
@ -157,13 +157,19 @@ except:
body = file.read()
sched = BlockingScheduler()
sched = BackgroundScheduler()
sched.add_job(post, 'date', run_date=date_to_post, args=[title, body, subreddit])
sched.start()
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
try:
sched.start()
except (KeyboardInterrupt):
logging.debug('The script has been closed. Thank you for using!')
# This is here to simulate application activity (which keeps the main thread alive).
while True:
time.sleep(2)
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
scheduler.shutdown()
# schedule.every().monday.at("17:12").do(uzenet)