4
5

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.

コマンドラインからtwitter投稿

Last updated at Posted at 2013-02-19
tweet.py
# !/usr/bin/env python
# -*- coding:UTF-8 -*-

from urllib import urlencode
from oauth2 import Client, Consumer, Token

consumer_key = ""
consumer_secret = ""
user_key = ""
user_secret = ""
client = Client(Consumer(consumer_key, consumer_secret),
        Token(user_key, user_secret))

message = raw_input()
client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST',
        urlencode({'status': message}))

twitterを壁に向かって独り事いうだけのツールと考えればTLを見る必要も投稿結果を確認する必要もないので、本当に投稿するだけの機能しかないです。

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

from urllib import urlencode
from oauth2 import Client, Consumer, Token
import sys

consumer_key = ""
consumer_secret = ""
user_key = ""
user_secret = ""
client = Client(Consumer(consumer_key, consumer_secret),
        Token(user_key, user_secret))

client.request('https://api.twitter.com/1.1/statuses/update.json', 'POST',
        urlencode({'status': sys.argv[1]}))

微調整版です。コマンドライン上で一行で完結し、かつ全角文字もdelキー、BSキーも大丈夫になりましたが今度は()など記号が混ざるとダメで顔文字が使えなかったりします。むーーーー
用法
$ tweet2.py すぐにココに入力できます。BS出来ます。ですが半角記号弱いです

また何か他のことをしている時に解決できそうか?思いついたら微調整をします。

4
5
2

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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?