Last active
August 13, 2016 11:01
-
-
Save MykolaBalakin/20722fa24340face5acb0b7739ca78dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Config | |
{ | |
public static Int32 GoodRowMin => 6; | |
public static Int32 GoodRowMax => 9; | |
public static Int32 GoodColumnMin => 8; | |
public static Int32 GoodColumnMax => 17; | |
} | |
void Main() | |
{ | |
while (true) | |
{ | |
Worker(237315); | |
Thread.Sleep(TimeSpan.FromSeconds(30)); | |
} | |
} | |
void Worker(Int32 showtimeId) | |
{ | |
var allSeats = GetHallScheme(showtimeId); | |
var goodSeats = allSeats.Where(s => s.IsGood()).ToList(); | |
if (goodSeats.Count > 0) | |
{ | |
"Founded".Dump(); | |
var player = new SoundPlayer(@"C:\Windows\Media\Alarm01.wav"); | |
player.Play(); | |
} | |
} | |
IEnumerable<Seat> GetHallScheme(Int32 showrimeId) | |
{ | |
var uri = $"http://cabinet.planetakino.ua/Hall/HallScheme?showtimeId={showrimeId}"; | |
var request = HttpWebRequest.CreateHttp(uri); | |
using (var response = request.GetResponse()) | |
using (var stream = response.GetResponseStream()) | |
using (var reader = new StreamReader(stream)) | |
{ | |
var content = reader.ReadToEnd(); | |
var data = XDocument.Parse($"<root>{content}</root>"); | |
var elements = ((IEnumerable<Object>)data.XPathEvaluate("root/div[@class=\"hallContainer\"]/div[@exp-data-row]")).Cast<XElement>(); | |
return elements.Select(div => new Seat | |
{ | |
Row = Int32.Parse(div.Attribute("exp-data-row").Value), | |
Column = Int32.Parse(div.Attribute("exp-data-col").Value) | |
}); | |
} | |
} | |
static class SeatExtensions | |
{ | |
public static Boolean IsGood(this Seat s) | |
{ | |
return s.Row >= Config.GoodRowMin && s.Row <= Config.GoodRowMax && s.Column >= Config.GoodColumnMin && s.Column <= Config.GoodColumnMax; | |
} | |
} | |
class Seat | |
{ | |
public Int32 Row { get; set; } | |
public Int32 Column { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment