Esempio n. 1
0
def post_tweet(message):
    consumer_key = Configuration.get_instance().consumer_key
    consumer_secret = Configuration.get_instance().consumer_secret

    access_token_key = Configuration.get_instance().access_token_key
    access_token_secret = Configuration.get_instance().access_token_secret

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token_key, access_token_secret)

    api = tweepy.API(auth)

    return api.update_status(status=message)
Esempio n. 2
0
def post_tweet(message):
    consumer_key = Configuration.get_instance().consumer_key
    consumer_secret = Configuration.get_instance().consumer_secret

    access_token_key = Configuration.get_instance().access_token_key
    access_token_secret = Configuration.get_instance().access_token_secret

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token_key, access_token_secret)

    api = tweepy.API(auth)

    return api.update_status(status=message)
Esempio n. 3
0
    def get(self):

        if self.logged_in and self.current_user.admin:

            query = Query(kind="Tweet")

            tweets = query.fetch()

            tweets = reversed(sorted(tweets, key=lambda tweet: tweet.created))

            tweet_list = []

            for t in tweets:
                tweet_list.append({'message': t.message,
                                   'priority': t.priority,
                                   'created': t.created,
                                   'sent': t.sent,
                                   'id': t.key.id()})

            sent_tweets = [t for t in tweet_list if t['sent'] != None]

            template_values = {'total': len(tweet_list),
                               'sent_tweets': len(sent_tweets),
                               'unsent_tweets': len(tweet_list) - len(sent_tweets),
                               'frequency': Configuration.get_instance().tweet_frequency,
                               'tweets': tweet_list}

            path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/admin/tweets.html')
            self.response.out.write(template.render(path, template_values))

        else:
            self.redirect('/')
Esempio n. 4
0
    def get(self):

        try:
            tweet_frequency = Configuration.get_instance().tweet_frequency

            if randint(1, tweet_frequency) == 2:
                qry = Tweet.query(Tweet.sent == None).order(Tweet.priority, -Tweet.priority)

                found_tweets = qry.fetch(1)

                if found_tweets and len(found_tweets) > 0:
                    found_tweet = found_tweets[0]

                    post_tweet(found_tweet.message)

                    found_tweet.sent = datetime.datetime.now()

                    found_tweet.put()

                    logging.info("Tweet posted")
                else:
                    logging.info("No tweets to send")
            else:
                logging.info("Decided not to tweet, frequency " + str(tweet_frequency) + ".")

            self.response.status = 200
        except Exception as e:
            self.response.status = 500

            trace = traceback.format_exc()

            logging.error(e.message)
            logging.error(trace)
Esempio n. 5
0
    def get(self):

        try:
            tweet_frequency = Configuration.get_instance().tweet_frequency

            if randint(1, tweet_frequency) == 2:
                qry = Tweet.query(Tweet.sent == None).order(
                    Tweet.priority, -Tweet.priority)

                found_tweets = qry.fetch(1)

                if found_tweets and len(found_tweets) > 0:
                    found_tweet = found_tweets[0]

                    post_tweet(found_tweet.message)

                    found_tweet.sent = datetime.datetime.now()

                    found_tweet.put()

                    logging.info("Tweet posted")
                else:
                    logging.info("No tweets to send")
            else:
                logging.info("Decided not to tweet, frequency " +
                             str(tweet_frequency) + ".")

            self.response.status = 200
        except Exception as e:
            self.response.status = 500

            trace = traceback.format_exc()

            logging.error(e.message)
            logging.error(trace)
Esempio n. 6
0
    def get(self):

        if self.logged_in:
            template_values = {
                'user': {
                    'name': self.current_user.get_username()
                },
                'logout_url': self.get_logout()
            }
        else:
            template_values = {
                'user': None,
                'login_url': users.create_login_url('/report')
            }

        template_values['login_create_url'] = users.create_login_url('/create')
        template_values['debug_login'] = Configuration.get_instance(
        ).debug_login
        template_values['web_debug'] = Configuration.get_instance().web_debug

        path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'),
                            '../templates/home.html')
        self.response.out.write(template.render(path, template_values))
Esempio n. 7
0
    def show_main(self, user):

        response = {}

        attacks = user.get_attacks_as_dict()
        response['data'] = simplejson.dumps(generate_statistics_from_events(attacks))

        response['web_debug'] = Configuration.get_instance().web_debug
        response['share_report'] = user.share_report_key
        response['share_report_and_list'] = user.share_report_and_list_key
        response['logout_url'] = self.get_logout()
        response['show_logout'] = True
        response['show_add'] = True
        response['show_options'] = True
        response['show_list'] = True
        response['user'] = user

        path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/main.html')
        self.response.out.write(template.render(path, response))
Esempio n. 8
0
    def get(self):

        events = self.get_example_attacks()

        response = generate_statistics_from_events(events)

        response['web_debug'] = Configuration.get_instance().web_debug
        response['show_logout'] = False
        response['share_report'] = "example_report"
        response['share_report_and_list'] = "example_report_and_list"
        response['show_add'] = True
        response['show_options'] = True
        response['show_list'] = True
        response['example'] = True
        response['user'] = {'name': 'Example User', 'provider_name': 'Google+'}

        response['data'] = simplejson.dumps(response)

        path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/main.html')
        self.response.out.write(template.render(path, response))
Esempio n. 9
0
    def show_main(self, user):

        response = {}

        attacks = user.get_attacks_as_dict()
        response['data'] = simplejson.dumps(
            generate_statistics_from_events(attacks))

        response['web_debug'] = Configuration.get_instance().web_debug
        response['share_report'] = user.share_report_key
        response['share_report_and_list'] = user.share_report_and_list_key
        response['logout_url'] = self.get_logout()
        response['show_logout'] = True
        response['show_add'] = True
        response['show_options'] = True
        response['show_list'] = True
        response['user'] = user

        path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'),
                            '../../templates/main.html')
        self.response.out.write(template.render(path, response))
Esempio n. 10
0
    def get(self):

        events = self.get_example_attacks()

        response = generate_statistics_from_events(events)

        response['web_debug'] = Configuration.get_instance().web_debug
        response['show_logout'] = False
        response['share_report'] = "example_report"
        response['share_report_and_list'] = "example_report_and_list"
        response['show_add'] = True
        response['show_options'] = True
        response['show_list'] = True
        response['example'] = True
        response['user'] = {'name': 'Example User', 'provider_name': 'Google+'}

        response['data'] = simplejson.dumps(response)

        path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'),
                            '../../templates/main.html')
        self.response.out.write(template.render(path, response))
Esempio n. 11
0
    def get(self):

        if self.logged_in and self.current_user.admin:

            query = Query(kind="Tweet")

            tweets = query.fetch()

            tweets = reversed(sorted(tweets, key=lambda tweet: tweet.created))

            tweet_list = []

            for t in tweets:
                tweet_list.append({
                    'message': t.message,
                    'priority': t.priority,
                    'created': t.created,
                    'sent': t.sent,
                    'id': t.key.id()
                })

            sent_tweets = [t for t in tweet_list if t['sent'] != None]

            template_values = {
                'total': len(tweet_list),
                'sent_tweets': len(sent_tweets),
                'unsent_tweets': len(tweet_list) - len(sent_tweets),
                'frequency': Configuration.get_instance().tweet_frequency,
                'tweets': tweet_list
            }

            path = os.path.join(
                os.path.join(os.path.dirname(__file__), 'html'),
                '../../templates/admin/tweets.html')
            self.response.out.write(template.render(path, template_values))

        else:
            self.redirect('/')
Esempio n. 12
0
    def get(self):

        matches = re.match(r"/shared/(?P<key>[0-9a-z_]+)/.*",
                           self.request.path)

        if matches:
            shared_link = matches.group("key")

            response = {}
            attacks = None

            if len(shared_link) == 7:
                # Report with List
                acc = User.get_account_from_share_link_report_and_list(
                    shared_link)

                response['show_list'] = True

                attacks = acc.get_attacks_as_dict()

            if len(shared_link) == 8:
                # Report only
                acc = User.get_account_from_share_link_report_only(shared_link)

                response['show_list'] = False

                attacks = acc.get_attacks_as_dict()

            if shared_link == "example_report":
                response['show_list'] = False

                attacks = Example.get_example_attacks()

            if shared_link == "example_report_and_list":
                response['show_list'] = True

                attacks = Example.get_example_attacks()

            if attacks is not None:
                if len(attacks) > 0:
                    response['data'] = simplejson.dumps(
                        generate_statistics_from_events(attacks))
                else:
                    response['data'] = {}

                response['show_logout'] = False
                response['show_add'] = False
                response['show_options'] = False
                response['shared'] = True
                response['web_debug'] = Configuration.get_instance().web_debug

                path = os.path.join(
                    os.path.join(os.path.dirname(__file__), 'html'),
                    '../../templates/main.html')
                self.response.out.write(template.render(path, response))
            else:
                template_values = {
                    'status': '404 - Not found',
                    'title': 'What a headache!',
                    'message':
                    "Sorry, we couldn't find what you're looking for."
                }

                self.response.status = 404
                path = os.path.join(
                    os.path.join(os.path.dirname(__file__), 'html'),
                    '../../templates/error.html')
                self.response.out.write(template.render(path, template_values))
        else:
            template_values = {
                'status': '404 - Not found',
                'title': 'What a headache!',
                'message': "Sorry, we couldn't find what you're looking for."
            }

            self.response.status = 404
            path = os.path.join(
                os.path.join(os.path.dirname(__file__), 'html'),
                '../../templates/error.html')
            self.response.out.write(template.render(path, template_values))
Esempio n. 13
0
    def get(self):

        matches = re.match(
                r"/shared/(?P<key>[0-9a-z_]+)/.*",
                self.request.path)

        if matches:
            shared_link = matches.group("key")

            response = {}
            attacks = None

            if len(shared_link) == 7:
                # Report with List
                acc = User.get_account_from_share_link_report_and_list(shared_link)

                response['show_list'] = True

                attacks = acc.get_attacks_as_dict()

            if len(shared_link) == 8:
                # Report only
                acc = User.get_account_from_share_link_report_only(shared_link)

                response['show_list'] = False

                attacks = acc.get_attacks_as_dict()

            if shared_link == "example_report":
                response['show_list'] = False

                attacks = Example.get_example_attacks()

            if shared_link == "example_report_and_list":
                response['show_list'] = True

                attacks = Example.get_example_attacks()

            if attacks is not None:
                if len(attacks) > 0:
                    response['data'] = simplejson.dumps(generate_statistics_from_events(attacks))
                else:
                    response['data'] = {}

                response['show_logout'] = False
                response['show_add'] = False
                response['show_options'] = False
                response['shared'] = True
                response['web_debug'] = Configuration.get_instance().web_debug

                path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/main.html')
                self.response.out.write(template.render(path, response))
            else:
                template_values = {'status': '404 - Not found',
                                   'title': 'What a headache!',
                                   'message': "Sorry, we couldn't find what you're looking for."}

                self.response.status = 404
                path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/error.html')
                self.response.out.write(template.render(path, template_values))
        else:
            template_values = {'status': '404 - Not found',
                               'title': 'What a headache!',
                               'message': "Sorry, we couldn't find what you're looking for."}

            self.response.status = 404
            path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/error.html')
            self.response.out.write(template.render(path, template_values))