本文整理汇总了Python中model.User.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_key_name方法的具体用法?Python User.get_by_key_name怎么用?Python User.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.get_by_key_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def post(self):
entityType = self.request.get('entityType')
email = self.request.get('email')
if entityType == 'EstimatedTime':
user = User.get_by_key_name(key_names = email)
if not user:
self.response.out.write("null")
else:
hexGmailThreadIdList = self.request.get('hexGmailThreadIdList')
if hexGmailThreadIdList:
user_ctx_id = user.user_ctx_id
tid_list = json.loads(hexGmailThreadIdList)
results = []
for thread_id in tid_list:
if thread_id:
thread = Thread.get_or_insert(key_name = thread_id, thread_id = thread_id, user_email = email)
if thread.is_processed:
results.append(str(thread.estimated_reading_time))
else:
if not thread.is_queued:
thread.is_queued = True
thread.put()
processReadingThread(user_ctx_id, email, [thread_id])
#FIXME
#deferred.defer(processReadingThread, user_ctx_id, email, [thread_id], _queue='reading-queue', _target='crawler')
results.append("-1")
else:
results.append(None)
self.response.out.write(json.dumps(results))
else:
self.response.out.write("null")
elif entityType == 'User':
user = User.get_by_key_name(key_names = email)
if not user:
self.response.out.write('null')
else:
result = {
"userId": user.user_ctx_id,
"email": email,
"orgKey": "",
"creationTimestamp": "1359721200347",
"lastUpdatedTimestamp": "1359878999598",
"lastSeenTimestamp": "1359878400000",
"lastSeenClientVersion": "5.10",
"lastSeenExtVersion": "5.0",
"lastSeenBrowser": "Chrome",
"userSettings": {
"value": "{}"
},
"isOauthComplete": user.is_oauth_complete,
"userKey": "",
"displayName": email,
"key": "",
"experiments": {}
}
self.response.out.write(json.dumps(result))
else:
self.response.out.write("[]")
示例2: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get(self, user_email):
flow = createFlow(self, user_email)
credentials = StorageByKeyName(CredentialsModel, user_email, 'credentials').get()
force = self.request.get('force')
if force and force == 'true':
self.redirect(flow.step1_get_authorize_url())
return
if credentials:
user = User.get_by_key_name(user_email)
if not user or not user.is_oauth_complete:
ctxIO = ContextIO(consumer_key=settings.CONTEXTIO_OAUTH_KEY,
consumer_secret=settings.CONTEXTIO_OAUTH_SECRET)
current_account = ctxIO.post_account(email=user_email)
user = User.get_or_insert(key_name = user_email,
user_ctx_id=current_account.id,
email=user_email)
refresh_token = credentials.refresh_token
try:
if not refresh_token:
raise Exception('no refresh token')
current_account.post_source(email=user_email,
username=user_email,
server='imap.gmail.com',
provider_refresh_token=refresh_token,
provider_consumer_key=settings.APPENGINE_CONSUMER_KEY)
except Exception as e:
logging.error(str(e))
self.redirect(flow.step1_get_authorize_url())
user.is_oauth_complete = True
user.put()
self.response.out.write(r"""<html><head><script type="text/javascript">window.close();</script></head><body><div id="sbi_camera_button" class="sbi_search" style="left: 0px; top: 0px; position: absolute; width: 29px; height: 27px; border: none; margin: 0px; padding: 0px; z-index: 2147483647; display: none;"></div></body></html>""")
else:
logging.info('redirect')
self.redirect(flow.step1_get_authorize_url())
示例3: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get(self):
if self.get_current_user() is not None:
user = User.get_by_key_name(self.user["uid"])
if user is not None:
try:
dobot = DoubanRobot(user.douban_key, user.douban_secret)
dobot.get_current_user()
self.redirect("/auth/weibo/")
except Exception,e:
pass
示例4: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get(self):
email = self.request.get('email')
thread_ids = json.loads(self.request.get('thread_ids'))
user = User.get_by_key_name(key_names = email)
for index, thread_id in enumerate(thread_ids):
thread = Thread.get_or_insert(key_name = thread_id, thread_id = thread_id, user_email = email)
thread.is_queued = True
thread.is_processed = False
thread.put()
deferred.defer(processReadingThread, user.user_ctx_id, email, thread_ids, _queue='reading-queue', _target='crawler')
示例5: current_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def current_user(self):
"""Returns the logged in Facebook user, or None if unconnected."""
if not hasattr(self, "_current_user"):
self._current_user = None
user_id = functions.parse_cookie(self.request.cookies.get("fb_user"))
if user_id:
self._current_user = User.get_by_key_name(user_id)
logging.debug("Current User: ")
pp = pprint.PrettyPrinter(indent=2)
#pp.pprint(self._current_user)
logging.debug(pp.pformat(self._current_user))
return self._current_user
示例6: get_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get_user(user_identifier):
"""
Returns the user corresponding to the given identifier.
Args:
The user identifier string
Returns:
An instance of the User model, or None if no user exists
with that identifier.
"""
return User.get_by_key_name(user_identifier)
示例7: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get(self,page):
try:
self.session = sessions.Session()
user = User.get_by_key_name(str(self.session["twitter_id"]))
s = self.session
except :
user = None
s = None
values = {
'user': user,
'session': s,
}
path = os.path.join(os.path.dirname(__file__), 'templates/' + page + '.html')
self.response.out.write(template.render(path, values))
return
示例8: get_current_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get_current_user(self):
if self.user is None:
uid = self.get_cookie("uid")
if uid is None:
return None
self.user = {}
self.user["uid"] = uid
self.user["name"] = self.get_cookie("name")
self.user["weibo_name"] = self.get_cookie("weibo_name")
if self.user["weibo_name"] is None:
user = User.get_by_key_name(self.user["uid"])
if user is not None and user.weibo_key and user.weibo_secret:
try:
weibot = WeiboRobot(user.weibo_key, user.weibo_secret)
self.user["weibo_name"] = weibot.auth.get_username()
self.set_cookie("weibo_name", self.user["weibo_name"])
except WeibopError,e:
pass
示例9: fetch
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def fetch(uid):
user = User.get_by_key_name(uid)
if not user:
return
doubanbot = DoubanRobot(user.douban_key, user.douban_secret)
weibobot = WeiboRobot(user.weibo_key, user.weibo_secret)
entries = doubanbot.get_miniblogs()
#entries.sort(cmp=lambda x,y: cmp(x.time, y.time))
if not entries:
user.sync_time = datetime.datetime.now() + datetime.timedelta(seconds=TIME_DELTA)
user.put()
return
cnt = 0
for entry in reversed(entries):
if (not user.last_id) or (entry.id > user.last_id):
try:
cnt += 1
weibobot.send(entry.to_send)
except WeibopError, e:
# handle error: user has revoked access privilege to this application
if e.reason.find("40072") != -1:
logging.info("Delete binding, because user has revoked access privilege for this application from Sina: " + e.reason);
user.delete()
return
# 40028 indicates that the tweet is duplicated or user is in black list
if e.reason.find("40028") != -1 or e.reason.find("40308") != -1:
if e.reason.find("有关部门") != -1:
#您输入的网址被有关部门列为恶意网址,无法发表,请谅解。
logging.info(entry.to_send)
continue
logging.info("User is in black list? Skip this tweet and temporary disable sync for 1 hour. " + e.reason)
user.sync_time = datetime.datetime.now() + datetime.timedelta(seconds=3600)
if cnt>0:
user.last_id = entries[-(cnt-1)].id
user.put()
return
# ignore "repeated weibo text" error
if e.reason.find("40025") != -1:
logging.info("Error ignored: " + e.reason)
else:
# other error
pass
示例10: get_logged_in_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get_logged_in_user():
"""Gets the currently logged in user.
The login is based on the GAE user system, but Users are stored as
separate entities. If the user does not have an entity, one will
be created using the information in his Google account.
Returns:
An instance of the User model, or None if the user is not
logged in.
"""
guser = users.get_current_user()
if not guser:
return None
user = User.get_by_key_name(guser.user_id())
if not user:
user = User(key_name=guser.user_id(), name=guser.nickname())
user.put()
return user
示例11: get_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get_user(self, required=False):
"""Returns the User object given by the URL."""
if self.response_dict().user:
return self.response_dict().user
key = self.url_arg(0)
if key:
user = None
try:
user = User.get(key)
except db.BadKeyError:
pass
if not user:
email = urllib.unquote(key)
key_name = User.key_name_from_email(email)
user = User.get_by_key_name(key_name)
if user:
self.response_dict(user = user) # for the template
return user
if required:
raise NotFoundException("user not found")
示例12: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def post(self):
try:
domain = self.request.get('domain')
task_id = int(self.request.get('id'))
assignee = self.request.get('assignee')
except (TypeError, ValueError):
self.error(403)
logging.error("Invalid input")
return
user = api.get_and_validate_user(domain)
if not user:
self.error(403)
return
assignee = User.get_by_key_name(assignee)
if not assignee:
self.error(403)
logging.error("No assignee")
return
task = api.assign_task(domain, task_id, user, assignee)
session = Session(writer='cookie',
wsgiref_headers=self.response.headers)
add_message(session, "Task '%s' assigned to '%s'" %
(task.title(), assignee.name))
self.redirect(self.request.headers.get('referer'))
示例13: get_user_from_identifier
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get_user_from_identifier(user_identifier):
"""Returns the user corresponding to the given identifier"""
# TODO(tijmen): Name this get_user and rename the current
# function to something like get_logged_in_user().
return User.get_by_key_name(user_identifier)
示例14: receive
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def receive(self, mail_message):
try:
email = mail_message.to.split('@')
except:
email = None
email_prefix = email[0].split('.')
screen_name_temp = email_prefix[0].split('<')
try:
screen_name = screen_name_temp[1]
except:
screen_name = screen_name_temp[0]
email_key = email_prefix[1]
email_user = User.find_by_screen_name(screen_name.lower());
try:
if(email_key == email_user.email_key):
# Set Up Twitter Client
callback_url = "%s/verify" % self.request.host_url
client = oauth.TwitterClient(MainHandler.application_key, MainHandler.application_secret, callback_url)
#Get Post
plaintext_bodies = mail_message.bodies('text/plain')
for content_type, body in plaintext_bodies:
decoded_text = body.decode()
content = decoded_text
try:
subject = mail_message.subject + "\n\r"
except:
subject = ''
if content is not None:
body = functions.strip_tags(content)
else:
body = ''
#Save Post
post_info = {}
post_info['content'] = subject + body
post_key = Post.save_post(post_info)
#Save Tweetc
user = User.get_by_key_name(str(email_user.twitter_id))
tweetc_info = {}
tweetc_info['tweet_id'] = None
tweetc_info['tweet'] = None
tweetc_info['user'] = user.key()
tweetc_info['post'] = post_key
tweetc_info['client'] = 'email'
tweetc_key = Tweetc.save_tweetc(tweetc_info)
#Send Tweet
tweetc = Tweetc.get(tweetc_key)
tweet = functions.word_wrap(content,108,prefix ="||")
tweet = tweet.split("||")
tweetc_code = tweetc.code()
del tweet[0]
if len(tweet) == 1:
i = 1
elif len(tweet) == 2:
i = 2
else:
i = 3
count = 0
tweet_list = []
while (count < i):
last = i - 1
if count == last:
tweetout = tweet[count] + ' ' + str(count + 1) + '/' + str(i)
if len(tweet) > 3:
tweetout += '...'
tweetout += ' http://tweetc.com/' + tweetc_code
else:
tweetout = tweet[count] + ' ' + str(count + 1) + '/' + str(i)
self.response.out.write(tweetout)
tweet_list.append(tweetout)
count = count + 1
first_tweet = tweet_list[0] + ' http://tweetc.com/' + tweetc_code
tweet_list.reverse()
count = 0
while (count < i):
self.response.out.write(tweet_list[count] + '<br>')
additional_params={"status":tweet_list[count]}
url = "http://twitter.com/statuses/update.json"
result = client.make_request(url=url, token=user.token,secret=user.secret, additional_params=additional_params, method=urlfetch.POST)
rsp = json.loads(result.content)
if count == 0:
status_id = rsp['id']
count = count + 1
#Update Tweetc with Tweet ID
tweetc = Tweetc.get(tweetc_key)
tweetc.tweet_id = status_id
tweetc.tweet = first_tweet
tweetc.put()
except:
logging.info(screen_name)
logging.info(email_key)
logging.info("Sending Email Error")
示例15: get_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_key_name [as 别名]
def get_user(user_key):
user = deserialize_entities(memcache.get("user-%s" % user_key))
if user is None:
user = User.get_by_key_name(user_key)
return user