本文整理汇总了Python中template.Template.build方法的典型用法代码示例。如果您正苦于以下问题:Python Template.build方法的具体用法?Python Template.build怎么用?Python Template.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类template.Template
的用法示例。
在下文中一共展示了Template.build方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Api
# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import build [as 别名]
class Api(object):
def __init__(self, client):
self.client = client
self.template = Template()
self.settings = Settings()
self.color = Color()
def get_profile(self, params):
"""
wayterm > profile\[screen_name]
wayterm > p\[screen_name]
- get user's profile
"""
try:
screen_name = params[0]
except IndexError:
screen_name = None
try:
if screen_name == None:
response = self.client.get('users/show', uid = self.client.token['uid'])
else:
response = self.client.get('users/show', screen_name = screen_name)
except RuntimeError as e:
self._print_error(e)
return
print self.template.build('Profile', 'get', response)
self.get_user_updates(screen_name, self.settings.PROFILE_STATUS_CNT)
def get_user_updates(self, screen_name, count):
"""
private
"""
try:
response = self.client.get('statuses/user_timeline', screen_name = screen_name, count = count)
except RuntimeError as e:
self._print_error(e)
return
for status in response['statuses']:
print self.template.build('Update', 'get', status)
def get_updates(self, params):
"""
wayterm > list\[limit]
wayterm > l\[limit]
- get user's newest updates
- default limit = 10
"""
try:
limit = params[0]
except IndexError:
limit = self.settings.DEFAULT_LIST_STATUS_CNT
try:
response = self.client.get('statuses/home_timeline', uid=self.client.token['uid'], count=limit)
except RuntimeError as e:
self._print_error(e)
return
for status in response['statuses']:
print self.template.build('Update', 'get', status)
def post_tweet(self, params):
"""
wayterm > tweet\[message]
wayterm > t\[message]
- post weibo
"""
try:
pic_url = params[1]
except IndexError:
pic_url = None
try:
tweet = params[0]
tweet_length = len(tweet.decode('utf-8'))
if tweet_length == 0:
print 'Tweet can not be empty!'
return
if tweet_length > self.settings.MAX_CHARACTER_CNT:
print 'Tweet is over 140 characters. (' + str(tweet_length) + ' characters)'
return
if pic_url is None:
response = self.client.post('statuses/update', status=tweet)
else:
pic_data = self._fetch_pic_data(pic_url)
response = self.client.post('statuses/upload', status=tweet, pic=pic_data)
if not response.has_key('id'):
print 'Sina Weibo returns error.'
return
mid = self.client.get('statuses/querymid', id=response['id'], type=1)
weibo_url = self.settings.WEIBO_ROOT_URL + str(response['user']['id']) + '/' + mid["mid"]
response.update({"weibo_url":weibo_url})
print self.template.build('Update', 'post', response)
except RuntimeError as e:
print self.color.ERROR + '[ERROR] ' + str(e) + self.color.PLAIN
#.........这里部分代码省略.........