Skip to content

Instantly share code, notes, and snippets.

@nor0x
Created June 5, 2020 11:43
Show Gist options
  • Save nor0x/6494814144e2a10b8dae56e6a0b0c49a to your computer and use it in GitHub Desktop.
Save nor0x/6494814144e2a10b8dae56e6a0b0c49a to your computer and use it in GitHub Desktop.
C# script to download images from TPDNE
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