本文整理汇总了Python中snslog.SNSLog类的典型用法代码示例。如果您正苦于以下问题:Python SNSLog类的具体用法?Python SNSLog怎么用?Python SNSLog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SNSLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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)
示例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
示例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
示例6: update
def update(self, text):
try:
self.client.miniblog.new(text)
return True
except Exception, e:
logger.warning("DoubanAPIError: %s", e)
return False
示例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
示例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
示例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
示例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)))
示例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)
示例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
示例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
示例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
示例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_'],
})