Twitterskript
Postat: 14 jun 2009, 15:16
Jag har skrivit ett skript som gör att man kan twittra från bash:
spara skriptet som "twitter.sh" och kör sedan:
sedan startas skriptet med
Du behöver
curl och
xmlstarlet för att det skall funka
Lite mer om skriptet finns på min blogg: http://mickenordin.se/blog/index.php/20 ... er-i-bash/
edit: har uppdaterat skriptet
spara skriptet som "twitter.sh" och kör sedan:
Kod: Markera allt
chmod +x twitter.sh
Kod: Markera allt
./twitter.sh


Kod: Markera allt
#!/bin/bash
###############################
# Dependencies: #
# curl xmlstarlet #
# #
# Written by: #
# Micke Nordin 2009 #
# #
# License: #
# http://sam.zoy.org/wtfpl/ #
# #
# Note: #
# You can create a file #
# called user.inc and place #
# it in the same dirctory #
# as twitter.sh. #
# This file should contain #
# your username and password #
# in this format: #
# #
# username=your_username_here #
# password=your_password_here #
# #
# and nothing else #
###############################
function auth()
{
filename="`dirname $0`/user.inc"
if [ -f "$filename" ]; then
source "$filename"
else
echo "Enter username: "
read username
echo "Enter password (nothing is shown on screen): "
stty_orig=`stty -g`
stty -echo
read password
stty $stty_orig
fi
}
function tweet()
{
echo "What is your tweet?"
read tweet
curl -u $username:$password -d status="$tweet" http://twitter.com/statuses/update.xml &> /dev/null
}
function update()
{
curl -g -u $username:$password http://twitter.com/statuses/friends_timeline.rss -s | xmlstarlet sel --template --match "/rss/channel/item/description" --value-of "." --nl
}
function public()
{
curl -g http://twitter.com/statuses/public_timeline.rss -s | xmlstarlet sel --template --match "/rss/channel/item/description" --value-of "." --nl
}
function follow()
{
echo "Who do you want to follow?"
read follower
curl -u $username:$password -d "" "http://twitter.com/friendships/create/$follower.xml?follow=true" &> /dev/null
}
function unfollow()
{
echo "Who do you want to unfollow?"
read unfollower
curl -u $username:$password -d "" "http://twitter.com/friendships/destroy/$unfollower.xml" &> /dev/null
}
function loop()
{
choice=""
while [ "$choice" != "q" ]; do
echo "choose f/h(help)/p/q/s/t/u"
read choice
if [ "$choice" = "f" ]; then
follow
fi
if [ "$choice" = "h" ]; then
echo "f = follow
h = this cruft
p = see public timeline
q = quit
s = send tweet
t = see updates on your timeline
u = unfollow"
fi
if [ "$choice" = "t" ]; then
update
fi
if [ "$choice" = "p" ]; then
public
fi
if [ "$choice" = "s" ]; then
tweet
fi
if [ "$choice" = "u" ]; then
unfollow
fi
done
}
auth
loop
exit 0
edit: har uppdaterat skriptet