本文整理汇总了Python中snslog.SNSLog类的典型用法代码示例。如果您正苦于以下问题:Python SNSLog类的具体用法?Python SNSLog怎么用?Python SNSLog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SNSLog类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _parse
def _parse(self, dct):
if "deleted" in dct and dct["deleted"]:
logger.debug("This is a deleted message %s of SinaWeiboStatusMessage", dct["id"])
self.parsed.time = "unknown"
self.parsed.username = "unknown"
self.parsed.userid = "unknown"
self.parsed.text = "unknown"
self.deleted = True
return
self.ID.id = dct["id"]
self.parsed.time = utils.str2utc(dct["created_at"])
self.parsed.username = dct["user"]["name"]
self.parsed.userid = dct["user"]["id"]
self.parsed.reposts_count = dct["reposts_count"]
self.parsed.comments_count = dct["comments_count"]
if "retweeted_status" in dct:
self.parsed.username_orig = "unknown"
try:
self.parsed.username_orig = dct["retweeted_status"]["user"]["name"]
except KeyError:
logger.warning("KeyError when parsing SinaWeiboStatus. May be deleted original message")
self.parsed.text_orig = dct["retweeted_status"]["text"]
self.parsed.text_trace = dct["text"]
self.parsed.text = (
self.parsed.text_trace + " || " + "@" + self.parsed.username_orig + " : " + self.parsed.text_orig
)
else:
self.parsed.text_orig = dct["text"]
self.parsed.text_trace = None
self.parsed.text = self.parsed.text_orig
开发者ID:rankun203,项目名称:snsapi,代码行数:33,代码来源:sina.py
示例2: forward
def forward(self, message, text):
try:
self.client.miniblog.reshare(message.ID.id)
return True
except Exception, e:
logger.warning("DoubanAPIError: %s", e)
return False
开发者ID:huiliang,项目名称:snsapi,代码行数:7,代码来源:douban.py
示例3: home_timeline
def home_timeline(self, count=20):
'''Get home timeline
* function : get statuses of yours and your friends'
* parameter count: number of statuses
'''
url = "https://api.weibo.com/2/statuses/home_timeline.json"
params = {}
params['count'] = count
params['access_token'] = self.token.access_token
jsonobj = self._http_get(url, params)
statuslist = snstype.MessageList()
try:
if("error" in jsonobj):
logger.warning("error json object returned: %s", jsonobj)
return []
for j in jsonobj['statuses']:
statuslist.append(self.Message(j,\
platform = self.jsonconf['platform'],\
channel = self.jsonconf['channel_name']\
))
except Exception, e:
logger.warning("Catch exception: %s", e)
开发者ID:uestcmy,项目名称:snsapi_changedfile,代码行数:25,代码来源:sina.py
示例4: unlike
def unlike(self, message):
try:
self.client.miniblog.unlike(message.ID.id)
return True
except Exception, e:
logger.warning("DoubanAPIError, %s", e)
return False
开发者ID:huiliang,项目名称:snsapi,代码行数:7,代码来源:douban.py
示例5: reply
def reply(self, statusID, text):
try:
self.client.miniblog.comment.new(statusID.id, text)
return True
except Exception, e:
logger.warning('DoubanAPIError: %s', str(e))
return False
开发者ID:huiliang,项目名称:snsapi,代码行数:7,代码来源:douban.py
示例6: update
def update(self, text):
try:
self.client.miniblog.new(text)
return True
except Exception, e:
logger.warning("DoubanAPIError: %s", e)
return False
开发者ID:huiliang,项目名称:snsapi,代码行数:7,代码来源:douban.py
示例7: _forward
def _forward(self, mID, text):
"""
Raw forward method
* Only support Sina message
* Use 'text' as exact comment sequence
"""
try:
ret = self.weibo_request("statuses/repost", "POST", {"id": mID.id, "status": text})
if "id" in ret:
return True
else:
logger.warning(
"'%s' forward status '%s' with comment '%s' fail. ret: %s",
self.jsonconf.channel_name,
mID,
text,
ret,
)
return False
except Exception as e:
logger.warning(
"'%s' forward status '%s' with comment '%s' fail: %s", self.jsonconf.channel_name, mID, text, e
)
return False
开发者ID:rankun203,项目名称:snsapi,代码行数:25,代码来源:sina.py
示例8: _forward
def _forward(self, mID, text):
'''
Raw forward method
* Only support Renren message
* Use 'text' as exact comment sequence
'''
try:
api_params = {'method': 'status.forward',
'status': text,
'forward_owner': mID.source_user_id,
'place_id': 'RRAF04D95FA37892FFA88',
'forward_id': mID.status_id
}
ret = self.renren_request(api_params)
if 'id' in ret:
# ret['id'] is the ID of new status
# X, their doc says the field name is 'result'...
return True
else:
logger.warning("'%s' forward status '%s' with comment '%s' fail. ret: %s",
self.jsonconf.channel_name, mID, text, ret)
return False
except Exception as e:
logger.warning("'%s' forward status '%s' with comment '%s' fail: %s",
self.jsonconf.channel_name, mID, text, e)
return False
开发者ID:YangRonghai,项目名称:snsapi,代码行数:27,代码来源:renren.py
示例9: unlike
def unlike(self, message, channel=None):
"""
unlike 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, 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
开发者ID:huiliang,项目名称:snsapi,代码行数:34,代码来源:snspocket.py
示例10: update_func
def update_func(self):
logger.debug("acquiring lock")
self.dblock.acquire()
try:
conn = sqlite3.connect(self.sqlitefile)
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
cursor.execute("SELECT * FROM pending_update")
i = cursor.fetchone()
if i:
cursor.execute("DELETE FROM pending_update WHERE id = ?", (i['id'], ))
j = {
'id': str(i['id']),
'args': str2obj(str(i['args'])),
'kwargs': str2obj(str(i['kwargs'])),
'type': str(i['type']),
'callback': str2obj(str(i['callback']))
}
res = getattr(self.sp, j['type'])(*j['args'], **j['kwargs'])
if j['callback']:
j['callback'](self, res)
conn.commit()
cursor.close()
except Exception, e:
logger.warning("Error while updating: %s" % (str(e)))
开发者ID:Kelvin-Zhong,项目名称:snsapi,代码行数:25,代码来源:snspocket.py
示例11: _fetch_code_local_username_password
def _fetch_code_local_username_password(self):
try:
login_username = self.auth_info.login_username
login_password = self.auth_info.login_password
app_key = self.jsonconf.app_key
app_secret = self.jsonconf.app_secret
callback_url = self.auth_info.callback_url
referer_url = self._last_requested_url
postdata = {"client_id": app_key,
"redirect_uri": callback_url,
"userId": login_username,
"passwd": login_password,
"isLoginSina": "0",
"action": "submit",
"response_type": "code",
}
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0",
"Host": "api.weibo.com",
"Referer": referer_url
}
auth_url = "https://api.weibo.com/oauth2/authorize"
# auth_url = self.auth_info.auth_url
resp_url = self._http_post(auth_url, data=postdata, headers=headers, json_parse=False).url
logger.debug("response URL from local post: %s", resp_url)
return resp_url
except Exception, e:
logger.warning("Catch exception: %s", e)
开发者ID:huiliang,项目名称:snsapi,代码行数:31,代码来源:sina.py
示例12: update
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
开发者ID:huiliang,项目名称:snsapi,代码行数:30,代码来源:sina.py
示例13: like
def like(self, message):
'''
Like method
* Weibo doesn't provide an API for "like"
* So "favourite" function supersedes "like"
* Here "like" means "add to my favourites"
* Receive a message
'''
mID = message.ID
try:
ret = self.weibo_request('favorites/create',
'POST',
{'id': mID.id})
# error_code 20704 means this status had been collected.
# For the purpose of backward compatibility, we also view
# it as a successful like
if 'favorited_time' in ret or ret["error_code"] == 20704:
message.parsed.liked = True
return True
else:
logger.warning("'%s' likes status '%s' fail. ret: %s",
self.jsonconf.channel_name, mID, ret)
return False
except Exception, e:
logger.warning("Exception: %s. '%s' like status '%s' fail. ret: %s",
e, self.jsonconf.channel_name, mID, ret)
return False
开发者ID:wcyz666,项目名称:snsrouter-modified,代码行数:27,代码来源:sina.py
示例14: unlike
def unlike(self, message):
res = None
flag = False
try:
# The order in the bracket is important since there
# exists "SHARE_XXXX" type. In order to figure out
# the actual type, SHARE must be put in the first position.
for msg_type in ["SHARE", "BLOG", "PHOTO", "ALBUM", "STATUS", "VIDEO"]:
if msg_type in message.ID.feed_type:
flag = True
break
if flag:
res = self.renren_request(
method="like/ugc/remove",
ugcOwnerId=message.ID.source_user_id,
likeUGCType="TYPE_" + msg_type,
ugcId=message.ID.resource_id
)
else:
return False
except Exception as e:
logger.warning('Catch exception: %s', type(e))
return False
if res:
return True
else:
return False
开发者ID:huiliang,项目名称:snsapi,代码行数:27,代码来源:renren.py
示例15: reply
def reply(self, statusId, text):
res = None
flag = False
try:
# The order in the bracket is important since there
# exists "SHARE_XXXX" type. In order to figure out
# the actual type, SHARE must be put in the first position.
for msg_type in ["SHARE", "BLOG", "PHOTO", "ALBUM", "STATUS", "VIDEO"]:
if msg_type in statusId.feed_type:
flag = True
break
if flag:
res = self.renren_request(
method="comment/put",
content=text,
commentType=msg_type,
entryOwnerId=statusId.source_user_id,
entryId=statusId.resource_id
)
else:
return BooleanWrappedData(False, {
'errors': ['SNSAPI_NOT_SUPPORTED'],
})
except Exception, e:
logger.warning('Catch exception: %s', e)
return BooleanWrappedData(False, {
'errors': ['PLATFORM_'],
})
开发者ID:huiliang,项目名称:snsapi,代码行数:28,代码来源:renren.py
示例16: get
def get(self, attr, default_value = "(null)"):
'''
dict entry reading with fault tolerance.
:attr:
A str or a list of str.
If attr is a list, we will try all the candidates until
one 'get' is successful. If none of the candidates succeed,
we will return a "(null)"
e.g. RSS format is very diverse.
To my current knowledge, some formats have 'author' fields,
but others do not:
* rss : no
* rss2 : yes
* atom : yes
* rdf : yes
This function will return a string "(null)" by default if the
field does not exist. The purpose is to expose unified interface
to upper layers. seeing "(null)" is better than catching an error.
'''
if isinstance(attr, str):
return dict.get(self, attr, default_value)
elif isinstance(attr, list):
for a in attr:
val = dict.get(self, a, None)
if val:
return val
return default_value
else:
logger.warning("Unkown type: %s", type(attr))
return default_value
开发者ID:Nukker,项目名称:snsapi,代码行数:34,代码来源:utils.py
示例17: update
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
开发者ID:huiliang,项目名称:snsapi,代码行数:27,代码来源:tencent.py
示例18: save_config
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")
开发者ID:Kelvin-Zhong,项目名称:snsapi,代码行数:25,代码来源:snspocket.py
示例19: unlike
def unlike(self, message):
'''
Unlike method
* Weibo doesn't provide an API for "unlike"
* So "unfavourite" function supersedes "unlike"
* Here "unlike" means "remove from my favourites"
* Receive a message
'''
mID = message.ID
try:
ret = self.weibo_request('favorites/destroy',
'POST',
{'id': mID.id})
# error_code 20705 means this status had never been collected.
# For the purpose of backward compatibility, we also view
# it as a successful unlike
if 'favorited_time' in ret or ret["error_code"] == 20705:
return True
else:
logger.warning("'%s' unlikes status '%s' fail. ret: %s",
self.jsonconf.channel_name, mID, ret)
return False
except Exception, e:
logger.warning("'%s' unlike status '%s' fail. ret: %s",
self.jsonconf.channel_name, mID, ret)
return False
开发者ID:huiliang,项目名称:snsapi,代码行数:26,代码来源:sina.py
示例20: append
def append(self, e):
if isinstance(e, Message):
if hasattr(e, 'deleted') and e.deleted:
logger.debug("Trying to append Deleted Message type element. Ignored")
else:
super(MessageList, self).append(e)
else:
logger.debug("Trying to append non- Message type element. Ignored")
开发者ID:Kelvin-Zhong,项目名称:snsapi,代码行数:8,代码来源:snstype.py
注:本文中的snslog.SNSLog类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论