def makepost():
    if request.method == "GET":
        if session.get('user') == None:
            return redirect("/login")
        else:
            return render_template("/makepost.html", current_user = session.get('user'))
    else:
        form = request.form
        database.addPost(form.get("title"), form.get("paragraph_text"), session['user'])
        return redirect("/")
Exemple #2
0
def publish_post():
    if request.method == 'POST':
        '''create new post'''
        data = request.get_json()
        data["FavoritesCount"] = 0
        lat = data.pop("lat")
        lng = data.pop("lng")
        database.addPost(data, lat, lng)
        print("created new entry in database")
        resp = jsonify(success=True)
        resp.status_code = 200
        return resp
Exemple #3
0
    def findNewPosts(self):
        subreddit = reddit.subreddit(self.subSettings[0])
        top = False
        hot = False
        new = True
        limitVal = self.subSettings[6]
        while True:
            try:
                post = 0
                # then get 1000 posts from new of the subreddit
                for submission in subreddit.new(limit=limitVal):
                    while True:
                        if not self.q.empty():
                            try:
                                x = self.q.queue[0]
                            except IndexError as e:
                                if 'deque index out of range' not in str(e):
                                    raise IndexError(e)
                            if x is not None and x is 'doneRunningHot':
                                post += 1
                                result = database.isLogged(
                                    submission.url,
                                    submission.media,
                                    submission.selftext,
                                    submission.permalink,
                                    submission.created_utc,
                                    top,
                                    hot,
                                    new,
                                    self.subSettings,
                                    reddit,
                                )
                                if result != [
                                    ['delete', -1, -1, -1, -1, -1]
                                ] and (result == [] or
                                       submission.created_utc != result[0][2]):
                                    rows.append(
                                        database.addPost(
                                            submission.created_utc,
                                            submission.url,
                                            submission.media,
                                            submission.permalink,
                                            submission.selftext,
                                            submission.author,
                                            submission.title,
                                            top,
                                            hot,
                                            new,
                                            self.subSettings[0],
                                        ))
                                    print('{} --> Added {}'.format(
                                        post,
                                        submission.permalink,
                                    ))

                                if result != [] and result != [[
                                        'delete', -1, -1, -1, -1, -1
                                ]]:
                                    print('reported')
                                    # report and make a comment
                                    submission.report('REPOST ALERT')
                                    cntr = 0
                                    table = ''
                                    for i in result:
                                        table = '{}{}|[{}](https://reddit.com{})|{}|{}%|{}\n'.format(
                                            table,
                                            str(cntr),
                                            i[5],
                                            i[0],
                                            i[1],
                                            str(i[3]),
                                            i[4],
                                        )
                                        cntr += 1
                                    fullText = 'I have detected that this may be a repost: \n'+ \
                                        '\nNum|Post|Date|Match|Author\n:--:|:--:|:--:|:--:|:--:\n{}'.format(table) + \
                                        '\n*Beep Boop* I am a bot | [Source](https://github.com/xXAligatorXx/repostChecker)' + \
                                        '| Contact u/XXAligatorXx for inquiries | The bot will delete its message at -2 score'
                                    doThis = True
                                    while doThis:
                                        try:
                                            submission.reply(fullText)
                                            doThis = False
                                        except:
                                            doThis = True
                                with self.q.mutex:
                                    self.q.queue.clear()
                                self.q.put('doneRunningNew')
                                break

                limitVal = 10
            except Exception as e:
                print(traceback.format_exc())
                if '503' in str(e):
                    print('503 from server')
                else:
                    f = open('errs.txt', 'a')
                    f.write(str(traceback.format_exc()))
            # Call the execute many after all posts have been added
            # need a way to calculate when all posts have been gathered and only then
            # execute this line once
            print('rows: ' + str(rows))
            conn = sqlite3.connect('PostsRepostBotTest.db')
            c = conn.cursor()
            c.executemany(
                "INSERT INTO Posts (Date, Content, Url, Location, Author, Title) VALUES (?, ?, ?, ?, ?, ?)",
                rows)
            conn.commit()
            c.close()
Exemple #4
0
    def findTopPosts(self):
        subreddit = reddit.subreddit(self.subSettings[0])
        print(self.subSettings)
        top = True
        hot = False
        new = False
        firstTime = True
        limitVal = self.subSettings[4]
        print('Starting searching...')
        while True:
            try:
                post = 0
                top = False
                hot = True
                # first get 50 posts from the top of the subreddit
                for submission in subreddit.top('all', limit=limitVal):
                    while True:
                        if (not self.q.empty()) or firstTime:
                            try:
                                x = self.q.queue[0]
                            except IndexError as e:
                                if 'deque index out of range' not in str(e):
                                    raise IndexError(e)
                            if firstTime or (x is not None
                                             and x is 'doneRunningNew'):
                                firstTime = False
                                top = True
                                hot = False
                                post += 1
                                result = database.isLogged(
                                    submission.url,
                                    submission.media,
                                    submission.selftext,
                                    submission.permalink,
                                    submission.created_utc,
                                    top,
                                    hot,
                                    new,
                                    self.subSettings,
                                    reddit,
                                )

                                if result != [
                                    ['delete', -1, -1, -1, -1, -1]
                                ] and (result == [] or
                                       submission.created_utc != result[0][2]):
                                    rows.append(
                                        database.addPost(
                                            submission.created_utc,
                                            submission.url,
                                            submission.media,
                                            submission.permalink,
                                            submission.selftext,
                                            submission.author,
                                            submission.title,
                                            top,
                                            hot,
                                            new,
                                            self.subSettings[0],
                                        ))
                                    print('{} --> Added {}'.format(
                                        post,
                                        submission.permalink,
                                    ))
                                with self.q.mutex:
                                    self.q.queue.clear()
                                self.q.put('doneRunningTop')

                            break

            except Exception as e:
                print(traceback.format_exc())
                if '503' in str(e):
                    print('503 from server')
                else:
                    f = open('errs.txt', 'a')
                    f.write(str(traceback.format_exc()))
Exemple #5
0
    def findHotPosts(self):
        subreddit = reddit.subreddit(self.subSettings[0])
        top = False
        hot = True
        new = False
        limitVal = self.subSettings[5]
        while True:
            try:
                post = 0
                # then get 50 posts from trending of the subreddit
                for submission in subreddit.hot(limit=limitVal):
                    while True:
                        if not self.q.empty():
                            try:
                                x = self.q.queue[0]
                            except IndexError as e:
                                if 'deque index out of range' not in str(e):
                                    raise IndexError(e)
                            if x is not None and x is 'doneRunningTop':
                                post += 1
                                result = database.isLogged(
                                    submission.url,
                                    submission.media,
                                    submission.selftext,
                                    submission.permalink,
                                    submission.created_utc,
                                    top,
                                    hot,
                                    new,
                                    self.subSettings,
                                    reddit,
                                )
                                if result != [
                                    ['delete', -1, -1, -1, -1, -1]
                                ] and (result == [] or
                                       submission.created_utc != result[0][2]):
                                    rows.append(
                                        database.addPost(
                                            submission.created_utc,
                                            submission.url,
                                            submission.media,
                                            submission.permalink,
                                            submission.selftext,
                                            submission.author,
                                            submission.title,
                                            top,
                                            hot,
                                            new,
                                            self.subSettings[0],
                                        ))
                                    print('{} --> Added {}'.format(
                                        post,
                                        submission.permalink,
                                    ))
                                with self.q.mutex:
                                    self.q.queue.clear()
                                self.q.put('doneRunningHot')
                                # Call the execute many after all posts have been added
                                #exec_many()
                                break

            except Exception as e:
                print(traceback.format_exc())
                if '503' in str(e):
                    print('503 from server')
                else:
                    f = open('errs.txt', 'a')
                    f.write(str(traceback.format_exc()))