You are on page 1of 2

{

"data": {

"sender": "0923452502973",

"datetime": "dd-mm-yyyy hh:mm:ss",

"message": "TRACK from 20004504,Speed:0Km/h,Location: http://maps.google.com/maps?


hl=en&q=+24.87347,+67.05525 2019-12-11 1:21"

,[+][-]?[\d]+[.][\d]*

[HttpPost]
[HttpRoute("smsfetcher/{unitid}")]
public int smsfetcher(string unitid)
{
try
{

if (unitid != "")
{

JObject rss = JObject.Parse(unitid);

//Save Sender
Data.sender = (long)rss["data"]["sender"];

//Save Datetime
Data.datetime = (string)rss["data"]["datetime"];

//Save Message
string path = (string)rss["data"]["message"];

path = path.Replace(" ", "");

//Save Message
Data.message = RegexItemExtractor(path, @"(TRACKfrom)[0-9]+");

//Save Speed
Data.speed = RegexItemExtractor(path, @"[0-9]+(Km/h)");

//Save Timestamp
Data.timestamp = RegexItemExtractor(path, @"(19|20)\d\d[- /.]
(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])(?:(1|21):[0-9][0-9])");

path = Regex.Replace(path, @"(19|20)\d\d[- /.](0[1-9]|1[012])[-


/.](0[1-9]|[12][0-9]|3[01])(?:(1|21):[0-9][0-9])", "");

//Save Location
Data.location = RegexItemExtractor(path,
@"(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=
%&/~+#-])?");

return 1;
}
else
{
return 0;
}

}
catch (Exception ex)
{
return 0;
}
}

public static string RegexItemExtractor(string text, string pattern)


{

Regex currencyRegex = new Regex(pattern);


Match match = currencyRegex.Match(text);
if (match.Success)
{
return match.ToString();
}
return " ";
}

public static class Data


{
public static long sender { get; set; }

public static string datetime { get; set; }

public static string path { get; set; }

public static string message { get; set; }

public static string speed { get; set; }

public static string location { get; set; }

public static string timestamp { get; set; }

You might also like