Skip to content

Instantly share code, notes, and snippets.

@tg12
Last active July 5, 2021 10:10
Show Gist options
  • Select an option

  • Save tg12/6344365e85f3d27d0f95fe906ec6a0ef to your computer and use it in GitHub Desktop.

Select an option

Save tg12/6344365e85f3d27d0f95fe906ec6a0ef to your computer and use it in GitHub Desktop.

Revisions

  1. tg12 revised this gist Jun 16, 2019. 1 changed file with 0 additions and 15 deletions.
    15 changes: 0 additions & 15 deletions reddit_crosspost_bot.py
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,3 @@
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
    # NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
    # DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
    # WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    # SOFTWARE.

    # Dont forget to tip your server!
    # Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
    # Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
    # Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
    # Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

    import time
    import praw
    import sqlite3
  2. tg12 created this gist Jun 15, 2019.
    100 changes: 100 additions & 0 deletions reddit_crosspost_bot.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,100 @@
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
    # NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
    # DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
    # WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    # SOFTWARE.

    # Dont forget to tip your server!
    # Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
    # Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
    # Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
    # Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

    import time
    import praw
    import sqlite3
    from random import randint
    from time import sleep

    # FROMSUB = "cyber" # The subreddit you want to take posts from
    # TOSUBS = ["cyber_security", "cyberlaws", "security", "privacy",
    # "netsec", "technology", "computerforensics", "ComputerSecurity"] # The
    # subreddits you want to post to

    FROMSUB = "brexit" # The subreddit you want to take posts from
    TOSUBS = ["ukpolitics", "unitedkingdom"] # The subreddits you want to post to

    r = praw.Reddit(client_id='',
    client_secret='',
    password='',
    user_agent="test2v_0.1",
    username='')

    print("Logged in as: " + str(r.user.me()))


    conn = sqlite3.connect('saved.db')
    c = conn.cursor()
    c.execute('CREATE TABLE IF NOT EXISTS posts (id text)')


    def alreadyExists(post):
    for thing in c.execute(
    '''SELECT * FROM posts WHERE id = '{}' '''.format(post.id)):
    return True
    return False


    def addPost(post):
    c.execute('''INSERT INTO posts VALUES ('{}') '''.format(post.id))


    def generateSelftext(post):
    if post.selftext == '':
    return None
    else:
    return post.selftext


    def generateLink(post):
    if post.selftext == '':
    return post.url
    else:
    return None


    def isPost(post):
    try:
    post.title
    return True
    except BaseException:
    return False


    def run():

    for post in [post for post in r.subreddit(FROMSUB).new(
    limit=20) if not alreadyExists(post) and isPost(post)]:
    for each in TOSUBS:
    print("[-]debug, " + str(each))
    try:
    print('Added post {}'.format(post.title))
    r.subreddit(each).submit(
    post.title +
    ' (x-post from /r/{})'.format(FROMSUB),
    url='https://www.reddit.com' +
    post.permalink,
    resubmit=True,
    send_replies=True)
    except BaseException as e:
    print(e)
    sleep(randint(540, 900))
    pass
    addPost(post)

    while True:
    run()
    conn.commit()