コード例 #1
0
def get_gtd_info(depth=0):
    headgum_channel_id = 'UCV58y_DbGkuYCNQC2OjJWOw'
    url_fmtstring = 'https://www.googleapis.com/youtube/v3/search?key={key}&channelId={channel_id}&part=snippet,id&order=date&maxResults=15&safeSearch=none'
    url = url_fmtstring.format(
        channel_id=headgum_channel_id,
        key=reddit_password.get_yt_api_key(),
    )
    resp = requests.get(url,
                        timeout=15.,
                        headers={
                            'Cache-Control': 'max-age=0, no-cache',
                        })
    json_data = json.loads(resp.text)
    if 'items' not in json_data:
        if depth > 5:
            send_email(subject="JSON error after 5 retries",
                       body="json_data: {}".format(json_data),
                       to="*****@*****.**")
            return None
        print("JSON ERROR?: {}".format(json_data))
        time.sleep(5)
        return get_gtd_info(depth=depth + 1)
    most_recent_vidz = [
        item for item in json_data['items']
        if ('Day in the Strife' in item['snippet']['title']
            or 'Off Days' in item['snippet']['title']
            or 'Geoffrey the Dumbass' in item['snippet']['title'])
    ]
    GTD_objs = [GTD.from_json_obj(item) for item in most_recent_vidz]
    GTD_objs = [x for x in GTD_objs if x]
    if GTD_objs:
        return GTD_objs[0]
    else:
        return None
コード例 #2
0
def get_gtd_info(depth=0):
    headgum_channel_id = 'UCV58y_DbGkuYCNQC2OjJWOw'
    url_fmtstring = 'https://www.googleapis.com/youtube/v3/search?key={key}&channelId={channel_id}&part=snippet,id&order=date&maxResults=5&safeSearch=none'
    url = url_fmtstring.format(
        channel_id=headgum_channel_id,
        key=reddit_password.get_yt_api_key(),
    )
    resp = requests.get(
        url,
        timeout=15.,
        headers={
            'Cache-Control': 'max-age=0, no-cache',
        }
    )
    json_data = json.loads(resp.text)
    if 'items' not in json_data:
        if depth > 5:
            send_email(subject="JSON error after 5 retries", body="json_data: {}".format(json_data), to="*****@*****.**")
            return None
        print("JSON ERROR?: {}".format(json_data))
        time.sleep(5)
        return get_gtd_info(depth=depth+1)
    most_recent_vidz = [item for item in json_data['items'] if 'Geoffrey the Dumbass' in item['snippet']['title'] or 'Off Days' in item['snippet']['title']]
    GTD_objs = [GTD.from_json_obj(item) for item in most_recent_vidz]
    GTD_objs = [x for x in GTD_objs if x]
    if GTD_objs:
        return GTD_objs[0]
    else:
        return None
コード例 #3
0
def main():
    global force_submit_iiwy, force_submit_twins, force_submit_nadd, force_submit_revue, force_submit_headgum, force_submit_rewatch, force_submit_gtd, force_submit_jna

    default_timeout = 20  # don't spam the servers :D

    foundlist = initialize_foundlist()

    mod_info = ModInfo(foundlist)

    time.sleep(5)
    jjkae_tools.start_test_thread(email_if_failures=True)

    past_exception_string = None
    while True:
        try:
            iiwy_loop(mod_info, force_submit_iiwy)
            force_submit_iiwy = False  # Only do it once

            twins_loop(mod_info, force_submit_twins)
            force_submit_twins = False  # Only do it once

            nadd_loop(mod_info, force_submit_nadd)
            force_submit_nadd = False  # Only do it once

            revue_loop(mod_info, force_submit_revue)
            force_submit_revue = False  # Only do it once

            headgum_loop(mod_info, force_submit_headgum)
            force_submit_headgum = False  # Only do it once

            mod_loop(mod_info, force_submit_rewatch)
            force_submit_rewatch = False  # Only do it once

            # Do it 10% of the time. This is because Youtube pretty heavily rate limits requests, so we can't be
            # hitting the server 3 times a minute.
            if mod_info.i % 10 == 1:
                gtd_loop(mod_info, force_submit_gtd)
                force_submit_gtd = False  # Only do it once

                jna_loop(mod_info, force_submit_jna)
                force_submit_jna = False  # Only do it once

            timeout = get_timeout(default_timeout)
            if timeout != 0:
                time.sleep(timeout)

            jjkae_tools.printinfo(mod_info)
            mod_info.i += 1
        except (SystemExit, KeyboardInterrupt) as e:
            raise e
        except Exception as e:
            this_exception_string = "{} {}".format(type(e).__name__, str(e.args))
            print(this_exception_string)
            if past_exception_string != this_exception_string:
                jjkae_tools.send_email(subject="JAKE AND AMIR BOT ERROR", body=this_exception_string, to="*****@*****.**")
                print("SENT EMAIL!!!")
            print(this_exception_string)
            past_exception_string = this_exception_string
            time.sleep(1.0)
            pass
コード例 #4
0
def get_jna_info(depth=0):
    jna_channel_id = 'UCNNxmRzlheZAeZuMYakh6vQ'
    url_fmtstring = 'https://www.googleapis.com/youtube/v3/search?key={key}&channelId={channel_id}&part=snippet,id&order=date&maxResults=15&safeSearch=none'
    url = url_fmtstring.format(
        channel_id=jna_channel_id,
        key=reddit_password.get_yt_api_key(),
    )
    resp = requests.get(url,
                        timeout=15.,
                        headers={
                            'Cache-Control': 'max-age=0, no-cache',
                        })
    json_data = json.loads(resp.text)
    if 'items' not in json_data:
        if depth > 5:
            send_email(subject="JSON error after 5 retries",
                       body="json_data: {}".format(json_data),
                       to="*****@*****.**")
            return None
        print("JSON ERROR?: {}".format(json_data))
        time.sleep(5)
        return get_jna_info(depth=depth + 1)
    most_recent_vidz = [
        item for item in json_data['items']
        if ('Jake and Amir:' in item['snippet']['title'])
    ]
    jna_objs = [JNA.from_json_obj(item) for item in most_recent_vidz]
    jna_objs = [x for x in jna_objs if x]
    if jna_objs:
        return jna_objs[0]
    else:
        return None
コード例 #5
0
ファイル: nadd.py プロジェクト: popcorncolonel/JakeandAmirBot
def get_nadd_info(depth=0):
    title = None
    name = None
    url = None
    desc = None
    episode_num = None
    filename = None
    if depth > 3:
        send_email(subject="NADD GETINFO ERROR", body="IDK depth={}".format(depth), to="*****@*****.**")
        sys.exit() # should I exit or just keep going???
    try:
        r = None
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            rss_loc = 'https://www.omnycontent.com/d/playlist/77bedd50-a734-42aa-9c08-ad86013ca0f9/4dbfc420-53a4-40c6-bbc7-ad8d012bc602/6ede3615-a245-4eae-9087-ad8d012bc631/podcast.rss'
            rss = feedparser.parse(rss_loc)
            episode = rss.entries[0]
    except (KeyboardInterrupt, SystemExit):
        raise
    except requests.exceptions.Timeout:
        print("encountered request Timeout. recursing.")
        time.sleep(3)
        return get_nadd_info()
    except Exception as e:
        print("encountered request error =(")
        print(e)
        time.sleep(3)
        return get_nadd_info(depth=depth + 1)
    orig_title = episode.title  # full title including number. `title` is like "Eldermourne - Ep. 32: People on the Inside"
    url = episode.links[-1].href
    episode_num = None
    title = orig_title
    if ': ' in orig_title:
        [episode_num, title] = orig_title.split(': ', maxsplit=1)  # now `title` is like "Dark Ritual (The Moonstone Saga)"
        episode_num_string = episode_num.split(' ')[-1]  # Ep. 5 -> 5, 'BONUS EPISODE' -> 'EPISODE'
        if episode_num_string.isdigit():
            episode_num = int(episode_num_string)
    if episode_num is not None:
        name = 'Episode {episode_num}: {title}'.format(**locals())
    else:
        name = 'Not Another D&D Podcast: {orig_title}'.format(**locals())
    reddit_title = name
    desc = episode.content[-1].value
    desc = re.sub('<.*?>', '\n', desc).replace('  ', ' ').replace('  ', ' ')  # replace <br> with \n, prevent weird space formatting i guess?

    desc = desc.replace('"', "'").strip()
    name = html_parser.unescape(name)
    title = html_parser.unescape(title)
    desc = html_parser.unescape(desc)
    nadd_obj = NADD(
        number=episode_num,
        title=title,
        reddit_title=reddit_title,
        monthstring=history.this_monthstring(),
        url=url,
        desc=desc,
    )
    return nadd_obj
コード例 #6
0
def post_gtd(gtd_obj, mod_info, testmode=False, depth=0):
    """

    :type testmode: bool
    :type gtd_obj: GTD
    :type mod_info: ModInfo
    """
    if depth > 3:
        send_email(subject="GTD SUBMISSION ERROR",
                   body="IDK",
                   to="*****@*****.**")
        return
    subreddit = 'jakeandamir'
    sub = mod_info.r.subreddit(subreddit)
    mod_info.login()

    if testmode:
        print("testmode - not actually submitting anything.")
        print("testmode - GTD found: ", gtd_obj.reddit_title)
        return

    try:
        if gtd_obj.ep_type in ['gtd', 'offdays', 'dayinthestrife']:
            #submission = sub.submit(gtd_obj.reddit_title, url=gtd_obj.url, flair_text='NEW GEOFFREY THE DUMBASS', flair_id='images')
            submission = sub.submit(gtd_obj.reddit_title, url=gtd_obj.url)
    except prawcore.exceptions.ServerError as e:
        print("Already submitted?")
        print(e)
        gtd_obj.reddit_url = 'TODO: Get the real submitted object'
        mod_info.past_history.add_gtd(gtd_obj)
        mod_info.past_history.write()
        return
    except Exception as e:
        print("Caught exception", e, "- recursing!")
        post_gtd(gtd_obj,
                 mod_info,
                 testmode=testmode or False,
                 depth=depth + 1)
        return
    submission.mod.approve()

    print("NEW GTD/OD!!! WOOOOO!!!!")
    print(gtd_obj.reddit_title)
    post_subreddit_comment(submission, gtd_obj)
    gtd_obj.reddit_url = submission.permalink
    submission.mod.sticky(bottom=True)
    #replace_top_sticky(sub, submission)
    submission.mod.distinguish()

    mod_info.past_history.add_gtd(gtd_obj)
    mod_info.past_history.write()
    print("Successfully submitted link! Time to celebrate.")
    return submission
コード例 #7
0
def post_jna(jna_obj, mod_info, testmode=False, depth=0):
    """

    :type testmode: bool
    :type jna_obj: JNA
    :type mod_info: ModInfo
    """
    if depth > 3:
        send_email(subject="JNA SUBMISSION ERROR",
                   body="IDK",
                   to="*****@*****.**")
        return
    subreddit = 'jakeandamir'
    sub = mod_info.r.subreddit(subreddit)
    mod_info.login()

    if testmode:
        print("testmode - not actually submitting anything.")
        print("testmode - jna found: ", jna_obj.reddit_title)
        return

    try:
        submission = sub.submit(jna_obj.reddit_title,
                                url=jna_obj.url,
                                resubmit=True)
    except prawcore.exceptions.ServerError as e:
        print("Already submitted?")
        print(e)
        jna_obj.reddit_url = 'TODO: Get the real submitted object'
        mod_info.past_history.add_jna(jna_obj)
        mod_info.past_history.write()
        return
    except Exception as e:
        print("Caught exception", e, "- recursing!")
        post_jna(jna_obj,
                 mod_info,
                 testmode=testmode or False,
                 depth=depth + 1)
        return
    submission.mod.approve()

    print("NEW JAKE AND AMIR!!! WOOOOO!!!!")
    print(jna_obj.reddit_title)
    post_subreddit_comment(submission, jna_obj)
    jna_obj.reddit_url = submission.permalink
    #submission.mod.sticky(bottom=True)
    submission.mod.distinguish()

    mod_info.past_history.add_jna(jna_obj)
    mod_info.past_history.write()
    print("Successfully submitted link! Time to celebrate.")
    return submission
コード例 #8
0
def post_gtd(gtd_obj, mod_info, testmode=False, depth=0):
    """

    :type testmode: bool
    :type gtd_obj: GTD
    :type mod_info: ModInfo
    """
    if depth > 3:
        send_email(subject="GTD SUBMISSION ERROR", body="IDK", to="*****@*****.**")
        return
    subreddit = 'jakeandamir'
    sub = mod_info.r.subreddit(subreddit)
    mod_info.login()

    if testmode:
        print("testmode - not actually submitting anything.")
        print("testmode - GTD found: ", gtd_obj.reddit_title)
        return

    try:
        if gtd_obj.ep_type == 'gtd':
            #submission = sub.submit(gtd_obj.reddit_title, url=gtd_obj.url, flair_text='NEW GEOFFREY THE DUMBASS', flair_id='images')
            submission = sub.submit(gtd_obj.reddit_title, url=gtd_obj.url)
        elif gtd_obj.ep_type == 'offdays':
            #submission = sub.submit(gtd_obj.reddit_title, url=gtd_obj.url, flair_text='NEW OFF DAYS', flair_id='images')
            submission = sub.submit(gtd_obj.reddit_title, url=gtd_obj.url)
    except prawcore.exceptions.ServerError as e:
        print("Already submitted?")
        print(e)
        gtd_obj.reddit_url = 'TODO: Get the real submitted object'
        mod_info.past_history.add_gtd(gtd_obj)
        mod_info.past_history.write()
        return
    except Exception as e:
        print("Caught exception", e, "- recursing!")
        post_gtd(gtd_obj, mod_info, testmode=testmode or False, depth=depth+1)
        return
    submission.mod.approve()

    print("NEW GTD/OD!!! WOOOOO!!!!")
    print(gtd_obj.reddit_title)
    post_subreddit_comment(submission, gtd_obj)
    gtd_obj.reddit_url = submission.permalink
    submission.mod.sticky(bottom=True)
    #replace_top_sticky(sub, submission)
    submission.mod.distinguish()

    mod_info.past_history.add_gtd(gtd_obj)
    mod_info.past_history.write()
    print("Successfully submitted link! Time to celebrate.")
    return submission
コード例 #9
0
def post_twins(twins_obj, mod_info, testmode=False, depth=0):
    """

    :type testmode: bool
    :type twins_obj: Twinnovation
    :type mod_info: ModInfo
    """
    if depth > 3:
        send_email(subject="twinnovation SUBMISSION ERROR",
                   body="IDK",
                   to="*****@*****.**")
        sys.exit()  # should I exit or just keep going???
    subreddit = 'twinnovation'
    sub = mod_info.r.subreddit(subreddit)
    mod_info.login()

    if testmode:
        print("testmode - not actually submitting anything.")
        print("testmode - twinnovation found: ", twins_obj.reddit_title)
        return

    try:
        submission = sub.submit(twins_obj.reddit_title, url=twins_obj.url)
    except prawcore.exceptions.ServerError as e:
        print("Already submitted?")
        print(e)
        twins_obj.reddit_url = 'TODO: Get the real submitted object'
        mod_info.past_history.add_twins_obj(twins_obj)
        mod_info.past_history.write()
        return
    except Exception as e:
        print("Caught exception", e, "- recursing!")
        post_twins(twins_obj,
                   mod_info,
                   testmode=testmode or False,
                   depth=depth + 1)
        return
    #sub.set_flair(submission, flair_text='NEW TWINNOVATION')
    submission.mod.approve()

    print("NEW twinnovation!!! WOOOOO!!!!")
    print(twins_obj.reddit_title)
    post_subreddit_comment(submission, twins_obj)
    twins_obj.reddit_url = submission.permalink
    set_bottom_sticky(sub, submission)

    mod_info.past_history.add_twins_obj(twins_obj)
    mod_info.past_history.write()
    print("Successfully submitted link! Time to celebrate.")
    return submission
コード例 #10
0
def post_twins(twins_obj, mod_info, testmode=False, depth=0):
    """

    :type testmode: bool
    :type twins_obj: Twinnovation
    :type mod_info: ModInfo
    """
    if depth > 3:
        send_email(subject="twinnovation SUBMISSION ERROR", body="IDK", to="*****@*****.**")
        sys.exit() # should I exit or just keep going???
    subreddit = 'twinnovation'
    sub = mod_info.r.subreddit(subreddit)
    mod_info.login()

    if testmode:
        print("testmode - not actually submitting anything.")
        print("testmode - twinnovation found: ", twins_obj.reddit_title)
        return

    try:
        submission = sub.submit(twins_obj.reddit_title, url=twins_obj.url)
    except prawcore.exceptions.ServerError as e:
        print("Already submitted?")
        print(e)
        twins_obj.reddit_url = 'TODO: Get the real submitted object'
        mod_info.past_history.add_twins_obj(twins_obj)
        mod_info.past_history.write()
        return
    except Exception as e:
        print("Caught exception", e, "- recursing!")
        post_twins(twins_obj, mod_info, testmode=testmode or False, depth=depth+1)
        return
    #sub.set_flair(submission, flair_text='NEW TWINNOVATION')
    submission.mod.approve()

    print("NEW twinnovation!!! WOOOOO!!!!")
    print(twins_obj.reddit_title)
    post_subreddit_comment(submission, twins_obj)
    twins_obj.reddit_url = submission.permalink
    set_bottom_sticky(sub, submission)

    mod_info.past_history.add_twins_obj(twins_obj)
    mod_info.past_history.write()
    print("Successfully submitted link! Time to celebrate.")
    return submission
コード例 #11
0
def post_iiwy(iiwy_obj, mod_info, testmode=False, depth=0):
    """

    :type testmode: bool
    :type iiwy_obj: IIWY
    :type mod_info: ModInfo
    """
    if depth > 3:
        send_email(subject="IIWY SUBMISSION ERROR", body="IDK", to="*****@*****.**")
        sys.exit() # should I exit or just keep going???
    subreddit = 'jakeandamir'
    sub = mod_info.r.subreddit(subreddit)
    mod_info.login()

    if testmode:
        print("testmode - not actually submitting anything.")
        print("testmode - IIWY found: ", iiwy_obj.reddit_title)
        return

    try:
        submission = sub.submit(iiwy_obj.reddit_title, url=iiwy_obj.url)
    except prawcore.exceptions.ServerError as e:
        print("Already submitted?")
        print(e)
        iiwy_obj.reddit_url = 'TODO: Get the real submitted object'
        mod_info.past_history.add_iiwy(iiwy_obj)
        mod_info.past_history.write()
        return
    except Exception as e:
        print("Caught exception", e, "- recursing!")
        post_iiwy(iiwy_obj, mod_info, testmode=testmode or False, depth=depth+1)
        return
    submission.mod.approve()

    print("NEW IIWY!!! WOOOOO!!!!")
    print(iiwy_obj.reddit_title)
    post_subreddit_comment(submission, iiwy_obj)
    iiwy_obj.reddit_url = submission.permalink
    replace_top_sticky(sub, submission)

    mod_info.past_history.add_iiwy(iiwy_obj)
    mod_info.past_history.write()
    print("Successfully submitted link! Time to celebrate.")
    return submission
コード例 #12
0
def main():
    global force_submit_iiwy, force_submit_twins, force_submit_nadd, force_submit_abbc, force_submit_rewatch, force_submit_gtd

    default_timeout = 20  # don't spam the servers :D

    foundlist = initialize_foundlist()

    next_episode = -1  # STARTS AT 1
    if len(sys.argv) > 1:
        next_episode = int(sys.argv[1])

    mod_info = ModInfo(next_episode, foundlist)

    if mod_info.next_episode > -1:
        print('Previous episode:', episodes[mod_info.next_episode - 2])
        print('Next episode to be posted:', episodes[mod_info.next_episode - 1])

    time.sleep(5)
    jjkae_tools.start_test_thread(email_if_failures=True)

    past_exception_string = None
    while True:
        try:
            timeout = get_timeout(default_timeout)

            iiwy_loop(mod_info, force_submit_iiwy)
            force_submit_iiwy = False  # Only do it once

            twins_loop(mod_info, force_submit_twins)
            force_submit_twins = False  # Only do it once

            nadd_loop(mod_info, force_submit_nadd)
            force_submit_nadd = False  # Only do it once

            abbc_loop(mod_info, force_submit_abbc)
            force_submit_abbc = False  # Only do it once

            # Don't do the rewatch or the monthly discussion
            #mod_loop(mod_info, force_submit_rewatch)
            #force_submit_rewatch = False  # Only do it once

            day = datetime.datetime.now().strftime('%A')
            if day == 'Thursday' and timeout == 1: # if we're in the zone of checking a lot for GTD
                gtd_loop(mod_info, force_submit_gtd)
                force_submit_gtd = False  # Only do it once
            else:
                if mod_info.i % 2 == 1:
                    # do it 50% of the time. This is because Youtube pretty heavily rate limits requests, so we can't be
                    # hitting the server 12 times a minute.
                    gtd_loop(mod_info, force_submit_gtd)
                    force_submit_gtd = False  # Only do it once

            if timeout != 0:
                time.sleep(timeout)

            jjkae_tools.printinfo(mod_info)
            mod_info.i += 1
        except (SystemExit, KeyboardInterrupt) as e:
            raise e
        except Exception as e:
            this_exception_string = "{} {}".format(type(e).__name__, str(e.args))
            print(this_exception_string)
            if past_exception_string != this_exception_string:
                jjkae_tools.send_email(subject="JAKE AND AMIR BOT ERROR", body=this_exception_string, to="*****@*****.**")
                print("SENT EMAIL!!!")
            print(this_exception_string)
            past_exception_string = this_exception_string
            time.sleep(1.0)
            pass