Created
June 5, 2020 11:43
-
-
Save nor0x/6494814144e2a10b8dae56e6a0b0c49a to your computer and use it in GitHub Desktop.
C# script to download images from TPDNE
This file contains hidden or 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
using System.Net.Http; | |
using System.Threading; | |
Console.WriteLine("Hello world!"); | |
var max=1000; | |
var url="https://www.thispersondoesnotexist.com/image"; | |
using(var client = new HttpClient()) | |
{ | |
for(int i = 0; i < max; i++) | |
{ | |
var guid = Guid.NewGuid().ToString(); | |
var fileInfo = new FileInfo($"{guid}.jpg"); | |
System.Console.WriteLine("downloading: " + guid); | |
var result = await client.GetAsync(url); | |
result.EnsureSuccessStatusCode(); | |
var ms = await result.Content.ReadAsStreamAsync(); | |
var fs = File.Create(fileInfo.FullName); | |
ms.Seek(0, SeekOrigin.Begin); | |
ms.CopyTo(fs); | |
Thread.Sleep(1500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment