Exemple #1
0
        public void ParsePage(string source, keydowno_backyard_farmerEntities db)
        {
            int start = source.IndexOf("<div id=\"searchresults\">");
            int end = source.IndexOf("<script type=\"text/javascript\">", start);

            string substr = source.Substring(start, end - start);

            string[] stringSeparators = new string[] { "http://rdf.data-vocabulary.org/" }; // separate the different vetshops
            string[] htmlText;
            htmlText = substr.Split(stringSeparators, StringSplitOptions.None); //string with vetshops

            // coords parser start here

            int pointsTemp = source.IndexOf("var point");
            int pointsStart = source.IndexOf(";", pointsTemp);
            int pointsEnd = source.IndexOf("map.bestFit");
            string pointsSubstr = source.Substring(pointsStart, pointsEnd - pointsStart);

            string[] pointSeparator = new string[] { "MQA.LatLng" }; // separate all the coordinates
            string[] pointsResult;
            pointsResult = pointsSubstr.Split(pointSeparator, StringSplitOptions.None); // string with coordinates

               // return htmlText[2];

            for (int i = 1; i < htmlText.Length - 1; i++)
            {
                Vet doctor = new Vet();
                VetsWorkingHour workHours = new VetsWorkingHour();

                doctor.Name = ParseData(htmlText[i], "v:name");
                doctor.Address = ParseData(htmlText[i], "v:street-address");
                doctor.City = ParseData(htmlText[i], "v:locality");
                doctor.State = ParseData(htmlText[i], "v:region");
                doctor.Zip = ParseData(htmlText[i], "v:postal-code");
                doctor.Phone = ParseData(htmlText[i], "v:tel");
                doctor.Image = GetImg(htmlText[i]);

                doctor.Latitude = double.Parse(ParseCoordinates(pointsResult[i])[0]);
                doctor.Longitude = double.Parse(ParseCoordinates(pointsResult[i])[1]);

                workHours.Monday = ParseWorkingHours(htmlText[i], "Mon");
                workHours.Tuesday = ParseWorkingHours(htmlText[i], "Tue");
                workHours.Wednesday = ParseWorkingHours(htmlText[i], "Wed");
                workHours.Thursday = ParseWorkingHours(htmlText[i], "Thu");
                workHours.Friday = ParseWorkingHours(htmlText[i], "Fri");
                workHours.Saturday = ParseWorkingHours(htmlText[i], "Sat");
                workHours.Sunday = ParseWorkingHours(htmlText[i], "Sun");

                db.Vets.Add(doctor);
                workHours.Id = doctor.Id;
                db.VetsWorkingHours.Add(workHours);
                db.SaveChanges();
            }
        }
Exemple #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            int errorCounter = 0;

            keydowno_backyard_farmerEntities db = new keydowno_backyard_farmerEntities();
            //List<string> codes = db.TempZipCodes.Select(x => x.Zip).ToList();
            List<ShittyDeadlocks> items = db.TempZipCodes.Select(i =>
            new ShittyDeadlocks
            {
                Zip = i.Zip,
                City = i.City,
                State = i.State
            }).ToList<ShittyDeadlocks>();
            //var items = db.TempZipCodes.Select(i =>
            //new
            //{
            //    Zip = i.Zip,
            //    City = i.City,
            //    State = i.State
            //});

            foreach (var item in items)
            {
                string zip = item.Zip;
                int zipParsed;
                try
                {
                    zipParsed = int.Parse(zip);
                }
                catch (Exception)
                {
                    continue;
                }
                if (zipParsed < 97220)
                {
                    continue;
                }
                string source = PerformRequest(zip);
                try
                {
                    ParsePage(source, db, item.City, item.State);
                }
                catch (Exception)
                {
                    errorCounter++;
                }
            }

            TextBox1.Text = errorCounter.ToString();
        }
Exemple #3
0
        public void ParsePage(string source, keydowno_backyard_farmerEntities db, string city, string state)
        {
            while (source.IndexOf("// Set up the InfoWindow for this marker.") != -1)
            {
                int start = source.IndexOf("// Set up the InfoWindow for this marker.");
                int end = source.IndexOf("markerArray[maNum] = curMarker;", start);

                string vetInfo = source.Substring(start, end - start);

                source = source.Substring(end);

                //vet phone
                start = vetInfo.IndexOf("<a href=\"tel://");
                end = vetInfo.IndexOf("\">", start);
                string vetPhone = vetInfo.Substring(start + "<a href=\"tel://".Length, end - start - "<a href=\"tel://".Length);
                vetInfo = vetInfo.Substring(end);

                //vet name
                start = vetInfo.IndexOf("curMarker = createMarker(\"");
                end = vetInfo.IndexOf("\",", start);
                string vetName = vetInfo.Substring(start + "curMarker = createMarker(\"".Length, end - start - "curMarker = createMarker(\"".Length);
                vetInfo = vetInfo.Substring(end);

                //vet address
                start = vetInfo.IndexOf("'', \"\", \"");
                end = vetInfo.IndexOf("\",", start + "'', \"\", \"".Length);
                string vetAddress = vetInfo.Substring(start + "'', \"\", \"".Length, end - start - "'', \"\", \"".Length);
                vetInfo = vetInfo.Substring(end);

                string vetZip = vetAddress.Substring(vetAddress.LastIndexOf(' ') + 1);
                try
                {
                    int testZip = int.Parse(vetZip);
                }
                catch (Exception)
                {
                    vetZip = "";
                }

                //vet longitude (strange, but longitude is first here)
                start = vetInfo.IndexOf("'");
                end = vetInfo.IndexOf("',", start);
                string vetLongitude = vetInfo.Substring(start + "'".Length, end - start - "'".Length);
                vetInfo = vetInfo.Substring(end + "',".Length);

                //vet latitude
                start = vetInfo.IndexOf("'");
                end = vetInfo.IndexOf("')", start);
                string vetLatitude = vetInfo.Substring(start + "'".Length, end - start - "'".Length);
                vetInfo = vetInfo.Substring(end);

                Vet doctor = new Vet();
                doctor.Name = vetName;
                doctor.Address = vetAddress;
                doctor.City = city;
                doctor.State = state;
                doctor.Zip = vetZip;
                doctor.Phone = vetPhone;

                doctor.Latitude = double.Parse(vetLatitude, CultureInfo.InvariantCulture);
                doctor.Longitude = double.Parse(vetLongitude, CultureInfo.InvariantCulture);
                db.Vets.Add(doctor);
                db.SaveChanges();
            }
        }
Exemple #4
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            keydowno_backyard_farmerEntities db = new keydowno_backyard_farmerEntities();
            List<string> codes = db.TempZipCodes.Select(x => x.Zip).ToList();

            foreach (var code in codes)
            {
                try
                {
                Thread.Sleep(1000);
                string zip = code.ToString();
                string source = PerformRequest(zip);
                ParsePage(source, db);
                int numPages = GetPagesNum(source);
                Thread.Sleep(1000);

                var a = db.TempZipCodes.Where(x => x.Zip == code).First();
                a.Parsed = true;
                db.SaveChanges();
                }
                catch (Exception)
                {

                    continue;
                }
            }
        }