2009-06-04 8 views

답변

10
@echo off & setlocal 
:: Supports curl, wget, plink, and nc 

set SoUID=YOUR UID HERE 
:: Example: set SoUID=49849 
set SoHost=stackoverflow.com 

set FlairPath=/users/flair/%SoUID%.json 
set FlairURL=http://%SoHost%%FlairPath% 
set TempTag=%SoHost%-%SoUID%-%random% 
set TempFile=%TEMP%\%TempTag%.json 
set Script=%TEMP%\%TempTag%.script 
set RawOut=%TEMP%\%TempTag%.out 

call :Check curl 
if not "%App%"=="" "%App%" -o "%TempFile%" -s "%FlairURL%" & goto :Next 

call :Check wget 
if not "%App%"=="" "%App%" -O "%TempFile%" -q "%FlairURL%" & goto :Next 

call :Check plink 
if not "%App%"=="" call :MakeScript & "%App%" -raw %SoHost% -P 80 -batch "%RawOut%" & goto :NextHdr 

call :Check nc 
if not "%App%"=="" call :MakeScript & "%App%" %SoHost% 80 "%RawOut%" & goto :NextHdr 

>&2 echo curl, wget, plink or netcat not found. Downloading plink from PuTTY site. 
set App=%TEMP%\plink.exe 
call :Mirror ftp.chiark.greenend.org.uk /users/sgtatham/putty-latest/x86/plink.exe 
if not exist "%App%" call :Mirror ftp.samurai.com /pub/putty/putty-latest/x86/plink.exe 
if not exist "%App%" call :Mirror ftp.totem.fix.no /pub/mirrors/putty/putty-latest/x86/plink.exe 
if not exist "%App%" call :Mirror ftp.ds5.agh.edu.pl /pub/putty/putty-latest/x86/plink.exe 
if not exist "%App%" goto :NoApp 
call :MakeScript & "%App%" -raw %SoHost% -P 80 -batch "%RawOut%" & del "%App%" & goto :NextHdr 
:Mirror 
if exist "%App%" del "%App%" 
> "%Script%" echo=lcd "%TEMP%" 
>>"%Script%" echo=binary 
>>"%Script%" echo=get %~2 
>>"%Script%" echo=bye 
ftp -s:"%Script%" -A -v -i %~1 > nul 2> nul 
goto :EOF 
:NextHdr 
for /f "usebackq tokens=1,* delims=:" %%a in ("%RawOut%") do (
    if [%%a]==[{"id"] set Flair=%%a:%%b & del "%Script%" "%RawOut%" & goto :Next2 
) 
:NoApp 
>&2 echo Giving up. & goto :EOF 
:Next 
if not exist "%TempFile%" echo Error downloading data. & goto :EOF 
set /p Flair=&2 echo Something went bad. 
) else (
    if "%SoName%"=="" (
     echo Your reputation is %SoReputation%. 
    ) else (
     echo Reputation of %SoName% is %SoReputation%. 
    ) 
) 
goto :EOF 
:Parse 
if "%~1"=="" goto :EOF 
set Line=%~1 
shift 
if /i "%Line:~0,11%"=="reputation:" (
    set SoReputation=%Line:~11% 
    goto :Parse 
) 
if /i "%Line:~0,12%"=="displayName:" (
    set SoName=%Line:~12% 
    goto :Parse 
) 
goto :Parse 
:Check 
set App= 
for %%e in (%PATHEXT%) do for %%i in (%1%%e) do if NOT "%%~$PATH:i"=="" set App=%%~$PATH:i 
goto :EOF 
:MakeScript 
> "%Script%" echo=GET %FlairPath% HTTP/1.1 
>>"%Script%" echo=Host: %SoHost% 
>>"%Script%" echo=Connection: close 
>>"%Script%" echo= 
goto :EOF 
+2

powershell이 ​​windows 명령 행 스크립트를 향상시키는 방법에 대한 좋은 예입니다. – eKek0

3

:를 통해 사용 가능한 사용자에 대한

있습니다
start iexplore http://stackoverflow.com/users/flair/{your UID here}.html 
+0

iexplore가 기본적으로 경로에없는 것을 제외하고는. – grawity

+1

내가 액세스 할 수있는 모든 Windows 상자에 있습니다. XP, Vista, 2003, 7 – Hardwareguy

+3

iexplore를 생략하면 기본 브라우저에서 열립니다. 오페라 또는 파이어 폭스. –

0

더 정교한 데이터 (JSON) :

http://stackoverflow.com/users/rep/50475/2009-01-01/2009-01-31 

해당 문자열을 구문 분석하여 흥미로운 데이터를 얻을 수 있습니다. Jon Skeet은 그의 rep tracker에 이것을 사용합니다.

관련 문제