Пример #1
0
        private static void ReadTweet(string _text, string _id, DateTime _date)
        {
            if (_text.StartsWith("Sol"))
            {
                int beg, end;

                var wi = new WeatherInfo();
                beg = _text.IndexOf("(") + 1;
                end = _text.IndexOf(")", beg);
                if (beg > 0 && end > 0)
                {
                    DateTime _temp = DateTime.MinValue;
                    if (DateTime.TryParse(_text.Substring(beg, end - beg), out _temp))
                    {
                        wi.Date = _temp;
                    }
                }

                beg = _text.IndexOf("): ", beg) + 3;
                end = _text.IndexOf(",", beg);
                if (beg > 2 && end > 2)
                {
                    wi.Explanation = _text.Substring(beg, end - beg);
                }

                beg = _text.IndexOf("high ", beg) + 5;
                end = _text.IndexOf("C/", beg);
                if (beg > 4 && end > 4)
                {
                    wi.HighTempC = double.Parse(_text.Substring(beg, end - beg).Replace(',', '.'), parseStyle, CultureInfo.InvariantCulture);
                }

                beg = _text.IndexOf("C/", beg) + 2;
                end = _text.IndexOf("F", beg);
                if (beg > 1 && end > 1)
                {
                    wi.HighTempF = double.Parse(_text.Substring(beg, end - beg).Replace(',', '.'), parseStyle, CultureInfo.InvariantCulture);
                }

                beg = _text.IndexOf("low ", beg) + 4;
                end = _text.IndexOf("C/", beg);
                if (beg > 3 && end > 3)
                {
                    wi.LowTempC = double.Parse(_text.Substring(beg, end - beg).Replace(',', '.'), parseStyle, CultureInfo.InvariantCulture);
                }

                beg = _text.IndexOf("C/", beg) + 2;
                end = _text.IndexOf("F", beg);
                if (beg > 1 && end > 1)
                {
                    wi.LowTempF = double.Parse(_text.Substring(beg, end - beg).Replace(',', '.'), parseStyle, CultureInfo.InvariantCulture);
                }

                if (wi.HighTemp < wi.LowTemp)
                {
                    var temp = wi.HighTempC;
                    wi.HighTempC = wi.LowTempC;
                    wi.LowTempC  = temp;

                    temp         = wi.HighTempF;
                    wi.HighTempF = wi.LowTempF;
                    wi.LowTempF  = temp;
                }

                beg = _text.IndexOf("at ", beg) + 3;
                end = _text.IndexOf("hPa", beg);
                if (beg > 2 && end > 2)
                {
                    wi.Pressure = double.Parse(_text.Substring(beg, end - beg).Replace(',', '.'), parseStyle, CultureInfo.InvariantCulture);
                }

                beg = _text.IndexOf("wind ", beg) + 5;
                end = _text.IndexOf(" at ", beg);
                if (beg > 4 && end > 4)
                {
                    wi.WindDir = (WindDirection)Enum.Parse(typeof(WindDirection), _text.Substring(beg, end - beg));
                }

                beg = _text.IndexOf(" at ", beg) + 4;
                end = _text.IndexOf("kmh", beg);
                if (beg > 3 && end > 3)
                {
                    wi.WindSpeed = double.Parse(_text.Substring(beg, end - beg).Replace(',', '.'), parseStyle, CultureInfo.InvariantCulture);
                }

                if (wi.Date > Date_Min && wi.Pressure > 0)
                {
                    WeatherInfos.Add(wi);
                }
            }
            else
            {
                Tweets.Add(new Tweet()
                {
                    Text = _text, Date = _date, URL = "https://twitter.com/MarsWxReport/status/" + _id
                });
            }
        }
Пример #2
0
        private static void ReadTweet(string _text, string _id, DateTime _date)
        {
            if (_text.StartsWith("Sol")) {
            int beg, end;

            var wi = new WeatherInfo();
            beg = _text.IndexOf("(") + 1;
            end = _text.IndexOf(")", beg);
            if (beg > 0 && end > 0) {
              DateTime _temp = DateTime.MinValue;
              if (DateTime.TryParse(_text.Substring(beg, end - beg), out _temp)) wi.Date = _temp;
            }

            beg = _text.IndexOf("): ", beg) + 3;
            end = _text.IndexOf(","  , beg);
            if (beg > 2 && end > 2) wi.Explanation = _text.Substring(beg,end - beg);

            beg = _text.IndexOf("high ", beg) + 5;
            end = _text.IndexOf("C/"   , beg);
            if (beg > 4 && end > 4) wi.HighTempC = double.Parse(_text.Substring(beg, end - beg).Replace(',','.'), parseStyle, CultureInfo.InvariantCulture);

            beg = _text.IndexOf("C/", beg) + 2;
            end = _text.IndexOf("F" , beg);
            if (beg > 1 && end > 1) wi.HighTempF = double.Parse(_text.Substring(beg, end - beg).Replace(',','.'), parseStyle, CultureInfo.InvariantCulture);

            beg = _text.IndexOf("low " , beg) + 4;
            end = _text.IndexOf("C/"   , beg);
            if (beg > 3 && end > 3) wi.LowTempC  = double.Parse(_text.Substring(beg, end - beg).Replace(',','.'), parseStyle, CultureInfo.InvariantCulture);

            beg = _text.IndexOf("C/", beg) + 2;
            end = _text.IndexOf("F" , beg);
            if (beg > 1 && end > 1) wi.LowTempF  = double.Parse(_text.Substring(beg, end - beg).Replace(',','.'), parseStyle, CultureInfo.InvariantCulture);

            if (wi.HighTemp < wi.LowTemp) {
              var temp = wi.HighTempC;
              wi.HighTempC = wi.LowTempC;
              wi.LowTempC  = temp;

              temp = wi.HighTempF;
              wi.HighTempF = wi.LowTempF;
              wi.LowTempF  = temp;
            }

            beg = _text.IndexOf("at ", beg) + 3;
            end = _text.IndexOf("hPa", beg);
            if (beg > 2 && end > 2) wi.Pressure  = double.Parse(_text.Substring(beg, end - beg).Replace(',','.'), parseStyle, CultureInfo.InvariantCulture);

            beg = _text.IndexOf("wind ", beg) + 5;
            end = _text.IndexOf(" at " , beg);
            if (beg > 4 && end > 4) wi.WindDir = (WindDirection)Enum.Parse(typeof(WindDirection), _text.Substring(beg, end - beg));

            beg = _text.IndexOf(" at ", beg) + 4;
            end = _text.IndexOf("kmh" , beg);
            if (beg > 3 && end > 3) wi.WindSpeed = double.Parse(_text.Substring(beg, end - beg).Replace(',','.'), parseStyle, CultureInfo.InvariantCulture);

            if (wi.Date > Date_Min && wi.Pressure > 0) WeatherInfos.Add(wi);
              } else {
            Tweets.Add(new Tweet() { Text = _text, Date = _date, URL = "https://twitter.com/MarsWxReport/status/" + _id });
              }
        }