Shell script para Twitter [RESOLVIDO]

25. Re: Shell script para Twitter [RESOLVIDO]

Raimundo Alves Portela
rai3mb

(usa Outra)

Enviado em 23/09/2011 - 22:53h

fabio escreveu:

Posta o código completo aqui omitindo seu login/senha.



#!/bin/bash
#Twitter tweeter by http://360percents.com
#v1.1 on May 12th 2011

#REQUIRED PARAMS
username="usuario@gmail.com"
password="minhasenhadificil"
tweet="$*" #must be less than 140 chars

#EXTRA OPTIONS
uagent="Mozilla/7.0" #user agent (fake a browser)
sleeptime=0 #add pause between requests

if [ $(echo "${tweet}" | wc -c) -gt 140 ]; then
echo "[FAIL] Tweet is over 140 chars!" && exit 1
fi

touch "cookie.txt" #create a temp. cookie file

#INITIAL PAGE
echo "[+] Fetching twitter.com..." && sleep $sleeptime
initpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" "https://mobile.twitter.com/session/new"`
token=`echo "$initpage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//'`

#LOGIN
echo "[+] Submitting the login form..." && sleep $sleeptime
loginpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" -d "authenticity_token=$token&username=$username&password=$password" "https://mobile.twitter.com/session"`

#HOME PAGE
echo "[+] Getting your twitter home page..." && sleep $sleeptime
homepage=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" "http://mobile.twitter.com/"`

#TWEET
echo "[+] Posting a new tweet..." && sleep $sleeptime
tweettoken=`echo "$homepage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//' | tail -n 1`
update=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" -d "authenticity_token=$tweettoken&tweet[text]=$tweet&tweet[display_coordinates]=false" "http://mobile.twitter.com/"`

#LOGOUT
echo "[+] Logging out..."
logout=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" "http://mobile.twitter.com/session/destroy"`

rm "cookie.txt"



  


26. Re: Shell script para Twitter [RESOLVIDO]

Geraldo Albuquerque
AprendiNoLinux

(usa Ubuntu)

Enviado em 23/09/2011 - 22:54h


#!/bin/bash
#Twitter tweeter by http://360percents.com
#v1.1 on May 12th 2011

#REQUIRED PARAMS
username="aprendizlinux@xxxx.xxx.br"
password="NaoVouFornecer"
tweet="$*" #must be less than 140 chars

#EXTRA OPTIONS
uagent="Mozilla/5.0" #user agent (fake a browser)
sleeptime=0 #add pause between requests

if [ $(echo "${tweet}" | wc -c) -gt 140 ]; then
echo "[FAIL] Tweet is over 140 chars!" && exit 1
fi

touch "cookie.txt" #create a temp. cookie file

#INITIAL PAGE
echo "[+] Fetching twitter.com..." && sleep $sleeptime
initpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" "https://mobile.twitter.com/session/new"`
token=`echo "$initpage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//'`

#LOGIN
echo "[+] Submitting the login form..." && sleep $sleeptime
loginpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" -d "authenticity_token=$token&username=$username&password=$password" "https://mobile.twitter.com/session"`

#HOME PAGE
echo "[+] Getting your twitter home page..." && sleep $sleeptime
homepage=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" "http://mobile.twitter.com/"`

#TWEET
echo "[+] Posting a new tweet..." && sleep $sleeptime
tweettoken=`echo "$homepage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//' | tail -n 1`
update=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" -d "authenticity_token=$tweettoken&tweet1=$tweet&tweet[display_coordinates]=false" "http://mobile.twitter.com/"`

#LOGOUT
echo "[+] Logging out..."
logout=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent" "http://mobile.twitter.com/session/destroy"`

rm "cookie.txt"




27. Re: Shell script para Twitter [RESOLVIDO]

Geraldo Albuquerque
AprendiNoLinux

(usa Ubuntu)

Enviado em 23/09/2011 - 22:56h

rai3mb escreveu:

#EXTRA OPTIONS
uagent="Mozilla/7.0" #user agent (fake a browser)
sleeptime=0 #add pause between requests



ahhhhhhh vc mudou aqui rsrs.



28. Re: Shell script para Twitter [RESOLVIDO]

Raimundo Alves Portela
rai3mb

(usa Outra)

Enviado em 23/09/2011 - 22:58h

AprendiNoLinux escreveu:

rai3mb escreveu:

#EXTRA OPTIONS
uagent="Mozilla/7.0" #user agent (fake a browser)
sleeptime=0 #add pause between requests



ahhhhhhh vc mudou aqui rsrs.


Faz diferença não, também funciona com o "Mozilla/5.0 "

Obs.: Não me acostumei com o code ;-)


29. Re: Shell script para Twitter [RESOLVIDO]

Geraldo Albuquerque
AprendiNoLinux

(usa Ubuntu)

Enviado em 23/09/2011 - 22:59h

Copiei a sua versão e salvei por cima. Erros...


./tweeter.sh "Testando via #ShellScript..."
[+] Fetching twitter.com...
./tweeter.sh: command substitution: linha 22: fim do arquivo inesperado enquanto procurava por `"'
./tweeter.sh: command substitution: linha 23: erro de sintaxe: fim prematuro do arquivo
[+] Submitting the login form...
./tweeter.sh: command substitution: linha 27: fim do arquivo inesperado enquanto procurava por `"'
./tweeter.sh: command substitution: linha 28: erro de sintaxe: fim prematuro do arquivo
[+] Getting your twitter home page...
./tweeter.sh: command substitution: linha 31: fim do arquivo inesperado enquanto procurava por `"'
./tweeter.sh: command substitution: linha 32: erro de sintaxe: fim prematuro do arquivo
[+] Posting a new tweet...
./tweeter.sh: command substitution: linha 36: fim do arquivo inesperado enquanto procurava por `"'
./tweeter.sh: command substitution: linha 37: erro de sintaxe: fim prematuro do arquivo
[+] Logging out...
./tweeter.sh: command substitution: linha 40: fim do arquivo inesperado enquanto procurava por `"'
./tweeter.sh: command substitution: linha 41: erro de sintaxe: fim prematuro do arquivo




30. Re: Shell script para Twitter [RESOLVIDO]

Geraldo Albuquerque
AprendiNoLinux

(usa Ubuntu)

Enviado em 23/09/2011 - 23:01h

Resolvido os erros rsrs, mas tuitar mesmo nem a porretada.


31. Re: Shell script para Twitter [RESOLVIDO]

Fábio Berbert de Paula
fabio

(usa Debian)

Enviado em 23/09/2011 - 23:04h

Opa, o meu (ops, o do Raimundo) funcionou agora!



32. Re: Shell script para Twitter [RESOLVIDO]

Raimundo Alves Portela
rai3mb

(usa Outra)

Enviado em 23/09/2011 - 23:06h

AprendiNoLinux escreveu:

Resolvido os erros rsrs, mas tuitar mesmo nem a porretada.


Aqui continua que é uma beleza:
http://mobile.twitter.com/rai3mb/status/117418711022964736

Acho que vai ficar para desafio, aprender linha a linha do script e ver porque eu consigo usar (sendo que não mudei nadinha além de login e senha) e o perfil de vocês não está aceitando..

Abraços


33. Re: Shell script para Twitter [RESOLVIDO]

Raimundo Alves Portela
rai3mb

(usa Outra)

Enviado em 23/09/2011 - 23:10h

AprendiNoLinux escreveu:

Resolvido os erros rsrs, mas tuitar mesmo nem a porretada.


Companheiro, já tentou executar ele em debug??

bash -x
./tweet.sh "Dessa vez vai!!!!!!!!!!!!"

Vê se dar para ver onde ocorre algum problema, ou parada, alguma pista.


34. Re: Shell script para Twitter [RESOLVIDO]

Geraldo Albuquerque
AprendiNoLinux

(usa Ubuntu)

Enviado em 23/09/2011 - 23:10h

rai3mb escreveu:
Aqui continua que é uma beleza:
http://mobile.twitter.com/rai3mb/status/117418711022964736

Acho que vai ficar para desafio, aprender linha a linha do script e ver porque eu consigo usar (sendo que não mudei nadinha além de login e senha) e o perfil de vocês não está aceitando..

Abraços


kkkk q ódio não conseguir fazer funcionar
https://twitter.com/#!/AprendiNoLinux/status/117420266300248066



35. Re: Shell script para Twitter [RESOLVIDO]

Geraldo Albuquerque
AprendiNoLinux

(usa Ubuntu)

Enviado em 23/09/2011 - 23:11h

rai3mb escreveu:

Companheiro, já tentou executar ele em debug??

bash -x
./tweet.sh "Dessa vez vai!!!!!!!!!!!!"

Vê se dar para ver onde ocorre algum problema, ou parada, alguma pista.


Vou tentar com o -x agora.


36. Re: Shell script para Twitter [RESOLVIDO]

Raimundo Alves Portela
rai3mb

(usa Outra)

Enviado em 23/09/2011 - 23:12h

Esse script quebra um galho, dar para automatizar parabéns para você ;-)

@AprendiNoLinux, olha com calma, ver os pontos onde erros podem ocorrer, veja esse negócio de SSL, não sei muito bem, mas acho que você vai conseguir!