Last active
March 27, 2024 14:25
-
-
Save davidruhmann/4bb3cab53c51022f74c8 to your computer and use it in GitHub Desktop.
[Batch] [PowerShell] Download Gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:Main <Username> [Destination=CD] | |
call :DownloadGists %1 %2 "%CD%" | |
exit /b | |
:: TODO Support duplicate file names. | |
:: Current pagination limit set to 1000 | |
:DownloadGists <Username> <Destination> ~UI/IO | |
PowerShell -NoProfile -ExecutionPolicy RemoteSigned -Command "$c = New-Object System.Net.WebClient; $c.Headers.Add('user-agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;)'); $c.DownloadString('https://api.github.com/users/%~1/gists?per_page=1000').Split(',') | ForEach { $_.Split('{') | ForEach { $_.Split('}') | ForEach { If ($_.Contains('filename')) { Write-Host ($f = $_.Split([char]0x0022)[3].Replace(([char]0x0022).ToString(), '')) } ElseIf ($_.Contains('raw_url')) { $c.DownloadFile($_.Split([char]0x0022)[3].Replace(([char]0x0022).ToString(), ''), '%~2\' + $f) } } } };" | |
exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The destination directory must exist else the script will throw an exception. If no destination directory is specified, the current working directory is used. The current limit is hard coded to 1000. Update the limit if needed. If there are any duplicate file names, the older file will overwrite the newer.