本文整理汇总了Python中twitter.util.printNicely函数的典型用法代码示例。如果您正苦于以下问题:Python printNicely函数的具体用法?Python printNicely怎么用?Python printNicely使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了printNicely函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: connectToStream
def connectToStream(self, auth):
printNicely("-- Connecting to Stream --")
stream = TwitterStream(auth = auth, secure = True, timeout = 20, heartbeat_timeout = 90)
tweet_iter = stream.statuses.filter(track = "love")
# while True:
# print(".")
# self.publish('com.myapp.heartbeat')
# yield sleep(1)
for tweet in tweet_iter:
# check whether this is a valid tweet
if tweet is None:
printNicely("-- None --")
return
elif tweet is Timeout:
printNicely("-- Timeout --")
sleep(5);
return
elif tweet is HeartbeatTimeout:
printNicely("-- Heartbeat Timeout --")
return
elif tweet is Hangup:
printNicely("-- Hangup --")
return
elif tweet.get('text'):
# obj = {'text': tweet["text"], 'user': tweet["user"]["screen_name"]}
obj = {'text': tweet["text"]}
yield obj
开发者ID:Avnerus,项目名称:tweettrek,代码行数:29,代码来源:backend.py
示例2: help_friends_and_followers
def help_friends_and_followers():
"""
Friends and Followers
"""
s = ' ' * 2
# Follower and following
usage = '\n'
usage += s + grey(u'\u266A' + ' Friends and followers \n')
usage += s * 2 + \
light_green('ls fl') + \
' will list all followers (people who are following you).\n'
usage += s * 2 + \
light_green('ls fr') + \
' will list all friends (people who you are following).\n'
usage += s * 2 + light_green('fl @dtvd88') + ' will follow ' + \
magenta('@dtvd88') + '.\n'
usage += s * 2 + light_green('ufl @dtvd88') + ' will unfollow ' + \
magenta('@dtvd88') + '.\n'
usage += s * 2 + light_green('mute @dtvd88') + ' will mute ' + \
magenta('@dtvd88') + '.\n'
usage += s * 2 + light_green('unmute @dtvd88') + ' will unmute ' + \
magenta('@dtvd88') + '.\n'
usage += s * 2 + light_green('muting') + ' will list muting users.\n'
usage += s * 2 + light_green('block @dtvd88') + ' will block ' + \
magenta('@dtvd88') + '.\n'
usage += s * 2 + light_green('unblock @dtvd88') + ' will unblock ' + \
magenta('@dtvd88') + '.\n'
usage += s * 2 + light_green('report @dtvd88') + ' will report ' + \
magenta('@dtvd88') + ' as a spam account.\n'
printNicely(usage)
开发者ID:thameera,项目名称:rainbowstream,代码行数:30,代码来源:rainbow.py
示例3: list
def list():
"""
Twitter's list
"""
t = Twitter(auth=authen())
# List all lists or base on action
try:
g['list_action'] = g['stuff'].split()[0]
except:
show_lists(t)
return
# Sub-function
action_ary = {
'home': list_home,
'all_mem': list_members,
'all_sub': list_subscribers,
'add': list_add,
'rm': list_remove,
'sub': list_subscribe,
'unsub': list_unsubscribe,
'own': list_own,
'new': list_new,
'update': list_update,
'del': list_delete,
}
try:
return action_ary[g['list_action']](t)
except:
printNicely(red('Please try again.'))
开发者ID:thameera,项目名称:rainbowstream,代码行数:29,代码来源:rainbow.py
示例4: quote
def quote():
"""
Quote a tweet
"""
# Get tweet
t = Twitter(auth=authen())
try:
id = int(g['stuff'].split()[0])
except:
printNicely(red('Sorry I can\'t understand.'))
return
tid = c['tweet_dict'][id]
tweet = t.statuses.show(id=tid)
# Get formater
formater = format_quote(tweet)
if not formater:
return
# Get comment
prefix = light_magenta('Compose your ') + light_green('#comment: ')
comment = raw_input(prefix)
if comment:
quote = comment.join(formater.split('#comment'))
t.statuses.update(status=quote)
else:
printNicely(light_magenta('No text added.'))
开发者ID:kaushikpendurthi,项目名称:rainbowstream,代码行数:25,代码来源:rainbow.py
示例5: help_list
def help_list():
"""
Lists
"""
s = ' ' * 2
# Twitter list
usage = '\n'
usage += s + grey(u'\u266A' + ' Twitter list\n')
usage += s * 2 + light_green('list') + \
' will show all lists you are belong to.\n'
usage += s * 2 + light_green('list home') + \
' will show timeline of list. You will be asked for list\'s name.\n'
usage += s * 2 + light_green('list all_mem') + \
' will show list\'s all members.\n'
usage += s * 2 + light_green('list all_sub') + \
' will show list\'s all subscribers.\n'
usage += s * 2 + light_green('list add') + \
' will add specific person to a list owned by you.' + \
' You will be asked for list\'s name and person\'s name.\n'
usage += s * 2 + light_green('list rm') + \
' will remove specific person from a list owned by you.' + \
' You will be asked for list\'s name and person\'s name.\n'
usage += s * 2 + light_green('list sub') + \
' will subscribe you to a specific list.\n'
usage += s * 2 + light_green('list unsub') + \
' will unsubscribe you from a specific list.\n'
usage += s * 2 + light_green('list own') + \
' will show all list owned by you.\n'
usage += s * 2 + light_green('list new') + \
' will create a new list.\n'
usage += s * 2 + light_green('list update') + \
' will update a list owned by you.\n'
usage += s * 2 + light_green('list del') + \
' will delete a list owned by you.\n'
printNicely(usage)
开发者ID:thameera,项目名称:rainbowstream,代码行数:35,代码来源:rainbow.py
示例6: muting
def muting():
"""
List muting user
"""
t = Twitter(auth=authen())
# Init cursor
next_cursor = -1
rel = {}
# Cursor loop
while next_cursor != 0:
list = t.mutes.users.list(
screen_name=g['original_name'],
cursor=next_cursor,
skip_status=True,
include_entities=False,
)
for u in list['users']:
rel[u['name']] = '@' + u['screen_name']
next_cursor = list['next_cursor']
# Print out result
printNicely('All: ' + str(len(rel)) + ' people.')
for name in rel:
user = ' ' + cycle_color(name)
user += color_func(c['TWEET']['nick'])(' ' + rel[name] + ' ')
printNicely(user)
开发者ID:thameera,项目名称:rainbowstream,代码行数:25,代码来源:rainbow.py
示例7: sent
def sent():
"""
Sent direct messages
"""
t = Twitter(auth=authen())
num = c['MESSAGES_DISPLAY']
rel = []
if g['stuff'].isdigit():
num = int(g['stuff'])
cur_page = 1
# Max message per page is 20 so we have to loop
while num > 20:
rel = rel + t.direct_messages.sent(
count=20,
page=cur_page,
include_entities=False,
skip_status=False
)
num -= 20
cur_page += 1
rel = rel + t.direct_messages.sent(
count=num,
page=cur_page,
include_entities=False,
skip_status=False
)
# Display
printNicely('Sent: newest ' + str(len(rel)) + ' messages.')
for m in reversed(rel):
print_message(m)
printNicely('')
开发者ID:thameera,项目名称:rainbowstream,代码行数:31,代码来源:rainbow.py
示例8: notify_follow
def notify_follow(e):
"""
Notify a follow event
"""
# Retrieve info
target = e['target']
if target['screen_name'] != c['original_name']:
return
source = e['source']
created_at = e['created_at']
# Format
source_user = cycle_color(source['name']) + \
color_func(c['NOTIFICATION']['source_nick'])(
' @' + source['screen_name'])
notify = color_func(c['NOTIFICATION']['notify'])(
'followed you')
date = parser.parse(created_at)
clock = fallback_humanize(date)
clock = color_func(c['NOTIFICATION']['clock'])(clock)
meta = c['NOTIFY_FORMAT']
meta = source_user.join(meta.split('#source_user'))
meta = notify.join(meta.split('#notify'))
meta = clock.join(meta.split('#clock'))
meta = emojize(meta)
# Output
printNicely('')
printNicely(meta)
开发者ID:shayanjm,项目名称:rainbowstream,代码行数:27,代码来源:draw.py
示例9: notify_list_user_unsubscribed
def notify_list_user_unsubscribed(e):
"""
Notify a list_user_unsubscribed event
"""
# Retrieve info
target = e['target']
if target['screen_name'] != c['original_name']:
return
source = e['source']
target_object = [e['target_object']] # list of Twitter list
created_at = e['created_at']
# Format
source_user = cycle_color(source['name']) + \
color_func(c['NOTIFICATION']['source_nick'])(
' @' + source['screen_name'])
notify = color_func(c['NOTIFICATION']['notify'])(
'unsubscribed from your list')
date = parser.parse(created_at)
clock = fallback_humanize(date)
clock = color_func(c['NOTIFICATION']['clock'])(clock)
meta = c['NOTIFY_FORMAT']
meta = source_user.join(meta.split('#source_user'))
meta = notify.join(meta.split('#notify'))
meta = clock.join(meta.split('#clock'))
meta = emojize(meta)
# Output
printNicely('')
printNicely(meta)
print_list(target_object, noti=True)
开发者ID:shayanjm,项目名称:rainbowstream,代码行数:29,代码来源:draw.py
示例10: main
def main():
args = parse_arguments()
if not all((args.token, args.token_secret, args.consumer_key, args.consumer_secret)):
print(__doc__)
return 2
# When using twitter stream you must authorize.
auth = OAuth(args.token, args.token_secret, args.consumer_key, args.consumer_secret)
if args.user_stream:
stream = TwitterStream(auth=auth, domain='userstream.twitter.com')
tweet_iter = stream.user()
elif args.site_stream:
stream = TwitterStream(auth=auth, domain='sitestream.twitter.com')
tweet_iter = stream.site()
else:
stream = TwitterStream(auth=auth, timeout=60.0)
tweet_iter = stream.statuses.sample()
# Iterate over the sample stream.
for tweet in tweet_iter:
# You must test that your tweet has text. It might be a delete
# or data message.
if tweet.get('text'):
printNicely(tweet['text'])
开发者ID:adonoho,项目名称:twitter,代码行数:25,代码来源:stream_example.py
示例11: fallback_humanize
def fallback_humanize(date, fallback_format=None, use_fallback=False):
"""
Format date with arrow and a fallback format
"""
# Convert to local timezone
date = arrow.get(date).to('local')
# Set default fallback format
if not fallback_format:
fallback_format = '%Y/%m/%d %H:%M:%S'
# Determine using fallback format or not by a variable
if use_fallback:
return date.datetime.strftime(fallback_format)
try:
# Use Arrow's humanize function
lang, encode = locale.getdefaultlocale()
clock = date.humanize(locale=lang)
except:
# Notice at the 1st time only
if not dg['humanize_unsupported']:
dg['humanize_unsupported'] = True
printNicely(
light_magenta('Humanized date display method does not support your $LC_ALL.'))
# Fallback when LC_ALL is not supported
clock = date.datetime.strftime(fallback_format)
return clock
开发者ID:shayanjm,项目名称:rainbowstream,代码行数:25,代码来源:draw.py
示例12: notify_list_user_subscribed
def notify_list_user_subscribed(e):
"""
Notify a list_user_subscribed event
"""
# Retrieve info
target = e['target']
if target['screen_name'] != c['original_name']:
return
source = e['source']
target_object = [e['target_object']] # list of Twitter list
created_at = e['created_at']
# Format
source_user = cycle_color(source['name']) + \
color_func(c['NOTIFICATION']['source_nick'])(
' @' + source['screen_name'])
notify = color_func(c['NOTIFICATION']['notify'])(
'subscribed to your list')
date = parser.parse(created_at)
date = arrow.get(date).to('local')
lang, encode = locale.getdefaultlocale()
clock = arrow.get(date).to('local').humanize(locale=lang)
clock = color_func(c['NOTIFICATION']['clock'])(clock)
meta = c['NOTIFY_FORMAT']
meta = source_user.join(meta.split('#source_user'))
meta = notify.join(meta.split('#notify'))
meta = clock.join(meta.split('#clock'))
# Output
printNicely('')
printNicely(meta)
print_list(target_object, noti=True)
开发者ID:OMGunDuende,项目名称:rainbowstream,代码行数:30,代码来源:draw.py
示例13: notify_follow
def notify_follow(e):
"""
Notify a follow event
"""
# Retrieve info
target = e['target']
if target['screen_name'] != c['original_name']:
return
source = e['source']
created_at = e['created_at']
# Format
source_user = cycle_color(source['name']) + \
color_func(c['NOTIFICATION']['source_nick'])(
' @' + source['screen_name'])
notify = color_func(c['NOTIFICATION']['notify'])(
'followed you')
date = parser.parse(created_at)
date = arrow.get(date).to('local')
lang, encode = locale.getdefaultlocale()
clock = arrow.get(date).to('local').humanize(locale=lang)
clock = color_func(c['NOTIFICATION']['clock'])(clock)
meta = c['NOTIFY_FORMAT']
meta = source_user.join(meta.split('#source_user'))
meta = notify.join(meta.split('#notify'))
meta = clock.join(meta.split('#clock'))
# Output
printNicely('')
printNicely(meta)
开发者ID:OMGunDuende,项目名称:rainbowstream,代码行数:28,代码来源:draw.py
示例14: notify_retweet
def notify_retweet(t):
"""
Notify a retweet
"""
source = t['user']
created_at = t['created_at']
# Format
source_user = cycle_color(source['name']) + \
color_func(c['NOTIFICATION']['source_nick'])(
' @' + source['screen_name'])
notify = color_func(c['NOTIFICATION']['notify'])(
'retweeted your tweet')
date = parser.parse(created_at)
date = arrow.get(date).to('local')
lang, encode = locale.getdefaultlocale()
clock = arrow.get(date).to('local').humanize(locale=lang)
clock = color_func(c['NOTIFICATION']['clock'])(clock)
meta = c['NOTIFY_FORMAT']
meta = source_user.join(meta.split('#source_user'))
meta = notify.join(meta.split('#notify'))
meta = clock.join(meta.split('#clock'))
# Output
printNicely('')
printNicely(meta)
draw(t=t['retweeted_status'], noti=True)
开发者ID:OMGunDuende,项目名称:rainbowstream,代码行数:25,代码来源:draw.py
示例15: list_update
def list_update(t):
"""
Update a list
"""
slug = raw_input(light_magenta('Your list that you want to update: '))
name = raw_input(light_magenta('Update name (leave blank to unchange): '))
mode = raw_input(light_magenta('Update mode (public/private): '))
description = raw_input(light_magenta('Update description: '))
try:
if name:
t.lists.update(
slug='-'.join(slug.split()),
owner_screen_name=g['original_name'],
name=name,
mode=mode,
description=description)
else:
t.lists.update(
slug=slug,
owner_screen_name=g['original_name'],
mode=mode,
description=description)
printNicely(green(slug + ' list is updated.'))
except:
printNicely(red('Oops something is wrong with Twitter :('))
开发者ID:thameera,项目名称:rainbowstream,代码行数:25,代码来源:rainbow.py
示例16: listen
def listen(self):
self.stream = TwitterStream(auth=self.auth, **self.stream_args)
self.query_args = dict()
if self.filterstr:
# https://dev.twitter.com/docs/streaming-apis/parameters#track
self.query_args['track'] = self.filterstr
if self.filterstr:
self.tweet_iter = self.stream.statuses.filter(**self.query_args)
else:
self.tweet_iter = self.stream.statuses.sample()
for tweet in self.tweet_iter:
if tweet is None:
printNicely("-- None --")
elif tweet is Timeout:
printNicely("-- Timeout --")
elif tweet is HeartbeatTimeout:
printNicely("-- Heartbeat Timeout --")
elif tweet is Hangup:
printNicely("-- Hangup --")
elif tweet.get('text'):
if self.callback:
# We parse the text to sort tweet into right channel
for keywords in self.keywords:
for word in keywords:
r = re.search(word,tweet.get("text"),re.IGNORECASE)
if not r:
continue
else:
tweet["channel"] = "," .join(keywords)
self.callback(json.dumps(tweet))
else:
printNicely("-- Some data: " + str(tweet))
开发者ID:f-breidenstein,项目名称:infowall,代码行数:34,代码来源:twitterstream.py
示例17: show_lists
def show_lists(t):
"""
List list
"""
rel = t.lists.list(screen_name=g['original_name'])
if rel:
print_list(rel)
else:
printNicely(light_magenta('You belong to no lists :)'))
开发者ID:thameera,项目名称:rainbowstream,代码行数:9,代码来源:rainbow.py
示例18: detail_twitter_error
def detail_twitter_error(twitterException):
"""
Display Twitter Errors nicely
"""
data = twitterException.response_data
try:
for m in data.get('errors', dict()):
printNicely(yellow(m.get('message')))
except:
printNicely(yellow(data))
开发者ID:DTVD,项目名称:rainbowstream,代码行数:10,代码来源:util.py
示例19: print_trends
def print_trends(trends):
"""
Display topics
"""
for topic in trends[:c['TREND_MAX']]:
name = topic['name']
url = topic['url']
line = cycle_color(name) + ': ' + color_func(c['TREND']['url'])(url)
printNicely(line)
printNicely('')
开发者ID:kiote,项目名称:rainbowstream,代码行数:10,代码来源:draw.py
示例20: quit
def quit():
"""
Exit all
"""
try:
save_history()
printNicely(green('See you next time :)'))
except:
pass
sys.exit()
开发者ID:kaushikpendurthi,项目名称:rainbowstream,代码行数:10,代码来源:rainbow.py
注:本文中的twitter.util.printNicely函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论