本文整理汇总了Python中twitter.read_token_file函数的典型用法代码示例。如果您正苦于以下问题:Python read_token_file函数的具体用法?Python read_token_file怎么用?Python read_token_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_token_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: connect_to_twitter
def connect_to_twitter(self):
oauth_token, oauth_secret = twitter.read_token_file('account_credentials')
consumer_key, consumer_secret = twitter.read_token_file('app_credentials')
authpoop = twitter.OAuth(oauth_token, oauth_secret,
consumer_key, consumer_secret)
self.rest_t = twitter.Twitter(auth=authpoop )
self.stream_t = twitter.TwitterStream(domain='userstream.twitter.com',auth=authpoop,timeout=30)
开发者ID:kaytwo,项目名称:tellmeaboutyourday,代码行数:8,代码来源:tellme.py
示例2: twitter_init
def twitter_init():
try:
config_settings["twitter_creds_file"] = os.path.abspath(
os.path.expanduser(config_settings["twitter_creds_file"])
)
if not os.path.exists(config_settings["twitter_creds_file"]):
twitter.oauth_dance(
"fuzzer_stats",
config_settings["twitter_consumer_key"],
config_settings["twitter_consumer_secret"],
config_settings["twitter_creds_file"],
)
oauth_token, oauth_secret = twitter.read_token_file(config_settings["twitter_creds_file"])
twitter_instance = twitter.Twitter(
auth=twitter.OAuth(
oauth_token,
oauth_secret,
config_settings["twitter_consumer_key"],
config_settings["twitter_consumer_secret"],
)
)
return twitter_instance
except (twitter.TwitterHTTPError, URLError):
print_err("Network error, twitter login failed! Check your connection!")
sys.exit(1)
开发者ID:zined,项目名称:afl-utils,代码行数:25,代码来源:afl_stats.py
示例3: tweet
def tweet(entry, conf, dryrun=False):
"""Send a tweet with the title, link and tags from an entry. The first time you
need to authorize Acrylamid but than it works without any interaction."""
key = "6k00FRe6w4SZfqEzzzyZVA"
secret = "fzRfQcqQX4gcZziyLeoI5wSbnFb7GGj2oEh10hnjPUo"
creds = os.path.expanduser('~/.twitter_oauth')
if not os.path.exists(creds):
twitter.oauth_dance("Acrylamid", key, secret, creds)
oauth_token, oauth_token_secret = twitter.read_token_file(creds)
t = twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_token_secret, key, secret))
tweet = u"New Blog Entry: {0} {1} {2}".format(entry.title,
helpers.joinurl(conf['www_root'], entry.permalink),
' '.join([u'#' + helpers.safeslug(tag) for tag in entry.tags]))
print(' ', bold(blue("tweet ")), end='')
print('\n'.join(wrap(tweet.encode('utf8'), subsequent_indent=' '*13)))
if not dryrun:
try:
t.statuses.update(status=tweet.encode('utf8'))
except twitter.api.TwitterError as e:
try:
log.warn("%s" % json.loads(e.response_data)['error'])
except (ValueError, TypeError):
log.warn("Twitter: something went wrong...")
开发者ID:naufraghi,项目名称:acrylamid,代码行数:29,代码来源:ping.py
示例4: tweet
def tweet(config, in_queue, flag, session_mutex):
oauth_token, oauth_secret = twitter.read_token_file(config.twitter_keys.cred_path)
_twitter = twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_secret, config.twitter_keys.key, config.twitter_keys.secret))
def send_tweet(body):
print("TWEET: Posting tweet...")
_twitter.statuses.update(status=body)
print("TWEET: Complete")
count = 0
flag.wait()
while flag.isSet() or not in_queue.empty():
try:
msg, schedule, uid = in_queue.get(timeout=10)
count += 1
print("\nTWEET ATOM: {0}".format(datetime.fromtimestamp(schedule).strftime("%H:%M:%S %m-%d-%Y")))
with session_mutex:
session = db.Session(config.resources.dbschema)
db.Atom.set_state(db.WAIT, uid, session)
session.commit()
session.close()
## Wait for schedule it hit
while int(time()) < schedule:
if not flag.isSet():
print("TWEET: Warning: Exiting with scheduled tweets. Oh well")
return
else:
sleep(1)
send_tweet(msg)
with session_mutex:
session = db.Session(config.resources.dbschema)
db.Atom.set_state(db.SENT, uid, session)
session.commit()
session.close()
sleep(config.tweet_quota.delta)
if (count % config.tweet_quota.joke_align) == 0:
with session_mutex:
session = db.Session(config.resources.dbschema)
joke = db.Joke.get_next(session)
if joke:
print("SENDING A JOKE")
send_tweet(joke.body)
session.commit()
sleep(config.tweet_quota.delta)
session.close()
except Empty:
sleep(0)
print("Exiting Tweet Engine.")
开发者ID:en0,项目名称:twitterbot,代码行数:59,代码来源:twitterbot.py
示例5: get_twitter
def get_twitter():
MY_TWITTER_CREDS = os.path.expanduser('~/.twitter_oauth')
oauth_token, oauth_secret = read_token_file(MY_TWITTER_CREDS)
t = Twitter(
auth=OAuth(oauth_token, oauth_secret,
CONSUMER_KEY, CONSUMER_SECRET)
)
return t
开发者ID:abadstubner,项目名称:twitter_bots,代码行数:8,代码来源:utils.py
示例6: post_to_twitter
def post_to_twitter(msg):
'''
todo:
check if trigramosaurus has been updated today, if so, skip updating.
'''
oauth_token, oauth_secret = twitter.read_token_file('trigramosaurus_credentials')
consumer_key, consumer_secret = twitter.read_token_file('app_credentials')
t = twitter.Twitter(
auth=twitter.OAuth(oauth_token, oauth_secret,
consumer_key, consumer_secret)
)
try:
result = t.statuses.update(status=msg)
# invalid status causes twitter.api.TwitterHTTPError
except:
error_out("some sort of twitter error",True)
return result
开发者ID:kaytwo,项目名称:trigramosaurus,代码行数:17,代码来源:trigramosaurus.py
示例7: __init__
def __init__ (self, ckey, csecret, token_file, user_name=""):
if not os.path.exists(token_file):
twitter.oauth_dance(user_name, ckey, csecret, token_file)
self.oauth_token, self.oauth_token_secret = twitter.read_token_file(token_file)
self.handle = twitter.Twitter(
auth=twitter.OAuth(self.oauth_token, self.oauth_token_secret,
ckey, csecret))
开发者ID:braynebuddy,项目名称:PyBrayne,代码行数:9,代码来源:iTwitter.py
示例8: tweet
def tweet(entry):
oauth_filename = OPTIONS["oauth_filename"]
oauth_token, oauth_token_secret = read_token_file(oauth_filename)
t = Twitter(auth=OAuth(oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMER_SECRET))
status = "%s" % (entry)
t.statuses.update(status=status)
开发者ID:GEO-IASS,项目名称:OSGeoLive,代码行数:9,代码来源:tweet_helper.py
示例9: get_auth
def get_auth():
"""
Twitter has some bizarre requirements about how to authorize an "app" to
use its API.
The user of the app has to log in to get a secret token. That's fine. But
the app itself has its own "consumer secret" token. The app has to know it,
and the user of the app has to not know it.
This is, of course, impossible. It's equivalent to DRM. Your computer can't
*really* make use of secret information while hiding the same information
from you.
The threat appears to be that, if you have this super-sekrit token, you can
impersonate the app while doing something different. Well, of course you
can do that, because you *have the source code* and you can change it to do
what you want. You still have to log in as a particular user who has a
token that's actually secret, you know.
Even developers of closed-source applications that use the Twitter API are
unsure what to do, for good reason. These "secrets" are not secret in any
cryptographic sense. A bit of Googling shows that the secret tokens for
every popular Twitter app are already posted on the Web.
Twitter wants us to pretend this string can be kept secret, and hide this
secret behind a fig leaf like everybody else does. So that's what we've
done.
"""
from twitter.oauth import OAuth
from twitter import oauth_dance, read_token_file
def unhide(secret):
"""
Do something mysterious and exactly as secure as every other Twitter
app.
"""
return "".join([chr(ord(c) - 0x2800) for c in secret])
fig_leaf = "⠴⡹⠹⡩⠶⠴⡶⡅⡂⡩⡅⠳⡏⡉⡈⠰⠰⡹⡥⡶⡈⡐⡍⡂⡫⡍⡗⡬⡒⡧⡶⡣⡰⡄⡧⡸⡑⡣⠵⡓⠶⠴⡁"
consumer_key = "OFhyNd2Zt4Ba6gJGJXfbsw"
if os.path.exists(AUTH_TOKEN_PATH):
token, token_secret = read_token_file(AUTH_TOKEN_PATH)
else:
authdir = os.path.dirname(AUTH_TOKEN_PATH)
if not os.path.exists(authdir):
os.makedirs(authdir)
token, token_secret = oauth_dance(
app_name="ftfy-tester",
consumer_key=consumer_key,
consumer_secret=unhide(fig_leaf),
token_filename=AUTH_TOKEN_PATH,
)
return OAuth(token=token, token_secret=token_secret, consumer_key=consumer_key, consumer_secret=unhide(fig_leaf))
开发者ID:Riprock,项目名称:python-ftfy,代码行数:56,代码来源:oauth.py
示例10: connect
def connect():
"Prepare an authenticated API object for use."
oauth_token, oauth_secret = twitter.read_token_file(
os.path.expanduser(OAUTH_FILE)
)
t = twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_secret,
CONSUMER_KEY, CONSUMER_SECRET))
return t
开发者ID:larsyencken,项目名称:centrifuge,代码行数:10,代码来源:centrifuge.py
示例11: setup_twitter
def setup_twitter(consumer_key, consumer_secret, credentials_file):
# Authenticate to twitter using OAuth
if not os.path.exists(credentials_file):
twitter.oauth_dance("Tweet to Door Sign Converter", consumer_key,
consumer_secret, credentials_file)
oauth_token, oauth_secret = twitter.read_token_file(credentials_file)
t = twitter.Twitter(auth=twitter.OAuth(
oauth_token, oauth_secret, consumer_key, consumer_secret))
return t
开发者ID:mikerenfro,项目名称:tweetable-office-door-sign,代码行数:11,代码来源:doorsign.py
示例12: get_twitter
def get_twitter():
MY_TWITTER_CREDS = os.path.join(os.path.dirname(__file__), '.clocktweeter_credentials')
if not os.path.exists(MY_TWITTER_CREDS):
twitter.oauth_dance("Trinity clock tweeter", CONSUMER_KEY,
CONSUMER_SECRET, MY_TWITTER_CREDS)
oauth_token, oauth_secret = twitter.read_token_file(MY_TWITTER_CREDS)
t = twitter.Twitter(auth=twitter.OAuth(
oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
return t
开发者ID:ricklupton,项目名称:clocktweeter,代码行数:11,代码来源:clocktweeter.py
示例13: oauth_login
def oauth_login(consumer_key, consumer_secret, access_token, access_token_secret):
if not access_token or not access_token_secret:
oauth_file = './twitter_oauth'
if not os.path.exists(oauth_file):
twitter.oauth_dance("App", consumer_key, consumer_secret, oauth_file)
access_token, access_token_secret = twitter.read_token_file(oauth_file)
auth = twitter.oauth.OAuth(access_token, access_token_secret,
consumer_key, consumer_secret)
return twitter.Twitter(auth=auth)
开发者ID:Bulletninja,项目名称:twitter-wordcloud-bot,代码行数:11,代码来源:twitterapi.py
示例14: tweet
def tweet(self, app_name, version):
MY_TWITTER_CREDS = os.path.expanduser('~/.twitter_oauth')
CONSUMER_KEY, CONSUMER_SECRET = self.load_app_keys()
if not os.path.exists(MY_TWITTER_CREDS):
twitter.oauth_dance("autopkgsays", CONSUMER_KEY, CONSUMER_SECRET,
MY_TWITTER_CREDS)
oauth_token, oauth_secret = twitter.read_token_file(MY_TWITTER_CREDS)
twitter_instance = twitter.Twitter(auth=twitter.OAuth(
oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
# Now work with Twitter
twitter_instance.statuses.update(status="%s version %s has been released" % (app_name, version))
开发者ID:natewalck,项目名称:recipes,代码行数:12,代码来源:TweetChanges.py
示例15: connect
def connect():
global t
# Twitter credentials
CONSUMER_KEY = "JEdRRoDsfwzCtupkir4ivQ"
CONSUMER_SECRET = "PAbSSmzQxbcnkYYH2vQpKVSq2yPARfKm0Yl6DrLc"
MY_TWITTER_CREDS = os.path.expanduser("~/.my_app_credentials")
if not os.path.exists(MY_TWITTER_CREDS):
oauth_dance("Semeval sentiment analysis", CONSUMER_KEY, CONSUMER_SECRET, MY_TWITTER_CREDS)
oauth_token, oauth_secret = read_token_file(MY_TWITTER_CREDS)
t = Twitter(auth=OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
开发者ID:smartinsightsfromdata,项目名称:SemEval-2015,代码行数:12,代码来源:interface_twitter.py
示例16: get_twitter_client
def get_twitter_client():
CONSUMER_KEY = 'mDW8dNVXrioYiSjse9hneaDGy'
CONSUMER_SECRET = 'jg0A2CcHaVSBWfsOqhgABUxQoZUx7sstEk9NSVUbVphkGJr1Zb'
oauth_filename = 'credentials'
if not os.path.exists(oauth_filename):
twitter.oauth_dance("ruukku", CONSUMER_KEY, CONSUMER_SECRET, oauth_filename)
oauth_token, oauth_secret = twitter.read_token_file(oauth_filename)
auth = twitter.OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET)
return twitter.Twitter(auth=auth)
开发者ID:jokallun,项目名称:flow-talks,代码行数:12,代码来源:tweets.py
示例17: __init__
def __init__(self):
if not file.exists(OAUTH_TOKEN_FILE):
oauth_dance("mpvshots",
CONSUMER_KEY,
CONSUMER_SECRET,
OAUTH_TOKEN_FILE)
oauth_token, oauth_secret = read_token_file(OAUTH_TOKEN_FILE)
oauth = OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET)
self._twitter = Twitter(auth=oauth)
self._upload = Twitter(domain="upload.twitter.com", auth=oauth)
开发者ID:slowpoketail,项目名称:mpvshots,代码行数:12,代码来源:twitter.py
示例18: __init__
def __init__( self ):
oauth_token, oauth_token_secret = twitter.read_token_file( config.TWITTER_OAUTH_FILE );
oauth = twitter.OAuth(
oauth_token,
oauth_token_secret,
config.TWITTER_CONSUMER_KEY,
config.TWITTER_CONSUMER_SECRET
);
self.__tw = twitter.Twitter(
auth = oauth,
secure = True,
domain = "api.twitter.com"
);
开发者ID:k3nju,项目名称:favsearch,代码行数:13,代码来源:favreader.py
示例19: connect_twitter
def connect_twitter():
"""Initialize connection to Twitter"""
# authenticate
creds = os.path.expanduser('~/.tweets2sql-oauth')
CONSUMER_KEY = 'mikYMFxbLhD1TAhaztCshA'
CONSUMER_SECRET = 'Ys9VHBWLS5fX4cFnDHSVac52fl388JV19yJz1WMss'
if not os.path.exists(creds):
twitter.oauth_dance("tweets2sql", CONSUMER_KEY, CONSUMER_SECRET, creds)
oauth_token, oauth_secret = twitter.read_token_file(creds)
auth = twitter.OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET)
# connect
return twitter.Twitter(domain='api.twitter.com', auth=auth, api_version = '1.1')
开发者ID:az0,项目名称:tweets2sql,代码行数:13,代码来源:tweets2sql.py
示例20: __init__
def __init__(self, autogen=True, markovdb=os.path.expanduser("~/markov"), twcreds=os.path.expanduser("~/.michiov_twitter_credentials"),twappcreds=os.path.expanduser("~/.michiov_twitter_appdata")):
self.mc = MarkovChain(markovdb)
self.reload()
if not os.path.exists(twappcreds):
print("Lack of app creds")
sys.exit(1)
twcons = json.loads(open(twappcreds).read())
conskey = twcons['key']
conssec = twcons['secret']
while not os.path.exists(twcreds):
twitter.oauth_dance("MPRZ Tech Labs", conskey, conssec, twcreds)
oauth_token, oauth_secret = twitter.read_token_file(twcreds)
self.t = twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_secret, conskey, conssec))
开发者ID:MPRZLabs,项目名称:icarus,代码行数:13,代码来源:reqas.py
注:本文中的twitter.read_token_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论