예제 #1
0
def ban(ill_fated):
    ban_message = textwrap.dedent("""
    Hear me and rejoice! You have had the great privilege of being saved by the great titan. 
    You may think this is suffering....no! It is salvation. The subreddit scales...tip toward balance 
    because of your sacrifice. Smile...for even in death, you have become children of Thanos!

    Join the others on /r/inthesoulworld

    ^(This action was performed by a bot.)
    ^(for feedback, bug reports or just to say thanks! The code is on )[^github](https://github.com/ArionMiles/InfinityGauntlet))
    """)

    ban_reason = "To bring balance to the sub"

    reddit = authenticate(user_agent, app_key, app_secret, username, password)
    for user in ill_fated:
        reddit.subreddit(subreddit).banned.add(user,
                                               ban_message=ban_message,
                                               ban_reason=ban_reason,
                                               duration=days_until_a4_releases)
        reddit.subreddit(subreddit).flair.set(user, 'perished')
        # reddit.subreddit('inthesoulworld').contributor.add(user)
        query = Users.__table__.update().where(
            and_(Users.username == user,
                 Users.saved == False)).values(saved=True)
        connection.execute(query)
        print(f"{user} was snapped out of existence.")
    connection.close()
예제 #2
0
def read_drinksdb():
    connect()
    from database import connection
    global drinks
    drinks = []

    cursor_drinks = connection.cursor()
    cursor_drinks.execute("SELECT name, category, volume, price FROM drink")
    rowsd = cursor_drinks.fetchall()

    for row in rowsd:
        drink = Drinks(row[0], row[1], row[2], row[3])
        drinks.append(drink)

    cursor_drinks.close()
    connection.close()
예제 #3
0
def read_peopledb():
    connect()
    from database import connection
    global rowsp, people
    people = []
    cursor_people = connection.cursor()

    cursor_people.execute("SELECT first_name, last_name, age FROM person")
    rowsp = cursor_people.fetchall()

    for row in rowsp:
        person = Person(row[0], row[1], row[2])
        people.append(person)

    cursor_people.close()
    connection.close()
예제 #4
0
    def enterval():
        connect()
        from database import connection
        value_first_name = new_first_name.get()
        value_surname = new_surname.get()
        value_age = new_age.get()
        
        cursor_people = connection.cursor()

        sql_person_command = "INSERT INTO person (first_name, last_name, age) VALUES (%s, %s, %s)"
        val_person = (value_first_name, value_surname, value_age)
        cursor_people.execute(sql_person_command, val_person)
        connection.commit()
        
        cursor_people.close()
        connection.close()
        new.destroy()
예제 #5
0
def scrape(reddit):
    print("Initializing database... (might take some time)")
    init_db()
    print("Database is setup successfully.")
    post_number = 1
    for submission in reddit.subreddit(subreddit).top(limit=SEARCH_LIMIT):
        print(f"Scraping contributors from thread (including all comments) number: {post_number}")
        authors = get_all_authors_from_submission(submission)
        if submission and submission.author and submission.author.name:
            authors.append(submission.author.name)
        unique_authors = list(set(authors))
        data = [{'username': unique_author, 'saved': False} for unique_author in unique_authors]
        query = Users.__table__.insert(prefixes=["OR REPLACE"])
        connection.execute(query, data)
        post_number += 1
    spare_authenticated_user()
    connection.close()
예제 #6
0
    def enterval():
        connect()
        from database import connection

        value_drink = new_drink.get()
        value_container = new_category.get()
        value_volume = new_volume.get()
        value_price = new_price.get()

        cursor_drinks = connection.cursor()

        sql_drink = "INSERT INTO drink (name, category, volume, price) VALUES (%s, %s, %s, %s)"
        val_drink = (value_drink, value_container, value_volume, value_price)
        cursor_drinks.execute(sql_drink, val_drink)
        connection.commit()
        cursor_drinks.close()
        connection.close()
        new.destroy()
예제 #7
0
    global total_authors
    total_authors = 0
    all_comments = get_all_nested_replies_from_comment_recursively(all_parent_comments)
    return all_comments


def get_all_nested_replies_from_comment_recursively(comments):
    all_comments = []
    for comment in comments:
        if isinstance(comment, Comment):
            if comment and comment.author and comment.author.name:
                global total_authors
                total_authors += 1
                if total_authors % 100 == 0:
                    print(f"Total authors extracted from this thread: {total_authors}")
                all_comments.append(comment.author.name)
        if isinstance(comment, MoreComments):
            all_comments.extend(get_all_nested_replies_from_comment_recursively(comment.comments()))
        if isinstance(comment, CommentForest):
            all_comments.extend(get_all_nested_replies_from_comment_recursively(comment.list()))
    return all_comments


if __name__ == '__main__':
    SEARCH_LIMIT = search_limit
    reddit = authenticate(user_agent, app_key, app_secret, username, password)
    try:
        scrape(reddit)
    except KeyboardInterrupt:
        connection.close()
예제 #8
0
def after_request(response):
    connection.close()
    return response