Twitter post from command line

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

Twitter post from command line
[Lambda] [Python] Post to Twitter from Lambda!
Post from another account with Twitter API
Command line introductory notes
Execute command from Python
Linux command line shortcut
Execute command from python
How to create an article from the command line
Open Chrome version of LINE from the command line [Linux]
Post from Python to Slack
Search for large files on Linux from the command line
Post to Twitter using Python
[Python] Read command line arguments from file name or stdin
How to get a string from a command line argument in python
[EC2] How to install and download chromedriver from the command line
Create custom Django commands and run them from the command line
Receive by standard input or send Gmail from command line operation
Command line argument processing (Python docopt)
Get celebrity tweet history from twitter
Slice notation with command line options
Post from python to facebook timeline
Output from Raspberry Pi to Line
Post multiple Twitter images with python
Post images from Python to Tumblr
Easily post to twitter with Python 3
Get data from Twitter using Tweepy
Get options in Python from both JSON files and command line arguments