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}))
If you think of twitter as a tool that you can just say to yourself against the wall, you don't need to look at the TL or check the posting results, so it's really just a function to post.
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]}))
It is a fine adjustment version. It is completed in one line on the command line, and double-byte characters, del key, and BS key are all right, but this time, if symbols such as () are mixed, emoticons cannot be used. Mmmmm
Usage
$ tweet2.py You can enter it here immediately. BS is possible. But the half-width symbol is weak
Is it possible to solve it when doing something else? If you come up with it, make fine adjustments.
Recommended Posts