Python-Twitter インストール

pypi.python.org

こっちだと投稿はできるけどリツイートの仕方がわからなかったので

python-twitterに変更

pypi.python.org

バージョン3からPython3に対応みたいなのでインストール

# バージョン指定でインストール
$ pip install python-twitter==3.0rc1

$ pip install python-twitter
# バージョン指定しないと2.2がインストールされてしまいます

myenigma.hatenablog.com

# ユーザー情報を取得
user = api.GetUser(screen_name = 'imabari119_bot')

# ユーザー名
print(user.screen_name)

# 位置情報
print(user.location)

# 自己紹介
print(user.description)

# 協定世界時とローカルタイムとの時差(秒)
print(user.utc_offset)

# タイムゾーン
print(user.time_zone)

# URL
print(user.url)

# 最新ツイート
print(user.status)

# ツイート数
print(user.statuses_count)

# フォロワー数
print(user.followers_count)

# フォーロー数
print(user.friends_count)

# お気に入り数
print(user.favourites_count)

# タイムラインを取得
timeline = api.GetHomeTimeline()

for tweet in timeline:
    print(tweet.text)

# ユーザーのタイムラインを取得
timeline = api.GetUserTimeline(screen_name = 'imabari119_bot')

for tweet in timeline:
    print(tweet.text)

# ツイート情報を取得
tweet = timeline[0]

# ツイートされた時間(協定世界時)
print(tweet.created_at)

# ツイートされた時間(UNIX秒) 使えない?
print(tweet.created_at_in_seconds)

# お気に入りに入れているか
print(tweet.favorited)

# 返信先のユーザー名
print(tweet.in_reply_to_screen_name)

# 返信先のユーザーID
print(tweet.in_reply_to_user_id)

# 140字を超えているか
print(tweet.truncated)

# ツイートされたクライアント
print(tweet.source)

# ツイートID
print(tweet.id)

# ツイート内容
print(tweet.text)

# ツイートの位置情報
print(tweet.location)

# ツイートされた時間(UNIX秒)?
print(tweet.relative_created_at)

# ツイートしたユーザーの情報
print(tweet.user)


# ユーザーのフォローを取得
friends = api.GetFriends()

for friend in friends:
    print(friend.screen_name)

# ユーザーのフォロワーを取得
followers = api.GetFollowers()

for follower in followers:
    print(follower.screen_name)

# ツイートを投稿
api.PostUpdate('おなかすいた')

# リツイート
tweets=api.GetUserTimeline(screen_name='imabari119_bot')
api.PostRetweet(tweets[0].id)