예제 #1
0
        public bool Search(Property prop)
        {
            try
            {
                var baseDir = AppContext.BaseDirectory;

                Console.WriteLine($@"Downloading {prop._key}");

                // set prop as Searching
                //prop.Searching = true;
                //prop.SearchingStartDate = DateTime.Now;
                //arango.Update<Property>(prop);


                //if (prop.RealEstateRecords == null || prop.RealEstateRecords.Count == 0)
                //{
                //    var result = RealEstate.SearchRealEstate(prop);
                //    if (result.InvalidAddress)
                //    {
                //        prop.RealEstateInvalidAddress = true;
                //    }
                //    else
                //    {
                //        prop.RealEstateLandSize = result.LandSize;
                //        prop.RealEstateFloorSize = result.FloorArea;
                //        prop.RealEstateYearBuilt = result.YearBuilt;
                //        prop.RealEstateRecords = result.Data;
                //        prop.RealEstateValueRange = result.ValueRange;
                //        prop.RealEstateBedroom = result.Bedroom;
                //        prop.RealEstateBathroom = result.Bathroom;
                //        prop.RealEstateParking = result.Parking;
                //    }
                //}

                if (prop.DomainRecords == null || prop.DomainRecords.Count == 0)
                {
                    var result = Domain.SearchDomain(prop);
                    if (result.InvalidAddress)
                    {
                        prop.DomainInvalidAddress = true;
                    }
                    else
                    {
                        prop.DomainPropertyStory = result.PropertyStory;
                        prop.DomainRecords       = result.Data;
                        prop.DomainLowValue      = result.LowValue;
                        prop.DomainMidValue      = result.MidValue;
                        prop.DomainHighValue     = result.HighValue;
                        prop.DomainBedroom       = result.Bedroom;
                        prop.DomainBathroom      = result.Bathroom;
                        prop.DomainParking       = result.Parking;
                        prop.Lat = result.Lat;
                        prop.Lng = result.Lng;
                    }
                }

                if (prop.RealEstateRecords != null && prop.RealEstateRecords.Count > 0 &&
                    prop.DomainRecords != null && prop.DomainRecords.Count > 0)
                {
                    prop.LastSearchSuccess = true;
                }
                else
                {
                    prop.LastSearchSuccess = false;
                }


                prop.LastSearch = DateTime.Now;

                prop.LastSearchSuccess = prop.DomainRecords != null && prop.RealEstateRecords != null;

                prop.TryCount += 1;

                prop.Searching = false;

                prop.ClientName = Dns.GetHostName();


                Console.WriteLine($@"Download {prop.LastSearchSuccess} {prop._key}");
                Console.WriteLine($@"Time: {prop.LastSearch}");

                File.WriteAllText($@"{CreatePostcodeFolder(prop.Postcode)}/{prop.BuildKey()}.json", JsonConvert.SerializeObject(prop, Formatting.Indented));
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            // --csv=filepath

            Regex csv = new Regex(@"^\-\-csv=");

            var argCsvPath = args.FirstOrDefault(arg => csv.IsMatch(arg));

            var pathCsv = csv.Replace(argCsvPath, "");

            Spider spider = new Spider();

            int    lineNumber     = 0;
            string lineNumberPath = $"{AppContext.BaseDirectory}/line.txt";

            if (File.Exists(lineNumberPath))
            {
                lineNumber = int.Parse(File.ReadAllText(lineNumberPath));

                Console.WriteLine($"Resumed from {lineNumber}");
            }

            int index = 0;

            using (StreamReader csvStreamReader = new StreamReader(pathCsv))
            {
                using (CsvReader csvReader = new CsvReader(csvStreamReader))
                {
                    csvReader.Configuration.BadDataFound = null;
                    // csvReader.Read();

                    while (csvReader.Read())
                    {
                        if (index < lineNumber)
                        {
                            var row  = csvReader.GetRecord <dynamic>();
                            var dict = row as IDictionary <string, object>;
                        }
                        else
                        {
                            var row  = csvReader.GetRecord <dynamic>();
                            var dict = row as IDictionary <string, object>;

                            var prop = new Property();

                            prop.UnitNumber          = dict["UNIT NUMBER"] as string;
                            prop.HouseNumber         = dict["HOUSE NUMBER"] as string;
                            prop.StreetName          = dict["STREET NAME"] as string;
                            prop.StreetType          = dict["STREET TYPE"] as string;
                            prop.StreetSuffix        = dict["STREET SUFFIX"] as string;
                            prop.Suburb              = dict["SUBURB"] as string;
                            prop.Postcode            = dict["POSTCODE"] as string;
                            prop.AddressUseType      = dict["ADDRESS USE TYPE"] as string;
                            prop.WardName            = dict["WARD NAME"] as string;
                            prop.PropertyDescription = dict["PROPERTY DESCRIPTION"] as string;

                            prop.BuildKey();

                            spider.Search(prop);

                            File.WriteAllText(lineNumberPath, index.ToString());
                        }
                        index += 1;
                    }
                }
            }
        }