80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
|
from enum import Enum
|
||
|
import praw
|
||
|
import json
|
||
|
import requests
|
||
|
|
||
|
class PostFlair(str, Enum):
|
||
|
debug = "b9626520-a55b-11ed-8a89-de8567ca69ac"
|
||
|
light_novel = "4c6c8e7c-2f96-11ed-b4e8-8ad3482a4000"
|
||
|
manga = "48e0f284-2f96-11ed-8035-9e12ed32b10a"
|
||
|
anime = "4671b6fa-2f96-11ed-8f94-324864767feb"
|
||
|
pre_pub = "dc2829a2-a14e-11ed-962a-ee45985252e2"
|
||
|
|
||
|
|
||
|
class PostData():
|
||
|
title: str
|
||
|
link: str
|
||
|
image: str
|
||
|
flair: PostFlair
|
||
|
|
||
|
def __init__(self):
|
||
|
pass
|
||
|
|
||
|
def main():
|
||
|
data = loadConfig("config.json")
|
||
|
postConfigs = data['PostConfigs']
|
||
|
botConfig = data['BotConfig']
|
||
|
|
||
|
reddit = praw.Reddit(
|
||
|
client_id = botConfig['appId'],
|
||
|
client_secret = botConfig['appSecret'],
|
||
|
refresh_token = botConfig['refreshToken'],
|
||
|
redirect_uri = botConfig['redirectUri'],
|
||
|
user_agent = botConfig['userAgent']
|
||
|
)
|
||
|
|
||
|
sub = reddit.subreddit(botConfig['subReddit'])
|
||
|
|
||
|
#submissionList = reddit.redditor("MestionorasAvatar").submissions.new()
|
||
|
|
||
|
# Timer Logic will be implemented here
|
||
|
# Move into class to improve performance (less value copying)
|
||
|
if True:
|
||
|
feedUri = postConfigs[0]['feed']
|
||
|
postData = getFeedData(feedUri)
|
||
|
postData.flair = PostFlair[postConfigs[0]['flair']]
|
||
|
|
||
|
exists = True
|
||
|
#for submission in submissionList:
|
||
|
exists = False
|
||
|
if not exists:
|
||
|
createPost(sub, postData)
|
||
|
pass
|
||
|
|
||
|
def createPost(sub, postConfig):
|
||
|
sub.submit(title=postConfig.title, url=postConfig.link, flair_id=postConfig.flair.value, spoiler=True)
|
||
|
pass
|
||
|
|
||
|
def getFeedData(uri) -> PostData:
|
||
|
res = requests.get(uri)
|
||
|
|
||
|
newPost = PostData()
|
||
|
|
||
|
if res.ok:
|
||
|
data = res.json()
|
||
|
# return most recent entry
|
||
|
recentEntry = data['items'][0]
|
||
|
newPost.title = recentEntry['title']
|
||
|
newPost.link = recentEntry['url']
|
||
|
newPost.image = recentEntry['image']
|
||
|
|
||
|
return newPost
|
||
|
|
||
|
|
||
|
def loadConfig(filePath):
|
||
|
configFile = open(filePath)
|
||
|
data = json.load(configFile)
|
||
|
return data
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|