Skip to content

Instantly share code, notes, and snippets.

@CultureGridNE
Created September 13, 2010 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CultureGridNE/577079 to your computer and use it in GitHub Desktop.
Save CultureGridNE/577079 to your computer and use it in GitHub Desktop.
twitterbot
@echo off
rem ==============================
rem test for user input
rem ==============================
if [%1]==[] goto error
if [%2]==[] goto error
rem ==============================
rem set password and user name
rem ==============================
set user=%1
set pass=%2
rem ==============================
rem set url
rem ==============================
set url="http://www.culturegrid.org.uk/discover/xsl/default?operation=searchRetrieve&version=1.1&query=dcterms.isPartOf+adj+%%22BeamishTreasures%%22+OR+dcterms.isPartOf+adj+%%22Bowes%%22+OR+dcterms.isPartOf+adj+%%22DurhamCountyCouncil%%22+OR+dcterms.isPartOf+adj+%%22Farne%%22+OR+dcterms.isPartOf+adj+%%22TWImagine%%22+OR+dcterms.isPartOf+adj+%%22iSeeGateshaed%%22+OR+dcterms.isPartOf+adj+%%22BedesWorld%%22"
rem ==============================
rem get number of records
rem ==============================
set xsl=xml sel -N "srw=http://www.loc.gov/zing/srw/" -T -t -v //srw:numberOfRecords
for /f %%a in ('curl -s %url%^|%xsl%') do set numberOfRecords=%%a
rem ==============================
rem set random number
rem ==============================
:loop
set rand=%random%
if %rand% == 0 goto :loop
if %rand% GTR %numberOfRecords% goto :loop
rem ==============================
rem concat record selection to url
rem ==============================
set url="%url:~1,-1%&startRecord=%rand%&maximumRecords=1"
set xsl=xml sel -T -t -m //doc -v "substring-after(str[@name='dc.related.link'],'http://')"
rem ==============================
rem set searchdate
rem ==============================
for /f %%a in ('doff yyyy-mm-ddThh:mi:ss') do set searchdate=%%a
rem ==============================
rem set status
rem ==============================
for /f "tokens=*" %%a in ('curl -s %url%^|%xsl%^|sed "s/:/%%253A/g;s/&/%%26/g"') do set status="status=%searchdate% http://%%a"
rem ==============================
rem twitter
rem ==============================
curl --basic --user "%user%:%pass%" --data-ascii %status% http://api.supertweet.net/1/statuses/update.xml >nul
rem ==============================
rem unset variables
rem ==============================
for %%a in (rand,url,xsl,user,pass,status,searchdate) do set %%a=
goto EOF
:error
echo.
echo ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
echo ³ CultureGridNE v1.5 ³
echo ³ twitterbot with OAUTH proxy ³
echo ³ Mike Hirst ³
echo ³ 09:28 13 September 2010 ³
echo ³ requires: ³
echo ³ cURL http://curl.haxx.se/ ³
echo ³ xmlstarlet http://xmlstar.sourceforge.net/ ³
echo ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
echo.
echo Usage: CultureGridNE [username] [password]
echo.
pause
cls
:EOF
@CultureGridNE
Copy link
Author

As of Sept 2010 Twitter will no longer allow basic authentication. v1.4 will not authenticate. v1.5 rewritten to include OAUTH proxy via http://api.supertweet.net/

@CultureGridNE
Copy link
Author

OAUTH authentication is now imlemented using Python.

http://mikehirst.netfirms.com/twitt_r/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment