Exemple #1
0
 public static bool CheckMagicBricksValidity(MagicBricksData data)
 {
     if ((!data.under_construction && data.age_of_property == 0) || data.bedroom_count == 0 || data.bathroom_count == 0 || data.latitude == 0 || data.longitude == 0 || data.id == 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #2
0
        static void ParseMagicBricksData(string inputDir, string outputDir)
        {
            var files = Directory.GetFiles(inputDir);

            foreach (var file in files)
            {
                var housingData = new MagicBricksData();
                housingData.id = int.Parse(Path.GetFileNameWithoutExtension(file));
                var          magicBricksHtml = File.ReadAllText(file);
                HtmlDocument htmlDoc         = new HtmlDocument();
                htmlDoc.LoadHtml(magicBricksHtml);
                var detailNode  = htmlDoc.GetElementbyId("detailOverview");
                var headerNode  = htmlDoc.GetElementbyId("detailHeaderFixed");
                var detailNodes = GetNodesOfAClass(detailNode, "aboutDetail");

                var    detailAddress = GetNodesOfAClass(headerNode, "detailAddress").First().InnerText;
                string address       = detailAddress;
                var    data          = GetLocationData(address);
                housingData.city_name   = data.city_name;
                housingData.pincode     = data.pincode;
                housingData.region_name = data.region_name;
                housingData.latitude    = data.location.lat;
                housingData.longitude   = data.location.lng;

                foreach (var node in detailNodes)
                {
                    var leftColText  = GetNodesOfAClass(node, "leftCol").First().InnerText;
                    var rightColText = GetNodesOfAClass(node, "rightCol").First().InnerText;
                    switch (leftColText)
                    {
                    case "Configuration":
                        housingData.bedroom_count  = int.Parse(rightColText);
                        housingData.bathroom_count = int.Parse(rightColText);
                        break;

                    case "Area":
                        housingData.built_up_area = int.Parse(rightColText);
                        break;

                    case "Status":
                        housingData.under_construction = bool.Parse(rightColText);
                        break;

                    case "Floor Number":
                        housingData.floor_number = int.Parse(rightColText);
                        housingData.floor_count  = int.Parse(rightColText);
                        break;

                    case "Price":
                        housingData.price_per_sqft = int.Parse(rightColText);
                        break;

                    default: continue;
                    }
                }
                housingData.price_per_sqft  = housingData.price_per_sqft / housingData.built_up_area;
                housingData.age_of_property = 0;

                if (!CheckMagicBricksValidity(housingData))
                {
                    Console.WriteLine("Data incomplete");
                    continue;
                }
                File.WriteAllText(Path.Combine(outputDir, string.Format("{0}.json", Path.GetFileNameWithoutExtension(file))), JsonConvert.SerializeObject(housingData));
            }
        }