public static GeoCoordinates ParseGeoCoordinates(string input) { var match = Regex.Match(input, GeoCoordinatesRegex); if (!match.Success) { return(null); } var geoCoordinates = new GeoCoordinates(); var latitude = Convert.ToDouble(match.Groups["lat"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); var longitude = Convert.ToDouble(match.Groups["long"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); if (Math.Abs(latitude) > 180) { Log.Debug("Latitude is lower than -180 or higher than 180 for input {0}", input); return(null); } if (Math.Abs(longitude) > 180) { Log.Debug("Longitude is lower than -180 or higher than 180 for input {0}", input); return(null); } geoCoordinates.Latitude = latitude; geoCoordinates.Longitude = longitude; return(geoCoordinates); }
public List <SniperInfo> parseMessage(string message) { var snipeList = new List <SniperInfo>(); var lines = message.Split(new[] { '\r', '\n' }); foreach (var input in lines) { sniperInfo = new SniperInfo(); GeoCoordinates geoCoordinates = GeoCoordinatesParser.parseGeoCoordinates(input); if (geoCoordinates == null) { Log.Debug($"Can't get coords from line: {input}"); continue; } else { sniperInfo.Latitude = geoCoordinates.latitude; sniperInfo.Longitude = geoCoordinates.longitude; } double iv = IVParser.parseIV(input); sniperInfo.IV = iv; parseTimestamp(input); PokemonId pokemon = PokemonParser.parsePokemon(input); sniperInfo.Id = pokemon; snipeList.Add(sniperInfo); } return(snipeList); }
public static GeoCoordinates parseGeoCoordinates(string input) { Match match = Regex.Match(input, @"(?<lat>\-?\d+(?:[\,|\.]\d+)?)[,|\s]+(?<long>\-?\d+(?:[\,|\.]\d+)?)"); if (match.Success) { GeoCoordinates geoCoordinates = new GeoCoordinates(); var latitude = Convert.ToDouble(match.Groups["lat"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); var longitude = Convert.ToDouble(match.Groups["long"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); if (Math.Abs(latitude) > 180) { Log.Debug("latitude is lower than -180 or higher than 180 for input {0}", input); return null; } if (Math.Abs(longitude) > 180) { Log.Debug("longitude is lower than -180 or higher than 180 for input {0}", input); return null; } geoCoordinates.latitude = latitude; geoCoordinates.longitude = longitude; return geoCoordinates; } return null; }
public static GeoCoordinates parseGeoCoordinates(string input) { Match match = Regex.Match(input, @"(?<lat>\-?\d+(?:[\,|\.]\d+)?)[,|\s]+(?<long>\-?\d+(?:[\,|\.]\d+)?)"); if (match.Success) { GeoCoordinates geoCoordinates = new GeoCoordinates(); var latitude = Convert.ToDouble(match.Groups["lat"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); var longitude = Convert.ToDouble(match.Groups["long"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); if (Math.Abs(latitude) > 180) { Log.Debug("latitude is lower than -180 or higher than 180 for input {0}", input); return(null); } if (Math.Abs(longitude) > 180) { Log.Debug("longitude is lower than -180 or higher than 180 for input {0}", input); return(null); } geoCoordinates.latitude = latitude; geoCoordinates.longitude = longitude; return(geoCoordinates); } return(null); }
public static GeoCoordinates ParseGeoCoordinates(string input) { var match = Regex.Match(input, GeoCoordinatesRegex); if (!match.Success) return null; var geoCoordinates = new GeoCoordinates(); var latitude = Convert.ToDouble(match.Groups["lat"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); var longitude = Convert.ToDouble(match.Groups["long"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); if (Math.Abs(latitude) > 180) { Log.Debug("Latitude is lower than -180 or higher than 180 for input {0}", input); return null; } if (Math.Abs(longitude) > 180) { Log.Debug("Longitude is lower than -180 or higher than 180 for input {0}", input); return null; } geoCoordinates.Latitude = latitude; geoCoordinates.Longitude = longitude; return geoCoordinates; }
public static GeoCoordinates parseGeoCoordinates(string input) { Match match = Regex.Match(input, @"(?<lat>\-?\d+[\,|\.]\d+)[,|\s]*(?<long>\-?\d+[\,|\.]\d+)"); if (match.Success) { GeoCoordinates geoCoordinates = new GeoCoordinates(); geoCoordinates.latitude = Convert.ToDouble(match.Groups["lat"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); geoCoordinates.longitude = Convert.ToDouble(match.Groups["long"].Value.Replace(',', '.'), CultureInfo.InvariantCulture); return geoCoordinates; } return null; }
private static ScanResult ScanLocation(GeoCoordinates location) { var formatter = new NumberFormatInfo { NumberDecimalSeparator = "." }; var offset = 0.001; // 0.003 = half a mile; maximum 0.06 is 10 miles if (offset < 0.001) offset = 0.003; if (offset > 0.06) offset = 0.06; var boundLowerLeftLat = location.Latitude - offset; var boundLowerLeftLng = location.Longitude - offset; var boundUpperRightLat = location.Latitude + offset; var boundUpperRightLng = location.Longitude + offset; var uri = $"http://skiplagged.com/api/pokemon.php?bounds={boundLowerLeftLat.ToString(formatter)},{boundLowerLeftLng.ToString(formatter)},{boundUpperRightLat.ToString(formatter)},{boundUpperRightLng.ToString(formatter)}"; ScanResult scanResult; try { var request = WebRequest.CreateHttp(uri); request.Accept = "application/json"; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36\r\n"; request.Method = "GET"; request.Timeout = 15000; request.ReadWriteTimeout = 32000; using (var resp = request.GetResponse()) { using (var reader = new StreamReader(resp.GetResponseStream())) { var fullresp = reader.ReadToEnd() .Replace(" M", "Male") .Replace(" F", "Female") .Replace("Farfetch'd", "Farfetchd") .Replace("Mr.Maleime", "MrMime"); scanResult = JsonConvert.DeserializeObject<ScanResult>(fullresp); } } } catch (Exception ex) { Log.Debug("Error querying skiplagged", ex); scanResult = new ScanResult { Status = "fail", pokemons = new List<PokemonLocation>() }; } return scanResult; }