3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tweepy2導入

Last updated at Posted at 2013-02-12

コレまで使用していたtweepyがapi1.1に対応していないということでコチラの導入を
https://bitbucket.org/sakito/tweepy
おそらく2013/02/12時点ではeasy_installやpipではなく人力でになるような、多分。。。
Downloadsにある最新版を解凍して出来るtweepy2を丸ごとtweepyと同じ階層にcp -Rでコピーしただけで動きました。

hoge.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-


from oauth2 import Client, Consumer, Token
import tweepy2
consumer_key = ""
consumer_secret = ""
user_key = "-"
user_secret = ""
auth = tweepy2.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(user_key, user_secret)
client = Client(Consumer(consumer_key, consumer_secret),
                Token(user_key, user_secret))
api = tweepy2.API(auth)

今までtweepyと書いていた箇所をtweepy2にしただけでOAuthトークンは問題ないようでした。

tweet.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-

import pywapi
from urllib import urlencode
import datetime
import hoge

result = pywapi.get_weather_from_yahoo('JAXX0043', 'metric')
time = datetime.datetime.now()
ms = time.microsecond

twit = u"@hoge 熊本の現在から今夜くらいの天候は" + result['forecasts'][0]['text'] + u" 気温は最高" \
        + result['forecasts'][0]['high'] \
       + u"で最低が" + result['forecasts'][0]['low'] + u"くらい。" + " #fkdr " + str(ms)

weth = twit.encode("utf-8")
hoge.client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST', urlencode({'status': weth}))

こちらは変更は最終行の投稿部分のurlが変わっただけで動きました。

ウチはtweepy2導入と投稿を投げるurl変更でほぼほぼ問題無さそう。
TLやフォロー・フォロワー取得して色々やってる人の場合は何か障害出てくるかもしれませんが。。。。

3
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?