本文整理汇总了Python中twitter.Twitter.tweet方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.tweet方法的具体用法?Python Twitter.tweet怎么用?Python Twitter.tweet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twitter.Twitter
的用法示例。
在下文中一共展示了Twitter.tweet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: twitter_callback
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import tweet [as 别名]
def twitter_callback(self, tweet):
"""Analyzes Trump tweets, trades stocks, and tweets about it."""
# Initialize the Analysis, Logs, Trading, and Twitter instances inside
# the callback to create separate httplib2 instances per thread.
analysis = Analysis(logs_to_cloud=LOGS_TO_CLOUD)
logs = Logs(name="main-callback", to_cloud=LOGS_TO_CLOUD)
# Analyze the tweet.
companies = analysis.find_companies(tweet)
logs.info("Using companies: %s" % companies)
if not companies:
return
# Trade stocks.
trading = Trading(logs_to_cloud=LOGS_TO_CLOUD)
trading.make_trades(companies)
# Tweet about it.
twitter = Twitter(logs_to_cloud=LOGS_TO_CLOUD)
twitter.tweet(companies, tweet)
示例2: _tweet
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import tweet [as 别名]
def _tweet(handle, questions, prefix=None, *suffix):
_title_max = 65
if handle is None:
logging.error("No twitter handle!!")
return -1
t = Twitter(handle)
for q in questions:
status = ""
# Add prefix: [featured]/[unanswered]
if prefix is not None:
status += "[%s] " % prefix
if len(q['title']) > _title_max:
status += "%s... " % q['title'][0:_title_max]
else:
status += "%s " % q['title']
status += q['link']
# NOTE: the suffix is a hashtag!
for item in suffix:
status += " #%s" % item
logging.info("Tweet:[[%s]] length:[[%d]]" % (status, len(status)))
t.tweet(status)
logging.info("%s tweeted %d questions [prefix=%s]" % \
(handle, len(questions), prefix))
return len(questions)
示例3: NDA
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import tweet [as 别名]
class NDA(IRC):
passive_interval = 60 # how long between performing passive, input independent operations like mail
admin_duration = 30 # how long an admin session is active after authenticating with !su
redis_in_prefix = "ndain:"
redis_out_prefix = "ndaout:"
def __init__(self, conf_file):
with open(conf_file, "r", encoding="utf-8") as f:
conf = json.load(f)
address = conf["address"]
port = conf.get("port", 6667)
user = conf["user"]
real_name = conf["real_name"]
nicks = conf["nicks"]
ns_password = conf.get("nickserv_password", None)
logging = conf.get("logging", False)
super().__init__(address, port, user, real_name, nicks, ns_password, logging)
self.channels = [Channel(c) for c in conf["channels"]]
self.admin_password = conf.get("admin_password", "")
self.idle_talk = conf.get("idle_talk", False)
self.auto_tweet_regex = conf.get("auto_tweet_regex", None)
self.youtube_api_key = conf.get("youtube_api_key", None)
self.pastebin_api_key = conf.get("pastebin_api_key", None)
self.reddit_consumer_key = conf.get("reddit_consumer_key", None)
self.reddit_consumer_secret = conf.get("reddit_consumer_secret", None)
self.admin_sessions = {}
self.last_passive = datetime.min
aliases = conf.get("aliases", {})
ignore_nicks = conf.get("ignore_nicks", [])
self.database = Database("nda.db", aliases, ignore_nicks)
tw_consumer_key = conf.get("twitter_consumer_key", None)
tw_consumer_secret = conf.get("twitter_consumer_secret", None)
tw_access_token = conf.get("twitter_access_token", None)
tw_access_secret = conf.get("twitter_access_token_secret", None)
self.twitter = Twitter(tw_consumer_key, tw_consumer_secret, tw_access_token, tw_access_secret)
use_redis = conf.get("use_redis", False)
self.redis, self.redis_sub = None, None
if use_redis:
try:
self.redis = redis.StrictRedis()
self.redis_sub = self.redis.pubsub(ignore_subscribe_messages=True)
self.redis_sub.psubscribe("%s*" % self.redis_in_prefix)
except:
self.log("Couldn't connect to redis, disabling redis support")
self.redis, self.redis_sub = None, None
def unknown_error_occurred(self, error):
for channel in self.channels:
self.send_message(channel.name, "tell proog that a %s occurred :'(" % str(type(error)))
def stopped(self):
self.database.close()
if self.redis_sub is not None:
self.redis_sub.close()
def connected(self):
self.admin_sessions = {}
self.last_passive = datetime.utcnow()
for channel in self.channels:
self._join(channel.name)
def message_sent(self, to, message):
# redis logging
if self.redis is not None:
self.redis.publish("%s%s" % (self.redis_out_prefix, to), message)
# add own message to the quotes database
if self.get_channel(to) is not None:
timestamp = int(datetime.utcnow().timestamp())
self.database.add_quote(to, timestamp, self.current_nick(), message, full_only=True)
def main_loop_iteration(self):
# check for external input
self.redis_input()
# perform various passive operations if the interval is up
if (datetime.utcnow() - self.last_passive).total_seconds() < self.passive_interval:
return
# check if any nicks with unread messages have come online (disabled for now)
# unread_receivers = self.database.mail_unread_receivers()
# if len(unread_receivers) > 0:
# self._ison(unread_receivers)
# check if it's time to talk
if self.idle_talk:
for channel in self.channels:
if channel.idle_timer.can_talk():
seq_id = 0
quote = self.database.random_quote(channel=channel.name, stringify=False)
if quote is not None:
message, author, date, seq_id = quote
self.send_message(channel.name, message)
channel.add_history(
#.........这里部分代码省略.........
示例4: len
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import tweet [as 别名]
import requests, random
from english import English
from twitter import Twitter
url = 'http://earthquake.usgs.gov/earthquakes/feed' \
'/v1.0/summary/significant_hour.geojson'
test_url = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_month.geojson'
r = requests.get(url)
if r.status_code == 200:
if len(r.json()['features']) > 0:
s = English(r.json())
t = Twitter()
t.tweet(s.sentence())
else:
print "Error: Status code {}".format(r.status_code)