Advertisement
Guest User

Fake Name Generator API

a guest
Dec 20th, 2016
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.47 KB | None | 0 0
  1. namespace FakeNameGenerator
  2. {
  3.     #region Structs & Enums
  4.     enum Gender
  5.     {
  6.         Male,
  7.         Female
  8.     }
  9.  
  10.     enum NameSet
  11.     {
  12.         American,
  13.         Arabic,
  14.         Australian,
  15.         Brazil,
  16.         Chechen,
  17.         Chinese,
  18.         Croatian,
  19.         Czech,
  20.         Danish,
  21.         Dutch,
  22.         England,
  23.         Eritrean,
  24.         Finnish,
  25.         French,
  26.         German,
  27.         Greenland,
  28.         Hispanic,
  29.         Hobbit,
  30.         Hungarian,
  31.         Icelandic,
  32.         Igbo,
  33.         Italian,
  34.         Japanese,
  35.         Norwegian,
  36.         Persian,
  37.         Polish,
  38.         Russian,
  39.         Scottish,
  40.         Slovenian,
  41.         Swedish,
  42.         Thai,
  43.         Vietnamese
  44.     }
  45.  
  46.     enum Country
  47.     {
  48.         Australia,
  49.         Austria,
  50.         Belgium,
  51.         Brazil,
  52.         Canada,
  53.         Cyprus,
  54.         Czech,
  55.         Denmark,
  56.         Estonia,
  57.         Finland,
  58.         France,
  59.         Germany,
  60.         Greenland,
  61.         Hungary,
  62.         Iceland,
  63.         Italy,
  64.         Netherlands,
  65.         NewZealand,
  66.         Norway,
  67.         Poland,
  68.         Portugal,
  69.         Slovenia,
  70.         SouthAfrica,
  71.         Spain,
  72.         Sweden,
  73.         Switzerland,
  74.         Tunisia,
  75.         UnitedKingdom,
  76.         UnitedStates
  77.     }
  78.  
  79.     struct Identity
  80.     {
  81.         public int Age;
  82.         public string Name;
  83.         public string SSN;
  84.         public string Phone;
  85.         public string Email;
  86.         public string Height;
  87.         public string Weight;
  88.         public string Vehicle;
  89.         public string Company;
  90.         public string Website;
  91.         public string Address;
  92.         public string Username;
  93.         public string Password;
  94.         public string CardType;
  95.         public string Birthday;
  96.         public string BloodType;
  97.         public string UserAgent;
  98.         public string Occupation;
  99.         public string MaidenName;
  100.         public string CardNumber;
  101.         public string CountryCode;
  102.         public string CardExpiration;
  103.     }
  104.     #endregion
  105.  
  106.     class FakeNameGeneratorAPI
  107.     {
  108.         public FakeNameGeneratorAPI() { }
  109.  
  110.         #region Enum Handling
  111.         private string GetCountry(Country c)
  112.         {
  113.             switch (c)
  114.             {
  115.                 case Country.Australia:
  116.                     return "au";
  117.                 case Country.Austria:
  118.                     return "as";
  119.                 case Country.Belgium:
  120.                     return "bg";
  121.                 case Country.Brazil:
  122.                     return "br";
  123.                 case Country.Canada:
  124.                     return "ca";
  125.                 case Country.Cyprus:
  126.                     return "cyen";
  127.                 case Country.Czech:
  128.                     return "cz";
  129.                 case Country.Denmark:
  130.                     return "dk";
  131.                 case Country.Estonia:
  132.                     return "ee";
  133.                 case Country.Finland:
  134.                     return "fi";
  135.                 case Country.France:
  136.                     return "fr";
  137.                 case Country.Germany:
  138.                     return "gr";
  139.                 case Country.Greenland:
  140.                     return "gl";
  141.                 case Country.Hungary:
  142.                     return "hu";
  143.                 case Country.Iceland:
  144.                     return "is";
  145.                 case Country.Italy:
  146.                     return "it";
  147.                 case Country.Netherlands:
  148.                     return "nl";
  149.                 case Country.NewZealand:
  150.                     return "nz";
  151.                 case Country.Norway:
  152.                     return "no";
  153.                 case Country.Poland:
  154.                     return "pl";
  155.                 case Country.Portugal:
  156.                     return "pt";
  157.                 case Country.Slovenia:
  158.                     return "sl";
  159.                 case Country.SouthAfrica:
  160.                     return "za";
  161.                 case Country.Spain:
  162.                     return "sp";
  163.                 case Country.Sweden:
  164.                     return "sw";
  165.                 case Country.Switzerland:
  166.                     return "sz";
  167.                 case Country.Tunisia:
  168.                     return "tn";
  169.                 case Country.UnitedKingdom:
  170.                     return "uk";
  171.                 case Country.UnitedStates:
  172.                     return "us";
  173.                 default: return "us";
  174.             }
  175.         }
  176.  
  177.         private string GetNameSet(NameSet ns)
  178.         {
  179.             switch (ns)
  180.             {
  181.                 case NameSet.American:
  182.                     return "us";
  183.                 case NameSet.Arabic:
  184.                     return "ar";
  185.                 case NameSet.Australian:
  186.                     return "au";
  187.                 case NameSet.Brazil:
  188.                     return "br";
  189.                 case NameSet.Chechen:
  190.                     return "celat";
  191.                 case NameSet.Chinese:
  192.                     return "ch";
  193.                 case NameSet.Croatian:
  194.                     return "hr";
  195.                 case NameSet.Czech:
  196.                     return "cs";
  197.                 case NameSet.Danish:
  198.                     return "dk";
  199.                 case NameSet.Dutch:
  200.                     return "nl";
  201.                 case NameSet.England:
  202.                     return "en";
  203.                 case NameSet.Eritrean:
  204.                     return "er";
  205.                 case NameSet.Finnish:
  206.                     return "fi";
  207.                 case NameSet.French:
  208.                     return "fr";
  209.                 case NameSet.German:
  210.                     return "gr";
  211.                 case NameSet.Greenland:
  212.                     return "gl";
  213.                 case NameSet.Hispanic:
  214.                     return "sp";
  215.                 case NameSet.Hobbit:
  216.                     return "hobbit";
  217.                 case NameSet.Hungarian:
  218.                     return "hu";
  219.                 case NameSet.Icelandic:
  220.                     return "is";
  221.                 case NameSet.Igbo:
  222.                     return "ig";
  223.                 case NameSet.Italian:
  224.                     return "it";
  225.                 case NameSet.Japanese:
  226.                     return "jpja";
  227.                 case NameSet.Norwegian:
  228.                     return "no";
  229.                 case NameSet.Persian:
  230.                     return "fa";
  231.                 case NameSet.Polish:
  232.                     return "pl";
  233.                 case NameSet.Russian:
  234.                     return "ru";
  235.                 case NameSet.Scottish:
  236.                     return "gd";
  237.                 case NameSet.Slovenian:
  238.                     return "sl";
  239.                 case NameSet.Swedish:
  240.                     return "sw";
  241.                 case NameSet.Thai:
  242.                     return "th";
  243.                 case NameSet.Vietnamese:
  244.                     return "vn";
  245.                 default: return "us";
  246.             }
  247.         }
  248.         #endregion
  249.  
  250.         #region Create Identity
  251.         /// <summary>
  252.         /// Returns new Identity with default settings.
  253.         /// </summary>
  254.         /// <returns>Identity</returns>
  255.         public Identity CreateIdentity()
  256.         {
  257.             return CreateIdentity(Gender.Male, NameSet.American, Country.UnitedStates);
  258.         }
  259.  
  260.         /// <summary>
  261.         /// Returns new Identity with gender settings.
  262.         /// </summary>
  263.         /// <param name="g">Male or Female</param>
  264.         /// <returns>Identity</returns>
  265.         public Identity CreateIdentity(Gender g)
  266.         {
  267.             return CreateIdentity(g, NameSet.American, Country.UnitedStates);
  268.         }
  269.  
  270.         /// <summary>
  271.         /// Returns new Identity with gender and nameset settings.
  272.         /// </summary>
  273.         /// <param name="g">Male or Female</param>
  274.         /// <param name="ns">Country origin for name.</param>
  275.         /// <returns>Identity</returns>
  276.         public Identity CreateIdentity(Gender g, NameSet ns)
  277.         {
  278.             return CreateIdentity(g, ns, Country.UnitedStates);
  279.         }
  280.  
  281.         /// <summary>
  282.         /// Returns new Identity with gender, nameset, and country settings.
  283.         /// </summary>
  284.         /// <param name="g">Male or Female</param>
  285.         /// <param name="ns">Country origin for name.</param>
  286.         /// <param name="c">Country origin for Identity.</param>
  287.         /// <returns>Identity</returns>
  288.         public Identity CreateIdentity(Gender g, NameSet ns, Country c)
  289.         {
  290.             Identity id = new Identity();
  291.             try
  292.             {
  293.                 using (WebClient wClient = new WebClient())
  294.                 {
  295.                     string html_source = wClient.DownloadString("http://www.fakenamegenerator.com" + String.Format("/gen-{0}-{1}-{2}.php", (g == Gender.Male) ? "male" : "female", GetNameSet(ns), GetCountry(c)));
  296.  
  297.                     Match m = Regex.Match(html_source, "<h3>(.*?)<");
  298.                     id.Name = m.Groups[1].Value;
  299.  
  300.                     m = Regex.Match(html_source, "\"adr\">\n(.*?)<");
  301.                     string street = m.Groups[1].Value.Trim();
  302.  
  303.                     m = Regex.Match(html_source, ".<br.>(.*?)<.div>");
  304.                     id.Address = (street + " " + m.Groups[1].Captures[0].Value.Trim());
  305.                     //Lazy bug fix
  306.                     if (id.Address.Contains("</br>") || id.Address.Contains("<br>"))
  307.                         id.Address = id.Address.Remove(id.Address.IndexOf('<'), 5);
  308.  
  309.                     m = Regex.Match(html_source, "<.dt>\\n\\s*<dd>(.*)<.");
  310.                     id.MaidenName = m.Groups[1].Value;
  311.  
  312.                     m = Regex.Match(html_source, "SSN<.dt><dd>(.*?)<div class=");
  313.                     id.SSN = (!string.IsNullOrEmpty(m.Groups[1].Value)) ? m.Groups[1].Value : "N/A";
  314.  
  315.                     m = Regex.Match(html_source, "Phone<.dt>\\n\\s*<dd>(.*?)<.dd>");
  316.                     id.Phone = m.Groups[1].Value;
  317.  
  318.                     m = Regex.Match(html_source, "Country code<.dt>\\n\\s*<dd>(.*?)<.dd>");
  319.                     id.CountryCode = m.Groups[1].Value;
  320.  
  321.                     m = Regex.Match(html_source, "Birthday<.dt>\\n\\s*<dd>(.*?)<.dd>");
  322.                     id.Birthday = m.Groups[1].Value;
  323.                     id.Age = (int)(DateTime.Now - Convert.ToDateTime(id.Birthday)).TotalDays / 365;
  324.  
  325.                     m = Regex.Match(html_source, @"Email Address<.dt>\n\n\s*<dd>(.*?)<div");
  326.                     id.Email = m.Groups[1].Value.Trim();
  327.  
  328.                     m = Regex.Match(html_source, @"Username<.dt>\n\s*<dd>(.*?)<.dd>");
  329.                     id.Username = m.Groups[1].Value;
  330.  
  331.                     m = Regex.Match(html_source, @"Password<.dt>\n\s*<dd>(.*?)<.dd>");
  332.                     id.Password = m.Groups[1].Value;
  333.  
  334.                     m = Regex.Match(html_source, @"Website<.dt>\n\s*<dd>(.*?)<.dd>");
  335.                     id.Website = m.Groups[1].Value;
  336.  
  337.                     m = Regex.Match(html_source, @"Browser user agent<.dt>\n\s*<dd>(.*?)<.dd>");
  338.                     id.UserAgent = m.Groups[1].Value;
  339.  
  340.                     m = Regex.Match(html_source, "Finance</h3>(.*?)</dl>", RegexOptions.Singleline);
  341.                     Match m2 = Regex.Match(m.Groups[1].Value, "<dt>(.*?)<.dt>");
  342.                     m = Regex.Match(m.Groups[1].Value, @"<.dt>\n\s*<dd>(.*?)<.dd>");
  343.                     id.CardNumber = m.Groups[1].Value;
  344.                     id.CardType = m2.Groups[1].Value;
  345.  
  346.                     m = Regex.Match(html_source, @"<dt>Expires<.dt>\n\s*<dd>(.*?)</dd>");
  347.                     id.CardExpiration = m.Groups[1].Value;
  348.  
  349.                     m = Regex.Match(html_source, @"<dt>Company<.dt>\n\s*<dd>(.*?)</dd>");
  350.                     id.Company = m.Groups[1].Value;
  351.  
  352.                     m = Regex.Match(html_source, @"<dt>Occupation<.dt>\n\s*<dd>(.*?)</dd>");
  353.                     id.Occupation = m.Groups[1].Value;
  354.  
  355.                     m = Regex.Match(html_source, @"<dt>Height<.dt>\n\s*<dd>(.*?)</dd>");
  356.                     id.Height = m.Groups[1].Value;
  357.  
  358.                     m = Regex.Match(html_source, @"<dt>Weight<.dt>\n\s*<dd>(.*?)</dd>");
  359.                     id.Weight = m.Groups[1].Value;
  360.  
  361.                     m = Regex.Match(html_source, @"<dt>Blood type<.dt>\n\s*<dd>(.*?)<.dd>");
  362.                     id.BloodType = m.Groups[1].Value;
  363.  
  364.                     m = Regex.Match(html_source, @"<dt>Vehicle<.dt>\n\s*<dd>(.*?)<.dd>");
  365.                     id.Vehicle = m.Groups[1].Value;
  366.                 }
  367.             }
  368.             catch(Exception ex)
  369.             {
  370.                 throw ex;
  371.             }
  372.  
  373.             return id;
  374.         }
  375.         #endregion
  376.     }
  377. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement