Beispiel #1
0
def post_table_submission(submission, table, tt, dry_run=False, cb=None):
    msg = StringIO()
    verified = verify_ama(submission)
    linesep(
        table,
        file=msg,
        limit=38000,
        intro="""\
**Verified?** *(This bot cannot verify AMAs just yet)*

**Date:** """ + datetime.utcfromtimestamp(submission.created_utc).strftime('%Y-%m-%d')
+ "\n\n"
+ "**[Link to submission]({0})** ".format(tt.get_parent_url(submission.subreddit.display_name))
+ (
    '(*Has self-text*)'
    if hasattr(submission, 'selftext') and submission.selftext
    else '(*No self-text*)'
  )
+ "\n\n"
+ ("**[Link to my post]({0})**\n\n".format(tt.get_comment_url(submission.subreddit.display_name)) if tt.comment else '')
+ '\n'
        ,
        outro="\n\n" + last_updated(tt) + """

*This post was generated by a robot! Send all complaints to [epsy](/message/compose/?to=epsy).*
"""
        )
    if dry_run:
        print('Editing submission ' + tt.submission if tt.submission else 'New submission')
        print('--- BEGIN SUBMISSION ---')
        print(msg.getvalue().encode('utf-8'))
        print('--- END SUBMISSION ---')
    else:
        if tt.submission:
            edit('t3_' + tt.submission, msg.getvalue(), 'tabled')
            if cb:
                cb()
        else:
            def submit_to_tabled():
                link = submit(
                    'tabled',
                    submissiontitle(submission),
                    msg.getvalue())
                tt.submission = link
                tt.save()
                print("Posted table for {0}: {1}".format(
                    tt.get_parent_url(), tt.get_submission_url('tabled')
                    ))
                if cb:
                    cb()
            ratelimit(submit_to_tabled)
Beispiel #2
0
def post_table_comment(submission, table, tt, dry_run=False, cb=None):
    r = get_reddit()

    msg = StringIO()
    linesep(
        table,
        file=msg,
        limit=3000,
        intro="""\
""",
        outro="""\

""" +
    ('**[View the full table]({0})** on'.format(tt.get_submission_url('tabled')) if tt.submission
    else 'More tables at') + """ [/r/tabled](/r/tabled)! | """
    + last_updated(tt) + """

*This comment was generated by a robot! Send all complaints to [epsy](/message/compose/?to=epsy).*
"""
        )
    if dry_run:
        print('Editing comment ' + tt.comment if tt.comment else 'New comment')
        print('--- BEGIN COMMENT ---')
        print(msg.getvalue().encode('utf-8'))
        print('--- END COMMENT ---')
    else:
        if tt.comment:
            if tt.comment != '_':
                edit('t1_' + tt.comment, msg.getvalue())
        else:
            def make_comment():
                try:
                    response = submission.add_comment(
                        msg.getvalue()
                        )
                except errors.APIException as e:
                    if e.error_type == 'TOO_OLD':
                        tt.comment = '_'
                        tt.save()
                    else:
                        raise
                else:
                    tt.comment = response.id
                    tt.save()
                    print("Posted excerpt for {0}: {1}".format(
                        tt.get_parent_url(), tt.get_comment_url(submission.subreddit.display_name)
                        ))
                if cb:
                    cb()
            ratelimit(make_comment)