本文整理汇总了Python中snslog.SNSLog.info方法的典型用法代码示例。如果您正苦于以下问题:Python SNSLog.info方法的具体用法?Python SNSLog.info怎么用?Python SNSLog.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snslog.SNSLog
的用法示例。
在下文中一共展示了SNSLog.info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reply
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def reply(self, statusID, text):
'''
docstring placeholder
'''
"""reply status
* parameter status: StatusID object
* paramter text: string, the reply message
* return: success or not
"""
api_params = dict(method = "share.addComment", content = text, \
share_id = statusID.status_id, user_id = statusID.source_user_id)
try:
ret = self.renren_request(api_params)
logger.debug("Reply to status '%s' return: %s", statusID, ret)
if 'result' in ret and ret['result'] == 1:
logger.info("Reply '%s' to status '%s' succeed", text, statusID)
return True
else:
return False
except Exception, e:
logger.warning("Reply failed: %s", e)
示例2: home_timeline
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def home_timeline(self, count=20):
'''Get home timeline
get statuses of yours and your friends'
@param count: number of statuses
'''
api_params = dict(method = "feed.get", type = 10, page = 1, count = count)
try:
jsonlist = self.renren_request(api_params)
except Exception as e:
logger.warning("catch expection: %s", e)
jsonlist = []
statuslist = snstype.MessageList()
for j in jsonlist:
try:
statuslist.append(self.Message(j,\
platform = self.jsonconf['platform'],\
channel = self.jsonconf['channel_name']\
))
except Exception as e:
logger.warning("catch expection '%s' in parsing '%s'", e, j)
logger.info("Read %d statuses from '%s'", len(statuslist), self.jsonconf.channel_name)
return statuslist
示例3: save_config
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def save_config(self,
fn_channel = DIR_DEFAULT_CONF_CHANNEL,
fn_pocket = DIR_DEFAULT_CONF_POCKET):
"""
Save configs: reverse of load_config
Configs can be modified during execution. snsapi components
communicate with upper layer using Python objects. Pocket
will be the unified place to handle file transactions.
"""
conf_channel = []
for c in self.itervalues():
conf_channel.append(c.jsonconf)
conf_pocket = self.jsonconf
try:
json.dump(conf_channel, open(fn_channel, "w"), indent = 2)
json.dump(conf_pocket, open(fn_pocket, "w"), indent = 2)
except:
raise snserror.config.save
logger.info("save configs done")
示例4: reply
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def reply(self, mID, text):
'''
Reply a renren blog
:param mID: MessageID object
:param text: string, the reply message
:return: success or not
'''
if mID.user_type == 'user':
owner_key = 'uid'
owner_value = mID.source_user_id
else: # 'page'
owner_key = 'page_id'
owner_value = mID.source_page_id
api_params = {'method': 'blog.addComment',
'content': text,
'id': mID.blog_id,
owner_key: owner_value}
logger.debug('request parameters: %s', api_params)
try:
ret = self.renren_request(api_params)
if 'result' in ret and ret['result'] == 1:
logger.info("Reply '%s' to status '%s' succeed", text, mID)
return True
except Exception, e:
logger.warning("Catch Exception %s", e)
示例5: like
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def like(self, message, channel=None):
"""
like a message
"""
if isinstance(message, snstype.Message):
mID = message.ID
elif isinstance(message, snstype.MessageID):
mID = message
else:
logger.warning("unknown type: %s", type(message))
return {}
if channel:
if channel in self:
# If the platforms are not identical, like method will surly fail
if self[channel].platform != mID.platform:
logger.warning("Inter-platform like method is not supported.")
elif self[channel].is_expired():
logger.warning("channel '%s' is expired. Do nothing.", channel)
else:
re = self[channel].like(message)
else:
logger.warning("channel '%s' is not in pocket. Do nothing.", channel)
else:
for c in self.itervalues():
if self.__check_method(c, 'like') and not c.is_expired():
re = c.like(message)
break
logger.info("Like status '%s'. Result: %s",\
message.digest(), re)
return re
示例6: get_saved_token
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def get_saved_token(self):
try:
fname = self.auth_info.save_token_file
if fname == "(default)" :
fname = self.jsonconf.channel_name+".token.save"
if fname != "(null)" :
with open(fname, "r") as fp:
token = utils.JsonObject(json.load(fp))
# check expire time
if self.is_expired(token):
logger.debug("Saved Access token is expired, try to get one through sns.auth() :D")
return False
#TODO: decrypt token
self.token = token
else:
logger.debug("This channel is configured not to save token to file")
return False
except IOError:
logger.debug("No access token saved, try to get one through sns.auth() :D")
return False
logger.info("Read saved token for '%s' successfully", self.jsonconf.channel_name)
print self.token
return True
示例7: update
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def update(self, text, title=None):
'''
Post a blog
:param text: Blog post body.
:param title: Blog post title. (optional)
:return: success or not
'''
if title is None:
title = self._cat(20, [(text, 1)])
api_params = {'method': 'blog.addBlog',
'content': text,
'title': title}
try:
ret = self.renren_request(api_params)
logger.debug("response: %s", ret)
#TODO:
# Preserve the id for further use?
# Return it as multi-return-value?
if 'id' in ret:
logger.info("Update status '%s' on '%s' succeed", text, self.jsonconf.channel_name)
return True
except Exception, e:
logger.warning("Catch Exception %s", e)
示例8: update
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def update(self, text, pic=None):
'''update a status
* parameter text: the update message
* return: success or not
'''
# NOTE:
# * With this pre-shortening, we can post potentially longer messages.
# * It consumes one more API quota.
text = self._replace_with_short_url(text)
text = self._cat(self.jsonconf['text_length_limit'], [(text, 1)], delim='//')
try:
if not pic:
ret = self.weibo_request('statuses/update',
'POST',
{'status': text})
else:
ret = self.weibo_request(
'statuses/upload',
'POST',
{'status': text},
files={'pic': ('pic.jpg', pic)}
)
self.Message(ret)
logger.info("Update status '%s' on '%s' succeed", text, self.jsonconf.channel_name)
return True
except Exception as e:
logger.warning("Update status fail. Message: %s", e)
return False
示例9: load_config
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def load_config(self,
fn_channel = DIR_DEFAULT_CONF_CHANNEL,
fn_pocket = DIR_DEFAULT_CONF_POCKET):
"""
Read configs:
* channel.conf
* pocket.conf
"""
count_add_channel = 0
try:
with open(path.abspath(fn_channel), "r") as fp:
allinfo = json.load(fp)
for site in allinfo:
if self.add_channel(utils.JsonDict(site)):
count_add_channel += 1
except IOError:
#raise snserror.config.nofile(fn_channel)
logger.warning("'%s' does not exist. Use default", fn_channel)
except ValueError as e:
raise snserror.config.load("file: %s; message: %s" % (fn_channel, e))
try:
with open(path.abspath(fn_pocket), "r") as fp:
allinfo = json.load(fp)
self.jsonconf = allinfo
except IOError:
#raise snserror.config.nofile(fn_pocket)
logger.warning("'%s' does not exist. Use default", fn_pocket)
except ValueError as e:
raise snserror.config.load("file: %s; message:%s" % (fn_channel, e))
logger.info("Read configs done. Add %d channels" % count_add_channel)
示例10: update
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def update(self, text, pic=None):
'''update a status
* parameter text: the update message
* return: success or not
'''
text = self._cat(self.jsonconf['text_length_limit'], [(text, 1)])
if not pic:
method = "t/add"
else:
method = "t/add_pic"
try:
if pic:
ret = self.tencent_request(method, "POST", content=text, files={'pic': ('pic.jpg', pic)})
else:
ret = self.tencent_request(method, "POST", content=text)
if(ret['msg'] == "ok"):
logger.info("Update status '%s' on '%s' succeed", text, self.jsonconf.channel_name)
return True
else:
return ret
except Exception, e:
logger.warning("Catch Exception: %s", e)
return False
示例11: unlike
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def unlike(self, message, channel=None):
"""
unlike a message
"""
if channel:
if channel in self:
# If the platforms are not identical, unlike method will surly fail
if self[channel].platform != mID.platform:
logger.warning("Inter-platform unlike method is not supported.")
elif self[channel].is_expired():
logger.warning("channel '%s' is expired. Do nothing.", channel)
else:
re = self[channel].unlike(message)
else:
logger.warning("channel '%s' is not in pocket. Do nothing.", channel)
else:
for c in self.itervalues():
if self.__check_method(c, 'unlike') and not c.is_expired():
re = c.unlike(message)
break
logger.info("UnLike status '%s'. Result: %s",\
message.digest(), re)
return re
示例12: auth
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def auth(self):
if self.get_saved_token():
return
logger.info("Try to authenticate '%s' using OAuth2", self.jsonconf.channel_name)
self.auth_first()
self.auth_second()
self.save_token()
logger.debug("Authorized! access token is " + str(self.token))
logger.info("Channel '%s' is authorized", self.jsonconf.channel_name)
示例13: oauth2
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def oauth2(self):
'''
Authorizing using synchronized invocation of OAuth2.
Users need to collect the code in the browser's address bar to this client.
callback_url MUST be the same one you set when you apply for an app in openSNS platform.
'''
logger.info("Try to authenticate '%s' using OAuth2", self.jsonconf.channel_name)
self._oauth2_first()
self._oauth2_second()
示例14: reply
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def reply(self, statusID, text):
'''reply to a status
* parameter text: the comment text
* return: success or not
'''
ret = self.tencent_request("t/reply", "POST", content=text, reid=statusID.reid)
if(ret['msg'] == "ok"):
return True
logger.info("Reply '%s' to status '%s' fail: %s", text, self.jsonconf.channel_name, ret)
return ret
示例15: reply
# 需要导入模块: from snslog import SNSLog [as 别名]
# 或者: from snslog.SNSLog import info [as 别名]
def reply(self, statusID, text):
"""reply to a status
* parameter text: the comment text
* return: success or not
"""
try:
ret = self.weibo_request("comments/create", "POST", {"id": statusID.id, "comment": text})
ret["id"]
return True
except Exception as e:
logger.info("Reply '%s' to status '%s' fail: %s", text, self.jsonconf.channel_name, e)
return False