コード例 #1
0
ファイル: main.py プロジェクト: hasadna/notification-center
 def get(self):
     for src in NotificationSource.query():
         logging.log(logging.INFO, "src=%s" % src.url)
         try:
             self.handle_single_source(src)
         except Exception,e:
             logging.log(logging.ERROR, "src=%s, err=%s" % (src.url,e))
コード例 #2
0
ファイル: main.py プロジェクト: hasadna/notification-center
    def _handle(self,url,tags,latlon):
        self._set_response_headers()

        user = users.get_current_user()

        if not user:
            response = { 'success': False, 'login': self._loginURL() }
        else:
            response = { 'success': False }
            if tags is not None:
                tags = tags.split(',')
            else:
                tags = []

            tags = [x for x in tags if len(x) > 0]

            src = NotificationSource.query( NotificationSource.url == url ).fetch(1)
            if len(src) == 1:
                src = src[0]
                conditions = [ Subscription.user == user,
                               Subscription.source == src.key,
                               Subscription.latlon == latlon ]
                if len(tags) > 0:
                  conditions.append( ndb.AND(*[Subscription.tags == tag for tag in tags]) )

                subscription = Subscription.query( *conditions ).fetch(1)
                if len(subscription) == 1:
                  subscription = subscription[0]
                  response = { 'success': True, 'id': subscription.key.urlsafe() }

        return json.dumps(response)
コード例 #3
0
 def get(self):
     for src in NotificationSource.query():
         logging.log(logging.INFO, "src=%s" % src.url)
         try:
             self.handle_single_source(src)
         except Exception, e:
             logging.log(logging.ERROR, "src=%s, err=%s" % (src.url, e))
コード例 #4
0
    def _handle(self, url, tags, latlon, radius, period):
        self._set_response_headers()

        user = users.get_current_user()

        if not user:
            response = {'success': False, 'login': self._loginURL()}
        else:
            try:
                period = int(period)
            except:
                period = 86400
            try:
                radius = int(radius)
            except:
                radius = None

            if tags is not None:
                tags = tags.split(',')
            else:
                tags = []

            tags = [x for x in tags if len(x) > 0]

            src = NotificationSource.query(
                NotificationSource.url == url).fetch(1)
            if len(src) == 1:
                src = src[0]
            else:
                src = NotificationSource(url=url)
                ndb.put_multi([src])

            conditions = [
                Subscription.user == user, Subscription.source == src.key,
                Subscription.latlon == latlon, Subscription.radius == radius
            ]
            if len(tags) > 0:
                conditions.append(
                    ndb.AND(*[Subscription.tags == tag for tag in tags]))

            subscription = Subscription.query(*conditions).fetch(1)
            if len(subscription) == 1:
                subscription = subscription[0]
                subscription.period = period
            else:
                subscription = Subscription(user=user,
                                            source=src.key,
                                            tags=tags,
                                            latlon=latlon,
                                            radius=radius,
                                            period=period,
                                            next_poll=datetime.datetime.now(),
                                            last_read=datetime.datetime.now() -
                                            datetime.timedelta(hours=3))
            ndb.put_multi([subscription])
            response = {'success': True, 'id': subscription.key.urlsafe()}

        return json.dumps(response)
コード例 #5
0
ファイル: main.py プロジェクト: hasadna/notification-center
    def _handle(self,url,tags,latlon,radius,period):
        self._set_response_headers()

        user = users.get_current_user()

        if not user:
            response = { 'success': False, 'login': self._loginURL() }
        else:
            try:
                period = int(period)
            except:
                period = 86400
            try:
                radius = int(radius)
            except:
                radius = None

            if tags is not None:
                tags = tags.split(',')
            else:
                tags = []

            tags = [x for x in tags if len(x) > 0]

            src = NotificationSource.query( NotificationSource.url == url ).fetch(1)
            if len(src) == 1:
                src = src[0]
            else:
                src = NotificationSource( url = url )
                ndb.put_multi([src])

            conditions = [ Subscription.user == user,
                           Subscription.source == src.key,
                           Subscription.latlon == latlon,
                           Subscription.radius == radius ]
            if len(tags) > 0:
                conditions.append( ndb.AND(*[Subscription.tags == tag for tag in tags]) )

            subscription = Subscription.query( *conditions ).fetch(1)
            if len(subscription) == 1:
                subscription = subscription[0]
                subscription.period = period
            else:
                subscription = Subscription( user = user, source = src.key,
                                             tags = tags, latlon = latlon, radius = radius, period = period,
                                             next_poll=datetime.datetime.now(),
                                             last_read=datetime.datetime.now() - datetime.timedelta(hours=3) )
            ndb.put_multi([subscription])
            response = { 'success': True, 'id': subscription.key.urlsafe() }

        return json.dumps(response)
コード例 #6
0
ファイル: main.py プロジェクト: alonisser/notification-center
    def get(self):
        for src in NotificationSource.query():
            logging.log(logging.INFO, "src=%s" % src.url)
            url = src.url

            try:
                data = urlfetch.fetch(url)
            except:
                logging.log(logging.WARN, "Failed to fetch url %s" % url)
                continue
            feed = feedparser.parse(data.content)

            if feed.feed.title != src.title:
                src.title = feed.feed.title
                ndb.put_multi([src])

            maxpublished = datetime.datetime.fromtimestamp(0)
            logging.log(logging.INFO, "#entries=%s" % len(feed.entries))
            for entry in feed.entries:
                try:
                    entry.published_parsed = datetime.datetime(*entry.published_parsed[:6])
                    if maxpublished is None:
                        maxpublished = entry.published_parsed
                    else:
                        maxpublished = max(maxpublished,entry.published_parsed)
                except:
                    entry.published_parsed = None

                if hasattr(entry,'pkw_tags'):
                    entry.pkw_tags = set(entry.pkw_tags.split(','))
                else:
                    entry.pkw_tags = None
            logging.log(logging.INFO, "#maxpublished=%r" % maxpublished)

            if maxpublished is None:
                logging.log(logging.WARN, "Could not get published date for feed %s" % url)
                continue

            now = datetime.datetime.now()
            subscriptions = Subscription.query( Subscription.next_poll < now,
                                                Subscription.source == src.key )

            for subscription in subscriptions:
                logging.log(logging.DEBUG, "subscription=%r" % subscription)
                self.send_mail( subscription, feed, maxpublished )
コード例 #7
0
    def _handle(self, url, tags, latlon):
        self._set_response_headers()

        user = users.get_current_user()

        if not user:
            response = {'success': False, 'login': self._loginURL()}
        else:
            response = {'success': False}
            if tags is not None:
                tags = tags.split(',')
            else:
                tags = []

            tags = [x for x in tags if len(x) > 0]

            src = NotificationSource.query(
                NotificationSource.url == url).fetch(1)
            if len(src) == 1:
                src = src[0]
                conditions = [
                    Subscription.user == user, Subscription.source == src.key,
                    Subscription.latlon == latlon
                ]
                if len(tags) > 0:
                    conditions.append(
                        ndb.AND(*[Subscription.tags == tag for tag in tags]))

                subscription = Subscription.query(*conditions).fetch(1)
                if len(subscription) == 1:
                    subscription = subscription[0]
                    response = {
                        'success': True,
                        'id': subscription.key.urlsafe()
                    }

        return json.dumps(response)