Ejemplo n.º 1
0
 def migrate(self, migration_id):
     migration = ndb.Key(urlsafe=migration_id).get()
     if migration and migration.key.kind() == Migration.kind:
         migration.update_subscriptions(self.user)
         self.redirect(gfw_url('my_gfw/subscriptions', {
             'migration_successful': 'true'}))
     else:
         self.write_error(404, 'Not found')
Ejemplo n.º 2
0
    def send_for_event(self, event):
        topic_result = self.subscription.run_analysis(event.begin, event.end)

        if topic_result.is_zero() == False:
            topic = Topic.get_by_id(event.topic)

            subscriptions_url = gfw_url('my_gfw/subscriptions', {})
            unsubscribe_url = '%s/v2/subscriptions/%s/unsubscribe' % \
                (runtime_config['APP_BASE_URL'], str(self.subscription.key.id()))
            begin = event.begin.strftime('%d %b %Y')
            end = event.end.strftime('%d %b %Y')

            url_params = self.subscription.params
            url_params['begin'] = event.begin
            url_params['end'] = event.end
            url_params['fit_to_geom'] = 'true'
            url_params['tab'] = 'analysis-tab'
            alert_link = map_url(self.subscription.params)

            email = self.subscription.email
            user_profile = self.subscription.user_id.get().get_profile()
            name = getattr(user_profile, 'name', email)

            template_params = {
                'selected_area': topic_result.area_name(),
                'alert_count': topic_result.formatted_value(),
                'alert_type': topic.description,
                'alert_date': begin + " to " + end,
                'alert_summary': summary_for_topic(topic),
                'alert_name': self.subscription.formatted_name(),
                'alert_link': alert_link,
                'unsubscribe_url': unsubscribe_url,
                'subscriptions_url': subscriptions_url
            }

            if topic.id == 'alerts/viirs':
                map_image = '%s/v2/subscriptions/%s/overview.png' % \
                (runtime_config['APP_BASE_URL'], str(self.subscription.key.id()))
                template_params['map_image'] = map_image
                urlfetch.fetch(map_image, method=urlfetch.GET)

                fire_alerts = topic_result.value()[1][:10]
                for alert in fire_alerts:
                    alert['acq_date'] = alert['acq_date'].split('T')[0]
                    alert['acq_time'] = alert['acq_time'][:2] + ':' + alert['acq_time'][2:] + ' UTC'
                    alert['latitude'] = "{0:.3f}".format(alert['latitude'])
                    alert['longitude'] = "{0:.3f}".format(alert['longitude'])

                template_params['fire_alerts'] = fire_alerts

            response = sparkpost.transmissions.send(
                recipients=[{'address': { 'email': email, 'name': name }}],
                template=template_for_topic(topic),
                substitution_data=template_params
            )

            logging.info("Send Subscription Email Result: %s" % response)
Ejemplo n.º 3
0
    def send(self):
        story_url = gfw_url('stories/%s' % self.story['id'], {})

        response = sparkpost.transmissions.send(
            recipients=runtime_config.get('wri_emails_stories'),
            template='new-story-wri',
            substitution_data={'story_url': story_url})

        logging.info("Send Story WRI Email Result: %s" % response)
Ejemplo n.º 4
0
 def dispatch(self):
     options_request = (self.request.method == "OPTIONS")
     self.user = self.request.user if hasattr(self.request, 'user') else None
     if not options_request and self.user is None:
         params = self.app.router.match(self.request)[-1]
         self.redirect(gfw_url('my_gfw/subscriptions', {
             'migration_id': params['migration_id']}))
     else:
         webapp2.RequestHandler.dispatch(self)
Ejemplo n.º 5
0
    def unsubscribe(self, subscription_id):
        subscription = Subscription.get_by_id(int(subscription_id))

        if subscription:
            subscription.unsubscribe()
            self.redirect(gfw_url('my_gfw/subscriptions',
                {'unsubscribed': 'true'}))
        else:
            self.write_error(404, 'Not found')
Ejemplo n.º 6
0
    def send_confirmation(self, subscription_id):
        subscription = Subscription.get_by_id(int(subscription_id))

        if subscription:
            subscription.unconfirm();
            self.redirect(gfw_url('my_gfw/subscriptions',
                {'subscription_confirmation_sent': 'true'}))
        else:
            self.write_error(404, 'Not Found')
Ejemplo n.º 7
0
 def migrate(self, migration_id):
     migration = ndb.Key(urlsafe=migration_id).get()
     if migration and migration.key.kind() == Migration.kind:
         migration.update_subscriptions(self.user)
         self.redirect(
             gfw_url('my_gfw/subscriptions',
                     {'migration_successful': 'true'}))
     else:
         self.write_error(404, 'Not found')
Ejemplo n.º 8
0
    def unsubscribe(self, subscription_id):
        subscription = Subscription.get_by_id(int(subscription_id))

        if subscription:
            subscription.unsubscribe()
            self.redirect(gfw_url('my_gfw/subscriptions',
                {'unsubscribed': 'true'}))
        else:
            self.write_error(404, 'Not found')
Ejemplo n.º 9
0
    def send_confirmation(self, subscription_id):
        subscription = Subscription.get_by_id(int(subscription_id))

        if subscription:
            subscription.unconfirm();
            self.redirect(gfw_url('my_gfw/subscriptions',
                {'subscription_confirmation_sent': 'true'}))
        else:
            self.write_error(404, 'Not Found')
Ejemplo n.º 10
0
 def dispatch(self):
     options_request = (self.request.method == "OPTIONS")
     self.user = self.request.user if hasattr(self.request,
                                              'user') else None
     if not options_request and self.user is None:
         params = self.app.router.match(self.request)[-1]
         self.redirect(
             gfw_url('my_gfw/subscriptions',
                     {'migration_id': params['migration_id']}))
     else:
         webapp2.RequestHandler.dispatch(self)
Ejemplo n.º 11
0
    def send(self):
        story_url = gfw_url('stories/%s' % self.story['id'], {})

        response = sparkpost.transmissions.send(
            recipients=runtime_config.get('wri_emails_stories'),
            template='new-story-wri',
            substitution_data={
                'story_url': story_url
            }
        )

        logging.info("Send Story WRI Email Result: %s" % response)
Ejemplo n.º 12
0
    def send(self):
        story_url = gfw_url('stories/%s' % self.story['id'], {})
        name = self.story['name']
        email = self.story['email']

        response = sparkpost.transmissions.send(
            recipients=[{'address': { 'email': email, 'name': name }}],
            template='new-story',
            substitution_data={
                'name': name,
                'story_url': story_url
            }
        )

        logging.info("Send Story Email Result: %s" % response)
Ejemplo n.º 13
0
    def send(self):
        story_url = gfw_url('stories/%s' % self.story['id'], {})
        name = self.story['name']
        email = self.story['email']

        response = sparkpost.transmissions.send(recipients=[{
            'address': {
                'email': email,
                'name': name
            }
        }],
                                                template='new-story',
                                                substitution_data={
                                                    'name': name,
                                                    'story_url': story_url
                                                })

        logging.info("Send Story Email Result: %s" % response)
Ejemplo n.º 14
0
 def confirm(self, subscription_id):
     if Subscription.confirm_by_id(subscription_id):
         self.redirect(gfw_url('my_gfw/subscriptions',
             {'subscription_confirmed': 'true'}))
     else:
         self.write_error(404, 'Not Found')
Ejemplo n.º 15
0
 def confirm(self, subscription_id):
     if Subscription.confirm_by_id(subscription_id):
         self.redirect(gfw_url('my_gfw/subscriptions',
             {'subscription_confirmed': 'true'}))
     else:
         self.write_error(404, 'Not Found')