Created
December 3, 2015 09:48
-
-
Save marionette-of-u/9d0b0ad7810425d9a4e8 to your computer and use it in GitHub Desktop.
旧geocitiesの生きているサイトを探します。
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Net.Http; | |
using System.IO; | |
using System.Windows.Forms; | |
namespace GeocitiesExplore | |
{ | |
class Program | |
{ | |
static async Task<string> GetWebPageAsync(Uri uri) | |
{ | |
using (HttpClient client = new HttpClient()) | |
{ | |
client.DefaultRequestHeaders.Add( | |
"User-Agent", | |
"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"); | |
client.DefaultRequestHeaders.Add("Accept-Language", "ja-JP"); | |
client.Timeout = TimeSpan.FromSeconds(10.0); | |
try | |
{ | |
return await client.GetStringAsync(uri); | |
} | |
catch (Exception) | |
{ | |
} | |
return null; | |
} | |
} | |
static string[] communityArray = | |
{ | |
"WallStreet", | |
"EpicureanTable", | |
"Colosseum", | |
"SiliconValley", | |
"SilkRoad", | |
"Technopolis", | |
"Berkeley", | |
"Heartland", | |
"Hollywoodv", | |
"Playtown", | |
"Broadway", | |
"Milano", | |
"Milkyway", | |
"MotorCity" | |
}; | |
[STAThreadAttribute] | |
static void Main(string[] args) | |
{ | |
if (args.Length != 3 || args.Length != 4) | |
{ | |
Console.Write("usage: geoexplore community n m [copy]\n- community\n0 WallStreet\n1 EpicureanTable\n2 Colosseum\n3 SiliconValley\n4 SilkRoad\n5 Technopolis\n6 Berkeley\n7 Heartland\n8 Hollywood\n9 Playtown\n10 Broadway\n11 Milano\n12 Milkyway\n13 MotorCity\n\n- n, m\n1000~9999\n"); | |
return; | |
} | |
int communityNum = 0; | |
try | |
{ | |
bool find = false; | |
for (int i = 0; i < communityArray.Length; ++i) | |
{ | |
if (args[0] == communityArray[i]) | |
{ | |
communityNum = i; | |
find = true; | |
break; | |
} | |
} | |
if (!find) | |
{ | |
communityNum = int.Parse(args[0]); | |
if (communityNum < 0 || communityNum >= communityArray.Length) | |
{ | |
throw new Exception(); | |
} | |
} | |
} | |
catch (Exception) | |
{ | |
Console.WriteLine("Invalid community, {0}.", args[0]); | |
return; | |
} | |
int addressN; | |
try | |
{ | |
addressN = int.Parse(args[1]); | |
if (addressN < 1000 || addressN > 9999) | |
{ | |
throw new Exception(); | |
} | |
} | |
catch (Exception) | |
{ | |
Console.WriteLine("Invalid address (n), {0}.", args[1]); | |
return; | |
} | |
int addressM; | |
try | |
{ | |
addressM = int.Parse(args[2]); | |
if (addressM < 1000 || addressM > 9999) | |
{ | |
throw new Exception(); | |
} | |
} | |
catch (Exception) | |
{ | |
Console.WriteLine("Invalid address (m), {0}.", args[2]); | |
return; | |
} | |
bool copy = false; | |
if (args.Length == 4 && args[3] == "copy") | |
{ | |
copy = true; | |
} | |
for (int i = addressN; i <= addressM; ++i) | |
{ | |
string str = "http://www.geocities.co.jp/" + communityArray[communityNum] + "/" + i.ToString() + "/"; | |
Console.Write(str); | |
Task<string> result = GetWebPageAsync(new Uri(str)); | |
result.Wait(); | |
if (result == null || result.Result == null || result.Result.IndexOf("<frame src=\"http://info.geocities.yahoo.co.jp/attachments/404_NotFoundUser.html\">") != -1) | |
{ | |
Console.WriteLine(" - 404."); | |
} | |
else | |
{ | |
Console.WriteLine(" - found."); | |
if (copy) | |
{ | |
Clipboard.SetText(str); | |
Console.ReadKey(); | |
} | |
} | |
} | |
Console.WriteLine("Finish."); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment