本文整理汇总了Python中models.Subscription.query方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.query方法的具体用法?Python Subscription.query怎么用?Python Subscription.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Subscription
的用法示例。
在下文中一共展示了Subscription.query方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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)
示例2: locations_insert
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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
示例3: get
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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')
示例4: handle_single_source
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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 )
示例5: get
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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}))
示例6: get
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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: action_insert
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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)
示例8: action_insert
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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)
示例9: timeline_delete
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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
示例10: action_insert
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import query [as 别名]
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)