def remove_all_sub(house_name): house_list = House.query(House.name == house_name).fetch() house_key = house_list[0].key sub_list = Subscription.query(Subscription.house_key == house_key).fetch() for sub in sub_list: sub.key.delete() return
def get(self): user, logout = check_user(users.get_current_user()) if user: template_args = {'logout_url': users.create_logout_url('/')} subscription_list = list() more = True curs = None while more: s, curs, more = Subscription.query( ).fetch_page( 10, start_cursor=curs) for sitem in s: subscription_list.append(sitem) template_args['subscriptions'] = subscription_list users_list = list() more = True curs = None while more: u, curs, more = User.query( ).order( -User.when).fetch_page( 10, start_cursor=curs) for uitem in u: users_list.append(uitem) template_args['users'] = users_list template = JINJA_ENVIRONMENT.get_template('users.html') self.response.write(template.render(template_args)) else: self.redirect('/admin')
def locations_insert(self, location): """Insert a new location for the current user. Not part of the actual mirror API but used by the emulator. """ if location.id is not None: raise endpoints.BadRequestException("ID is not allowed in request body.") location.put() # Notify location subscriptions data = {} data["collection"] = "locations" data["itemId"] = "latest" operation = Operation.UPDATE data["operation"] = operation.name header = {"Content-type": "application/json"} query = Subscription.query().filter(Subscription.user == endpoints.get_current_user()) query = query.filter(Subscription.collection == "locations") query = query.filter(Subscription.operation == operation) for subscription in query.fetch(): data["userToken"] = subscription.userToken data["verifyToken"] = subscription.verifyToken req = urllib2.Request(subscription.callbackUrl, json.dumps(data), header) try: urllib2.urlopen(req) except: logging.error(sys.exc_info()[0]) return location
def locations_insert(self, location): """Insert a new location for the current user. Not part of the actual mirror API but used by the emulator. """ if location.id is not None: raise endpoints.BadRequestException("ID is not allowed in request body.") location.put() # Notify location subscriptions data = {} data["collection"] = "locations" data["itemId"] = "latest" operation = Operation.UPDATE data["operation"] = operation.name header = {"Content-type": "application/json"} query = Subscription.query().filter(Subscription.user == endpoints.get_current_user()) query = query.filter(Subscription.collection == "locations") query = query.filter(Subscription.operation == operation) for subscription in query.fetch(): data["userToken"] = subscription.userToken data["verifyToken"] = subscription.verifyToken req = urllib2.Request(subscription.callbackUrl, json.dumps(data), header) try: urllib2.urlopen(req) except: logging.error(sys.exc_info()[0]) return location
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)
def is_subscribed(name, pigeon_id): pigeon_key = ndb.Key(Pigeon, pigeon_id) stream_list = Stream.query(Stream.name == name).fetch() stream_key = stream_list[0].key sub_list = Subscription.query( Subscription.Pigeon_key == pigeon_key, Subscription.Stream_key == stream_key).fetch() return True if sub_list else False
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)
def handle_single_source(self, src): url = src.url try: data = urlfetch.fetch(url) except: logging.log(logging.WARN, "Failed to fetch url %s" % url) return feed = feedparser.parse(data.content) current_title = None try: current_title = src.title except: pass if hasattr(feed.feed, 'title'): if feed.feed.title != current_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 if hasattr(entry, 'pkw_score'): entry.pkw_score = float(entry.pkw_score) else: entry.pkw_score = 1 logging.log(logging.INFO, "#maxpublished=%r" % maxpublished) if maxpublished is None: logging.log(logging.WARN, "Could not get published date for feed %s" % url) return 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)
def get_num_per_day(user_id, house_name): pigeon_key = ndb.Key(Pigeon, user_id) house_list = House.query(House.name == house_name).fetch() house_key = house_list[0].key sub_list = Subscription.query(Subscription.pigeon_key == pigeon_key, Subscription.house_key == house_key).fetch() if sub_list: return sub_list[0].num_per_day else: return
def get_sub_stream(pigeon_id): pigeon_key = ndb.Key(Pigeon, pigeon_id) sub_list = Subscription.query( Subscription.Pigeon_key == pigeon_key).fetch() stream_list = [] for sub in sub_list: if sub.Stream_key.get(): stream_list.append(sub.Stream_key.get()) return sorted(map(_get_stream_dict, stream_list), key=lambda d: d['LastPictDate'])[::-1]
def delete_subscription(pigeon_id, name): pigeon_key = ndb.Key(Pigeon, pigeon_id) stream_list = Stream.query(Stream.name == name).fetch() stream_key = stream_list[0].key sub_list = Subscription.query( Subscription.Pigeon_key == pigeon_key, Subscription.Stream_key == stream_key).fetch() if sub_list: sub_list[0].key.delete() return
def is_subscribed(house_name, pigeon_id): pigeon_key = ndb.Key(Pigeon, pigeon_id) house_list = House.query(House.name == house_name).fetch() house_key = house_list[0].key sub_list = Subscription.query(Subscription.pigeon_key == pigeon_key, Subscription.house_key == house_key).fetch() if sub_list: return True else: return False
def handle_single_source(self,src): url = src.url try: data = urlfetch.fetch(url) except: logging.log(logging.WARN, "Failed to fetch url %s" % url) return feed = feedparser.parse(data.content) current_title = None try: current_title = src.title except: pass if hasattr(feed.feed,'title'): if feed.feed.title != current_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 if hasattr(entry,'pkw_score'): entry.pkw_score = float(entry.pkw_score) else: entry.pkw_score = 1 logging.log(logging.INFO, "#maxpublished=%r" % maxpublished) if maxpublished is None: logging.log(logging.WARN, "Could not get published date for feed %s" % url) return 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 )
def set_schedule(user_id, house_name, num_per_day): pigeon_key = ndb.Key(Pigeon, user_id) house_list = House.query(House.name == house_name).fetch() house_key = house_list[0].key sub_list = Subscription.query(Subscription.pigeon_key == pigeon_key, Subscription.house_key == house_key).fetch() if sub_list: sub_list[0].num_per_day = num_per_day sub_list[0].put() return else: return
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)
def get(self,slug): user, logout = check_user(users.get_current_user()) if user: page = Page.query(Page.slug == slug).fetch(1) template_args = {'logout_url': users.create_logout_url('/')} if page: page = page[0] template_args['new'] = False template_args['title'] = page.title template_args['text'] = process_text_admin(page.text) template_args['edit'] = page.text template_args['prev'] = nonize(page.prev) template_args['next'] = nonize(page.next) template_args['doc'] = nonize(page.doc) template_args['level'] = page.allowed template_args['startpages'] = set([s.startpage for s in Subscription.query().fetch(10)]) template_args['slug'] = page.slug template_args['author'] = user.nickname() else: template_args['new'] = True template_args['title'] = '' template_args['text'] = '' template_args['edit'] = '' template_args['prev'] = '' template_args['next'] = '' template_args['doc'] = '' template_args['level'] = 1 template_args['startpages'] = set([s.startpage for s in Subscription.query().fetch(10)]) template_args['slug'] = slug template_args['author'] = user.nickname() template = JINJA_ENVIRONMENT.get_template('content.html') self.response.write(template.render(template_args)) else: self.redirect('/admin')
def get(self): user, logout = check_user(users.get_current_user()) if user: u = [] more = True cursor = None while more: d, cursor, more = Subscription.query().order( -Subscription.when).fetch_page( 10, start_cursor=cursor) for ditem in d: u.append(ditem.to_dict()) self.response.out.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({'data':u}))
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 )
def delete_subscription(pigeon_id, house_name): pigeon_key = ndb.Key(Pigeon, pigeon_id) house_list = House.query(House.name == house_name).fetch() house = house_list[0] house.num_of_subed = house.num_of_subed - 1 house.put() house_key = house.key sublist = Subscription.query(Subscription.pigeon_key == pigeon_key, Subscription.house_key == house_key).fetch() if sublist: sub = sublist[0] sub.key.delete() card_list = _get_all_cards(house_name) for card in card_list: _delete_progress(pigeon_key, card.key) return else: return
def get_sub_house(pigeon_id): pigeon_key = ndb.Key(Pigeon, pigeon_id) sub_list = Subscription.query( Subscription.pigeon_key == pigeon_key).fetch() house_list = [] if sub_list: for sub in sub_list: house_list.append(sub.house_key.get()) return map( lambda s: { "house_name": s.name, "cover_url": s.cover_url, "category": s.category, "view": s.view, "num_of_subed": s.num_of_subed }, house_list) else: return house_list
def action_insert(self, action): """Perform an action on a timeline card for the current user. This isn't part of the actual Mirror API but necessary for the emulator to send actions to the subscribed services. Returns just a simple success message """ current_user = endpoints.get_current_user() if current_user is None: raise endpoints.UnauthorizedException("Authentication required.") # TODO: check if card exists and belongs to the user data = {} data["collection"] = action.collection data["operation"] = action.operation.name data["itemId"] = action.itemId data["value"] = action.value header = {"Content-type": "application/json"} query = ( Subscription.query() .filter(Subscription.user == current_user) .filter(Subscription.operation == action.operation) ) for subscription in query.fetch(): data["userToken"] = subscription.userToken data["verifyToken"] = subscription.verifyToken req = urllib2.Request(subscription.callbackUrl, json.dumps(data), header) try: urllib2.urlopen(req) except urllib2.URLError as e: logging.error(e) return ActionResponse(success=True)
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)
def action_insert(self, action): """Perform an action on a timeline card for the current user. This isn't part of the actual Mirror API but necessary for the emulator to send actions to the subscribed services. Returns just a simple success message """ current_user = endpoints.get_current_user() if current_user is None: raise endpoints.UnauthorizedException("Authentication required.") card = ndb.Key("TimelineItem", action.itemId).get() if card is None or card.user != current_user: raise endpoints.NotFoundException("Card not found.") data = None operation = None if action.action == UserAction.SHARE: operation = Operation.UPDATE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.SHARE.name}] if action.action == UserAction.REPLY or action.action == UserAction.REPLY_ALL: operation = Operation.INSERT data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.REPLY.name}] if action.action == UserAction.DELETE: operation = Operation.DELETE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.DELETE.name}] if action.action == UserAction.CUSTOM: operation = Operation.UPDATE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.CUSTOM.name, "payload": action.value}] if action.action == UserAction.LAUNCH: operation = Operation.INSERT data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.LAUNCH.name}] if data is not None and operation is not None: header = {"Content-type": "application/json"} query = Subscription.query().filter(Subscription.user == current_user) query = query.filter(Subscription.collection == "timeline") query = query.filter(Subscription.operation == operation) for subscription in query.fetch(): data["userToken"] = subscription.userToken data["verifyToken"] = subscription.verifyToken req = urllib2.Request(subscription.callbackUrl, json.dumps(data), header) try: urllib2.urlopen(req) except: logging.error(sys.exc_info()[0]) # Report back to Glass emulator channel.send_message(current_user.email(), json.dumps({"id": action.itemId})) return ActionResponse(success=True)
def timeline_delete(self, card): """Remove an existing card for the current user. This will set all properties except the ID to None and set isDeleted to true """ if not card.from_datastore or card.user != endpoints.get_current_user(): raise endpoints.NotFoundException("Contact not found.") if card.isDeleted: raise endpoints.NotFoundException("Card has been deleted") # Delete attachments if card.attachments is not None: for att in card.attachments: try: gcs.delete(bucket + "/" + att.id) except gcs.NotFoundError: pass card.attachments = [] card.bundleId = None card.canonicalUrl = None card.created = None card.creator = None card.displayTime = None card.html = None card.inReplyTo = None card.isBundleCover = None card.isPinned = None card.menuItems = [] card.notification = None card.recipients = [] card.sourceItemId = None card.speakableType = None card.speakableText = None card.text = None card.title = None card.updated = None card.isDeleted = True card.put() # Notify Glass emulator channel.send_message(card.user.email(), json.dumps({"id": card.id})) # Notify timeline DELETE subscriptions data = {} data["collection"] = "timeline" data["itemId"] = card.id operation = Operation.DELETE data["operation"] = operation.name header = {"Content-type": "application/json"} query = Subscription.query().filter(Subscription.user == endpoints.get_current_user()) query = query.filter(Subscription.collection == "timeline") query = query.filter(Subscription.operation == operation) for subscription in query.fetch(): data["userToken"] = subscription.userToken data["verifyToken"] = subscription.verifyToken req = urllib2.Request(subscription.callbackUrl, json.dumps(data), header) try: urllib2.urlopen(req) except: logging.error(sys.exc_info()[0]) return card
def action_insert(self, action): """Perform an action on a timeline card for the current user. This isn't part of the actual Mirror API but necessary for the emulator to send actions to the subscribed services. Returns just a simple success message """ current_user = endpoints.get_current_user() if current_user is None: raise endpoints.UnauthorizedException('Authentication required.') # TODO: check if card exists and belongs to the user data = None operation = None if action.action == MenuAction.SHARE: operation = Operation.UPDATE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = ({"type": MenuAction.SHARE.name},) if action.action == MenuAction.REPLY or action.action == MenuAction.REPLY_ALL: operation = Operation.INSERT data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = ({"type": MenuAction.REPLY.name},) if action.action == MenuAction.DELETE: operation = Operation.DELETE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = ({"type": MenuAction.DELETE.name},) if action.action == MenuAction.CUSTOM: operation = Operation.UPDATE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = ({"type": MenuAction.DELETE.name, "payload": action.value},) if data is not None and operation is not None: header = {"Content-type": "application/json"} query = Subscription.query().filter(Subscription.user == current_user).filter(Subscription.operation == operation) for subscription in query.fetch(): data["userToken"] = subscription.userToken data["verifyToken"] = subscription.verifyToken req = urllib2.Request(subscription.callbackUrl, json.dumps(data), header) try: urllib2.urlopen(req) except urllib2.URLError as e: logging.error(e) return ActionResponse(success=True)
def action_insert(self, action): """Perform an action on a timeline card for the current user. This isn't part of the actual Mirror API but necessary for the emulator to send actions to the subscribed services. Returns just a simple success message """ current_user = endpoints.get_current_user() if current_user is None: raise endpoints.UnauthorizedException("Authentication required.") card = ndb.Key("TimelineItem", action.itemId).get() if card is None or card.user != current_user: raise endpoints.NotFoundException("Card not found.") data = None operation = None if action.action == UserAction.SHARE: operation = Operation.UPDATE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.SHARE.name}] if action.action == UserAction.REPLY or action.action == UserAction.REPLY_ALL: operation = Operation.INSERT data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.REPLY.name}] if action.action == UserAction.DELETE: operation = Operation.DELETE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.DELETE.name}] if action.action == UserAction.CUSTOM: operation = Operation.UPDATE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.CUSTOM.name, "payload": action.value}] if action.action == UserAction.LAUNCH: operation = Operation.UPDATE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = [{"type": UserAction.LAUNCH.name}] if data is not None and operation is not None: header = {"Content-type": "application/json"} query = Subscription.query().filter(Subscription.user == current_user) query = query.filter(Subscription.collection == "timeline") query = query.filter(Subscription.operation == operation) for subscription in query.fetch(): data["userToken"] = subscription.userToken data["verifyToken"] = subscription.verifyToken req = urllib2.Request(subscription.callbackUrl, json.dumps(data), header) try: urllib2.urlopen(req) except: logging.error(sys.exc_info()[0]) # Report back to Glass emulator channel.send_message(current_user.email(), json.dumps({"id": action.itemId})) return ActionResponse(success=True)
def action_insert(self, action): """Perform an action on a timeline card for the current user. This isn't part of the actual Mirror API but necessary for the emulator to send actions to the subscribed services. Returns just a simple success message """ current_user = endpoints.get_current_user() if current_user is None: raise endpoints.UnauthorizedException('Authentication required.') # TODO: check if card exists and belongs to the user data = None operation = None if action.action == MenuAction.SHARE: operation = Operation.UPDATE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = ({"type": MenuAction.SHARE.name}, ) if action.action == MenuAction.REPLY or action.action == MenuAction.REPLY_ALL: operation = Operation.INSERT data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = ({"type": MenuAction.REPLY.name}, ) if action.action == MenuAction.DELETE: operation = Operation.DELETE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = ({"type": MenuAction.DELETE.name}, ) if action.action == MenuAction.CUSTOM: operation = Operation.UPDATE data = {} data["collection"] = "timeline" data["itemId"] = action.itemId data["operation"] = operation.name data["userActions"] = ({ "type": MenuAction.DELETE.name, "payload": action.value }, ) if data is not None and operation is not None: header = {"Content-type": "application/json"} query = Subscription.query().filter( Subscription.user == current_user).filter( Subscription.operation == operation) for subscription in query.fetch(): data["userToken"] = subscription.userToken data["verifyToken"] = subscription.verifyToken req = urllib2.Request(subscription.callbackUrl, json.dumps(data), header) try: urllib2.urlopen(req) except urllib2.URLError as e: logging.error(e) return ActionResponse(success=True)
def timeline_delete(self, card): """Remove an existing card for the current user. This will set all properties except the ID to None and set isDeleted to true """ if not card.from_datastore or card.user != endpoints.get_current_user(): raise endpoints.NotFoundException("Contact not found.") if card.isDeleted: raise endpoints.NotFoundException("Card has been deleted") # Delete attachments keys = [] if card.attachments is not None: for att in card.attachments: keys.append(blobstore.BlobKey(att.id)) blobstore.delete_async(keys) card.attachments = [] card.bundleId = None card.canonicalUrl = None card.created = None card.creator = None card.displayTime = None card.html = None card.inReplyTo = None card.isBundleCover = None card.isPinned = None card.menuItems = [] card.notification = None card.recipients = [] card.sourceItemId = None card.speakableType = None card.speakableText = None card.text = None card.title = None card.updated = None card.isDeleted = True card.put() # Notify Glass emulator channel.send_message(card.user.email(), json.dumps({"id": card.id})) # Notify timeline DELETE subscriptions data = {} data["collection"] = "timeline" data["itemId"] = card.id operation = Operation.DELETE data["operation"] = operation.name header = {"Content-type": "application/json"} query = Subscription.query().filter(Subscription.user == endpoints.get_current_user()) query = query.filter(Subscription.collection == "timeline") query = query.filter(Subscription.operation == operation) for subscription in query.fetch(): data["userToken"] = subscription.userToken data["verifyToken"] = subscription.verifyToken req = urllib2.Request(subscription.callbackUrl, json.dumps(data), header) try: urllib2.urlopen(req) except: logging.error(sys.exc_info()[0]) return card
def subscriptions(): return render_template( 'subscriptions.html', subscriptions=Subscription.query().fetch(), events=logic.event.EVENTS, )