如何使用命令提示符脚本查看我的声誉?
(回复StackOverflow reputation using PowerShell,因为我很无聊.)
@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,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