Ejemplo n.º 1
0
def gen_video_from_hot():
    print("Subscribe or i'll end humanity.")

    with open('reddit_secret.json') as f:
        secret = json.load(f)

    print(secret)
    reddit = praw.Reddit(client_id=secret['client_id'],
                         client_secret=secret['client_secret'],
                         user_agent=secret['user_agent'])

    a_subreddit = reddit.subreddit('AskReddit')
    print(a_subreddit.display_name,
          '\n' + ('=' * len(a_subreddit.display_name)))
    submission = list(a_subreddit.hot(limit=1))[0]
    print("\nTitle:", submission.title)
    print("URL: " + submission.url)
    print("Author:", submission.author)
    print("\n")
    submission.sort = 'top'
    path = "rtemp" + ".mp4"
    create_submission_video(submission, path)
    uploaded = True
    upload_response = None
    try:
        upload_response = upload_video(
            path,
            description=DESCRIPTION + "Link to subreddit post: " +
            submission.url + "\n" + submission.title,
            title="AskReddit: " + submission.title,
            keywords="AskReddit, Reddit")
    except:
        uploaded = False
    if uploaded:
        uploaded_vids_db.insert({
            "reddit_url": submission.url,
            "permanent_reddit_url": submission.permalink,
            "youtube": upload_response
        })
    clean_temp()
        print(a_subreddit.display_name, '\n' + ('=' * len(a_subreddit.display_name)))
        # for index, submission in enumerate(a_subreddit.hot(limit=1)):

        # submission = a_subreddit.hot(limit=1).__next__(islice(count(), 0, 0 + 1))
        submission = list(a_subreddit.hot(limit=1))[0]
        print("\nTitle:", submission.title)
        print("URL: " + submission.url)
        print("Author:", submission.author)
        print("\n")
        submission.sort = 'top'
        path = "rtemp" + ".mp4"
        create_submission_video(submission, path)
        uploaded = True
        upload_response = None
        try:
            upload_response = upload_video(path,
                                           description=DESCRIPTION + "Link to subreddit post: " + submission.url + "\n" +
                                                       submission.title, title="AskReddit: " +
                                                                               submission.title,
                                           keywords="AskReddit, Reddit")
        except:
            uploaded = False
        if uploaded:
            uploaded_vids_db.insert(
                {"reddit_url": submission.url, "permanent_reddit_url": submission.permalink, "youtube": upload_response})
        clean_temp()
    except:
        print("Something went wrong")
        clean_temp()
    time.sleep(8 * 60 * 60)
Ejemplo n.º 3
0
from yt_upload import upload_video

upload_video()
Ejemplo n.º 4
0
def main():
    print("Subscribe or i'll end humanity.")

    with open('reddit_secret.json') as f:
        secret = json.load(f)

    reddit = praw.Reddit(client_id=secret.client_id,
                         client_secret=secret.client_secret,
                         user_agent=secret.user_agent)

    type = input("1. Top 2. Custom 3. Hot: ")

    if int(type) == 1:
        a_subreddit = reddit.subreddit('AskReddit')

        print(a_subreddit.display_name,
              '\n' + ('=' * len(a_subreddit.display_name)))

        for index, submission in enumerate(a_subreddit.top(limit=1)):
            print("\nTitle:", submission.title)
            print("Author:", submission.author)
            print("\n")
            submission.sort = 'top'
            path = "rtemp" + str(index) + ".mp4"
            prompt_create_submission_video(submission, path)
            uploaded = True
            upload_response = None
            try:
                upload_video(path,
                             description="",
                             title="AskReddit: " + submission.title,
                             keywords="AskReddit, Reddit")
            except:
                uploaded = False
            if uploaded:
                uploaded_vids_db.insert({
                    "reddit_url": submission.url,
                    "permanent_reddit_url": submission.permalink,
                    "youtube": upload_response
                })
            clean_temp()

    elif int(type) == 2:
        url = input("Enter subreddit submission url: ")
        submission = praw.models.Submission(reddit, url=url)
        print("\nTitle:", submission.title)
        print("Author:", submission.author)
        print("\n")
        submission.sort = 'top'
        path = "media/" + submission.title + "_" + submission.id + ".mp4"
        prompt_create_submission_video(submission, path)
        uploaded = True
        upload_response = None
        try:
            uploaded_respone = upload_video(
                path,
                description=DESCRIPTION + "Link to subreddit post: " + url +
                "\n" + submission.title,
                title="AskReddit: " + submission.title,
                keywords="AskReddit, Reddit")
        except:
            uploaded = False
        if uploaded:
            uploaded_vids_db.insert({
                "reddit_url": url,
                "permanent_reddit_url": submission.permalink,
                "youtube": upload_response
            })

    elif int(type) == 3:
        a_subreddit = reddit.subreddit('AskReddit')
        print(a_subreddit.display_name,
              '\n' + ('=' * len(a_subreddit.display_name)))
        submission = list(a_subreddit.hot(limit=1))[0]
        print("\nTitle:", submission.title)
        print("URL: " + submission.url)
        print("Author:", submission.author)
        print("\n")
        submission.sort = 'top'
        path = "rtemp" + ".mp4"
        prompt_create_submission_video(submission, path)
        uploaded = True
        upload_response = None
        try:
            upload_response = upload_video(
                path,
                description=DESCRIPTION + "Link to subreddit post: " +
                submission.url + "\n" + submission.title,
                title="AskReddit: " + submission.title,
                keywords="AskReddit, Reddit")
        except:
            uploaded = False
        if uploaded:
            uploaded_vids_db.insert({
                "reddit_url": submission.url,
                "permanent_reddit_url": submission.permalink,
                "youtube": upload_response
            })
        clean_temp()