本文整理汇总了Python中db.Db.set_datastore方法的典型用法代码示例。如果您正苦于以下问题:Python Db.set_datastore方法的具体用法?Python Db.set_datastore怎么用?Python Db.set_datastore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Db
的用法示例。
在下文中一共展示了Db.set_datastore方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: func_on
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def func_on(self, args):
if len(args):
for a in args:
if a == "home":
self._google_user.display_timeline |= MODE_HOME
elif a == "mention":
self._google_user.display_timeline |= MODE_MENTION
elif a == "dm":
self._google_user.display_timeline |= MODE_DM
elif a == "list":
self._google_user.display_timeline |= MODE_LIST
s = Session.get_by_key_name(self._google_user.jid)
if (
not s
and self._google_user.display_timeline
and self._google_user.enabled_user
and self._google_user.msg_template.strip()
):
try:
flag = xmpp.get_presence(self._google_user.jid)
except (xmpp.Error, DeadlineExceededError):
flag = False
if flag:
Db.set_datastore(Session(key_name=self._google_user.jid, shard=self._google_user.shard))
modes = []
if self._google_user.display_timeline & MODE_LIST:
modes.append("list")
if self._google_user.display_timeline & MODE_HOME:
modes.append("home")
if self._google_user.display_timeline & MODE_MENTION:
modes.append("mention")
if self._google_user.display_timeline & MODE_DM:
modes.append("dm")
return _("ON_MODE") % ", ".join(modes)
示例2: func_switch
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def func_switch(self, args):
length = len(args)
if length > 1:
raise NotImplementedError
else:
twitter_users = TwitterUser.get_by_jid(self._google_user.jid)
twitter_users_name = [u.twitter_name for u in twitter_users if u.twitter_name is not None]
if not length:
return (
_("NOW_USING") % self._google_user.enabled_user
+ "\n"
+ _("ALL_TWITTER_USERS_NAME") % "\n".join(twitter_users_name)
)
elif _check_username(args[0]):
twitter_users_name_ci = [x.lower() for x in twitter_users_name]
twitter_name_ci = args[0].lower()
if twitter_name_ci in twitter_users_name_ci:
i = twitter_users_name_ci.index(twitter_name_ci)
if (
not self._google_user.enabled_user
and self._google_user.display_timeline
and self._google_user.msg_template.strip()
):
try:
flag = xmpp.get_presence(self._google_user.jid)
except (xmpp.Error, DeadlineExceededError):
flag = False
if flag:
Db.set_datastore(Session(key_name=self._google_user.jid, shard=self._google_user.shard))
self._google_user.enabled_user = twitter_users_name[i]
return _("ENABLED_TWITTER_USER_CHANGED") % self._google_user.enabled_user
return _("NOT_ASSOCIATED_TWITTER_USER")
示例3: process
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def process(self, message):
global _locale
jid = message.sender.split('/')[0]
self._google_user = GoogleUser.get_by_jid(jid)
if self._google_user is None:
self._google_user = GoogleUser.add(jid)
_locale = self._google_user.locale
self._twitter_user = Dummy()
self._api = Dummy()
if self._google_user.enabled_user:
self._twitter_user = TwitterUser.get_by_twitter_name(self._google_user.enabled_user, self._google_user.jid)
if self._twitter_user is None:
self._google_user.enabled_user = ''
else:
self._api = twitter.Api(consumer_key=config.OAUTH_CONSUMER_KEY,
consumer_secret=config.OAUTH_CONSUMER_SECRET,
access_token_key=self._twitter_user.access_token_key,
access_token_secret=self._twitter_user.access_token_secret)
self._utils = Utils(self._google_user.jid)
try:
result = self.parse_command(message.body)
except NotImplementedError:
result = _('INVALID_COMMAND')
except twitter.TwitterInternalServerError:
result = _('INTERNAL_SERVER_ERROR')
except twitter.TwitterAuthenticationError:
self._google_user.retry += 1
if self._google_user.retry >= config.MAX_RETRY:
GoogleUser.disable(self._google_user.jid)
else:
Db.set_datastore(self._google_user)
result = _('NO_AUTHENTICATION')
return result
示例4: process
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def process(self):
global _locale
try:
message = xmpp.Message(self.request.POST)
except xmpp.InvalidMessageError:
return
jid = message.sender.split("/")[0]
self._google_user = GoogleUser.get_by_jid(jid)
if self._google_user is None:
self._google_user = GoogleUser.add(jid)
_locale = self._google_user.locale
if self._google_user.enabled_user:
self._twitter_user = TwitterUser.get_by_twitter_name(self._google_user.enabled_user, self._google_user.jid)
self._api = Dummy()
if self._twitter_user is None:
self._google_user.enabled_user = ""
else:
self._api = twitter.Api(
consumer_key=config.OAUTH_CONSUMER_KEY,
consumer_secret=config.OAUTH_CONSUMER_SECRET,
access_token_key=self._twitter_user.access_token_key,
access_token_secret=self._twitter_user.access_token_secret,
)
try:
self._user = self._api.verify_credentials()
if not self._user:
raise twitter.TwitterAuthenticationError
except twitter.TwitterAuthenticationError:
self._google_user.retry += 1
if self._google_user.retry >= config.MAX_RETRY:
GoogleUser.disable(self._google_user.jid)
xmpp.send_message(self._google_user.jid, _("NO_AUTHENTICATION"))
else:
Db.set_datastore(self._google_user)
return
else:
if self._google_user.retry > 0:
self._google_user.retry = 0
if self._twitter_user.twitter_name != self._user["screen_name"]:
self._twitter_user.twitter_name = self._user["screen_name"]
self._google_user.enabled_user = self._user["screen_name"]
else:
self._twitter_user = Dummy()
self._api = Dummy()
self._user = Dummy()
utils.set_jid(self._google_user.jid)
result = self.parse_command(message.body)
if result is None:
return
if result:
while CapabilitySet("xmpp").is_enabled():
try:
message.reply(result)
except xmpp.Error:
pass
else:
break
IdList.flush(self._google_user.jid)
Db.set_datastore(self._google_user)
示例5: post
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def post(self):
global _locale
try:
message = xmpp.Message(self.request.POST)
except xmpp.InvalidMessageError:
return
jid = message.sender.split('/')[0]
self._google_user = GoogleUser.get_by_jid(jid)
if self._google_user is None:
self._google_user = GoogleUser.add(jid)
_locale = self._google_user.locale
if self._google_user.enabled_user:
self._twitter_user = TwitterUser.get_by_twitter_name(self._google_user.enabled_user, self._google_user.jid)
self._api = Dummy()
if self._twitter_user is None:
self._google_user.enabled_user = ''
else:
self._api = twitter.Api(consumer_key=config.OAUTH_CONSUMER_KEY,
consumer_secret=config.OAUTH_CONSUMER_SECRET,
access_token_key=self._twitter_user.access_token_key,
access_token_secret=self._twitter_user.access_token_secret)
try:
self._user = self._api.verify_credentials()
except twitter.TwitterAuthenticationError:
self._google_user.retry += 1
if self._google_user.retry >= config.MAX_RETRY:
GoogleUser.disable(self._google_user.jid)
xmpp.send_message(self._google_user.jid, _('NO_AUTHENTICATION'))
else:
Db.set_datastore(self._google_user)
return
else:
if self._google_user.retry > 0:
self._google_user.retry = 0
try:
if self._twitter_user.twitter_name != self._user['screen_name']:
self._twitter_user.twitter_name = self._user['screen_name']
self._google_user.enabled_user = self._user['screen_name']
except TypeError:
logging.error('%s: %s' % (jid, unicode(self._user)))
return
else:
self._twitter_user = Dummy()
self._api = Dummy()
self._user = Dummy()
utils.set_jid(self._google_user.jid)
result = self.parse_command(message.body)
if result is None:
return
if result:
message.reply(result)
IdList.flush(self._google_user.jid)
Db.set_datastore(self._google_user)
示例6: post
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def post(self):
jid = self.request.get("from").split("/")[0]
s = Session.get_by_key_name(jid)
if not s:
u = GoogleUser.get_by_jid(jid)
if u and u.enabled_user and u.display_timeline and u.msg_template.strip():
try:
Db.set_datastore(Session(key_name=jid, shard=u.shard))
except CapabilityDisabledError:
try:
xmpp.send_presence(jid, presence_type=xmpp.PRESENCE_SHOW_AWAY)
except xmpp.Error:
pass
示例7: func_msgtpl
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def func_msgtpl(self, args):
if len(args):
tpl = " ".join(args)
while tpl[-2::] == r"\n":
tpl = tpl[: len(tpl) - 2] + "\n"
self._google_user.msg_template = tpl
s = Session.get_by_key_name(self._google_user.jid)
if not s and tpl.strip() and self._google_user.display_timeline and self._google_user.enabled_user:
try:
flag = xmpp.get_presence(self._google_user.jid)
except (xmpp.Error, DeadlineExceededError):
flag = False
if flag:
Db.set_datastore(Session(key_name=self._google_user.jid, shard=self._google_user.shard))
return _("MSG_TEMPLATE") % self._google_user.msg_template
示例8: post
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def post(self):
try:
message = xmpp.Message(self.request.POST)
except xmpp.InvalidMessageError:
return
else:
try:
result = self.process(message)
except (CapabilityDisabledError, DeadlineExceededError):
pass
else:
if result:
send_message(message.sender, result)
IdList.flush(self._google_user.jid)
Db.set_datastore(self._google_user)
示例9: post
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def post(self):
if db.WRITE_CAPABILITY:
jids = self.request.get_all('jid')
for jid in jids:
try:
google_user = GoogleUser.get_by_jid(jid)
except db.Error:
continue
_ = lambda x: gettext(x, locale=google_user.locale)
try:
twitter_user = TwitterUser.get_by_twitter_name(google_user.enabled_user, google_user.jid)
except db.Error:
continue
if twitter_user is None:
google_user.enabled_user = ''
Db.set_datastore(google_user)
continue
api = twitter.Api(consumer_key=config.OAUTH_CONSUMER_KEY,
consumer_secret=config.OAUTH_CONSUMER_SECRET,
access_token_key=twitter_user.access_token_key,
access_token_secret=twitter_user.access_token_secret)
try:
self._user = api.verify_credentials()
if 'screen_name' not in self._user:
raise twitter.TwitterError
except twitter.TwitterError:
google_user.retry += 1
if google_user.retry >= config.MAX_RETRY:
GoogleUser.disable(jid=google_user.jid)
xmpp.send_message(google_user.jid, _('NO_AUTHENTICATION'))
else:
Db.set_cache(google_user)
return
finally:
if google_user.retry > 0:
google_user.retry = 0
Db.set_cache(google_user)
if twitter_user.twitter_name != self._user['screen_name']:
twitter_user.twitter_name = self._user['screen_name']
Db.set_cache(twitter_user)
google_user.enabled_user = self._user['screen_name']
Db.set_cache(google_user)
utils.set_jid(google_user.jid)
home_statuses = []
home_mention_statuses = []
all_statuses = []
if google_user.display_timeline & MODE_HOME:
home_rpc = api.get_home_timeline(since_id=google_user.last_msg_id, async=True)
else:
home_rpc = api.get_home_timeline(since_id=google_user.last_mention_id, async=True)
if google_user.display_timeline & MODE_LIST:
list_rpc = api.get_list_statuses(user=google_user.list_user, id=google_user.list_id,
since_id=google_user.last_list_id, async=True)
else:
list_rpc = None
if google_user.display_timeline & MODE_MENTION:
mention_rpc = api.get_mentions(since_id=google_user.last_mention_id, async=True)
else:
mention_rpc = None
if google_user.display_timeline & MODE_DM:
dm_rpc = api.get_direct_messages(since_id=google_user.last_dm_id, async=True)
else:
dm_rpc = None
if google_user.display_timeline & MODE_HOME:
try:
home_statuses = api._process_result(home_rpc)
if home_statuses:
all_statuses.extend(home_statuses)
if home_statuses[0]['id'] > google_user.last_msg_id:
google_user.last_msg_id = home_statuses[0]['id']
except twitter.TwitterInternalServerError:
pass
except BaseException:
err = StringIO('')
traceback.print_exc(file=err)
logging.error(google_user.jid + ' Home:\n' + err.getvalue())
if google_user.display_timeline & MODE_LIST:
try:
statuses = api._process_result(list_rpc)
if statuses:
all_statuses.extend(statuses)
if statuses[0]['id'] > google_user.last_list_id:
google_user.last_list_id = statuses[0]['id']
except twitter.TwitterInternalServerError:
pass
except BaseException, e:
if 'Not found' not in e.message:
err = StringIO('')
traceback.print_exc(file=err)
logging.error(google_user.jid + ' List:\n' + err.getvalue())
if google_user.display_timeline & MODE_MENTION:
try:
statuses = api._process_result(mention_rpc)
all_statuses.extend(statuses)
if not google_user.display_timeline & MODE_HOME:
try:
home_statuses = api._process_result(home_rpc)
except twitter.TwitterInternalServerError:
pass
#.........这里部分代码省略.........
示例10: process
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def process(self, u):
jid = u.key().name()
try:
flag = xmpp.get_presence(jid)
except (xmpp.Error, DeadlineExceededError):
flag = True
if not flag:
u.delete()
return
google_user = GoogleUser.get_by_jid(jid)
if google_user is None:
u.delete()
return
time_delta = int(time()) - google_user.last_update
if time_delta < google_user.interval * 60 - 30:
return
_ = lambda x: gettext(x, locale=google_user.locale)
twitter_user = TwitterUser.get_by_twitter_name(google_user.enabled_user, google_user.jid)
if twitter_user is None:
google_user.enabled_user = ''
Db.set_datastore(google_user)
return
api = twitter.Api(consumer_key=config.OAUTH_CONSUMER_KEY,
consumer_secret=config.OAUTH_CONSUMER_SECRET,
access_token_key=twitter_user.access_token_key,
access_token_secret=twitter_user.access_token_secret)
try:
self._user = api.verify_credentials()
if not self._user or 'screen_name' not in self._user:
raise twitter.TwitterError
except twitter.TwitterError:
google_user.retry += 1
if google_user.retry >= config.MAX_RETRY:
GoogleUser.disable(jid=google_user.jid)
xmpp.send_message(google_user.jid, _('NO_AUTHENTICATION'))
else:
Db.set_cache(google_user)
return
finally:
if google_user.retry > 0:
google_user.retry = 0
Db.set_cache(google_user)
if twitter_user.twitter_name != self._user['screen_name']:
twitter_user.twitter_name = self._user['screen_name']
Db.set_cache(twitter_user)
google_user.enabled_user = self._user['screen_name']
Db.set_cache(google_user)
utils.set_jid(google_user.jid)
home_statuses = []
home_mention_statuses = []
all_statuses = []
at_username = '@' + google_user.enabled_user
if google_user.display_timeline & MODE_HOME or google_user.display_timeline & MODE_MENTION:
home_rpc = api.get_home_timeline(since_id=google_user.last_msg_id, async=True)
else:
home_rpc = None
if google_user.display_timeline & MODE_LIST:
list_rpc = api.get_list_statuses(user=google_user.list_user, id=google_user.list_id,
since_id=google_user.last_list_id, async=True)
else:
list_rpc = None
if google_user.display_timeline & MODE_MENTION:
mention_rpc = api.get_mentions(since_id=google_user.last_mention_id, async=True)
else:
mention_rpc = None
if google_user.display_timeline & MODE_DM:
dm_rpc = api.get_direct_messages(since_id=google_user.last_dm_id, async=True)
else:
dm_rpc = None
if google_user.display_timeline & MODE_HOME:
try:
home_statuses = api._process_result(home_rpc)
if home_statuses:
all_statuses.extend(home_statuses)
if home_statuses[0]['id'] > google_user.last_msg_id:
google_user.last_msg_id = home_statuses[0]['id']
except twitter.TwitterInternalServerError:
pass
except BaseException:
err = StringIO('')
traceback.print_exc(file=err)
logging.error(google_user.jid + ' Home:\n' + err.getvalue())
if google_user.display_timeline & MODE_MENTION:
try:
statuses = api._process_result(mention_rpc)
if statuses:
all_statuses.extend(statuses)
if statuses[0]['id'] > google_user.last_mention_id:
google_user.last_mention_id = statuses[0]['id']
if not google_user.display_timeline & MODE_HOME:
try:
home_statuses = api._process_result(home_rpc)
except twitter.TwitterInternalServerError:
pass
except BaseException:
err = StringIO('')
traceback.print_exc(file=err)
logging.error(google_user.jid + ' Home:\n' + err.getvalue())
else:
#.........这里部分代码省略.........
示例11: process
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
def process(self, google_user):
time_delta = int(time()) - google_user.last_update
if time_delta < google_user.interval * 60 - 30:
return
_ = lambda x: gettext(x, locale=google_user.locale)
twitter_user = TwitterUser.get_by_twitter_name(google_user.enabled_user, google_user.jid)
if twitter_user is None:
google_user.enabled_user = ''
Db.set_datastore(google_user)
return
api = twitter.Api(consumer_key=config.OAUTH_CONSUMER_KEY,
consumer_secret=config.OAUTH_CONSUMER_SECRET,
access_token_key=twitter_user.access_token_key,
access_token_secret=twitter_user.access_token_secret)
try:
self._user = api.verify_credentials()
if not self._user or 'screen_name' not in self._user:
raise twitter.TwitterError
except twitter.TwitterError:
google_user.retry += 1
if google_user.retry >= config.MAX_RETRY:
GoogleUser.disable(jid=google_user.jid)
xmpp.send_message(google_user.jid, _('NO_AUTHENTICATION'))
else:
Db.set_cache(google_user)
return
finally:
if google_user.retry > 0:
google_user.retry = 0
Db.set_cache(google_user)
if twitter_user.twitter_name != self._user['screen_name']:
twitter_user.twitter_name = self._user['screen_name']
Db.set_cache(twitter_user)
google_user.enabled_user = self._user['screen_name']
Db.set_cache(google_user)
self._utils = Utils(google_user.jid)
self._utils.allow_duplicate = False
at_username = '@' + google_user.enabled_user
statuses_id = []
mention_statuses = []
list_content = ''
dm_content = ''
mention_content = ''
home_content = ''
if google_user.display_timeline & MODE_DM:
try:
statuses = api.get_direct_messages(since_id=google_user.last_dm_id)
if statuses and statuses[0]['id'] > google_user.last_dm_id:
google_user.last_dm_id = statuses[0]['id']
dm_content = self._utils.parse_statuses(statuses)
except twitter.TwitterInternalServerError:
pass
except BaseException:
err = StringIO()
traceback.print_exc(file=err)
logging.error(google_user.jid + ' DM:\n' + err.getvalue())
if google_user.display_timeline & MODE_LIST:
try:
list_statuses = api.get_list_statuses(user=google_user.list_user, id=google_user.list_id, since_id=google_user.last_list_id)
if list_statuses:
if list_statuses[0]['id'] > google_user.last_list_id:
google_user.last_list_id = list_statuses[0]['id']
if google_user.display_timeline & MODE_MENTION:
for i in range(len(list_statuses) - 1, -1, -1):
x = list_statuses[i]
statuses_id.append(x['id'])
if at_username in x['text']:
mention_statuses.append(x)
del list_statuses[i]
list_content = self._utils.parse_statuses(list_statuses, filter_self=True)
except twitter.TwitterInternalServerError:
pass
except BaseException, e:
if 'Not found' not in e.message:
err = StringIO()
traceback.print_exc(file=err)
logging.error(google_user.jid + ' List:\n' + err.getvalue())
示例12: cmp
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import set_datastore [as 别名]
for x in tmp_mention_statuses:
if x['id'] not in statuses_id:
mention_statuses.append(x)
statuses_id.append(x['id'])
mention_statuses.sort(cmp=lambda x, y: cmp(x['id'], y['id']))
mention_content = self._utils.parse_statuses(mention_statuses, reverse=False, filter_self=True)
except twitter.TwitterInternalServerError:
pass
except BaseException:
err = StringIO()
traceback.print_exc(file=err)
logging.error(google_user.jid + ' Mention:\n' + err.getvalue())
IdList.flush(google_user.jid)
google_user.last_update = int(time())
if Db.set_datastore(google_user):
if dm_content:
xmpp.send_message(google_user.jid, _('DIRECT_MESSAGES') + '\n\n' + dm_content)
if mention_content:
xmpp.send_message(google_user.jid, _('MENTIONS') + '\n\n' + mention_content)
if list_content:
xmpp.send_message(google_user.jid, _('LIST') % (google_user.list_user + '/' + google_user.list_name) + '\n\n' + list_content)
if home_content:
xmpp.send_message(google_user.jid, _('TIMELINE') + '\n\n' + home_content)
if __name__ == "__main__":
application = webapp.WSGIApplication([('/cron(\d+)', cron_handler)])
run_wsgi_app(application)