Skip to content

Instantly share code, notes, and snippets.

@hsynkrcf
Created February 12, 2024 14:02
Show Gist options
  • Save hsynkrcf/d1c501ba20d757b9a2b5a30a3c61098c to your computer and use it in GitHub Desktop.
Save hsynkrcf/d1c501ba20d757b9a2b5a30a3c61098c to your computer and use it in GitHub Desktop.
Automated Appointment Maker to Spor İstanbul by Selenium
using OpenQA.Selenium;
public static class HourSelector
{
public static (int, int)? SelectHour(IWebElement element, bool isSaturday)
{
const string satHour = "08:00 - 09:00"; // Weekends saturday time
const string eachHours = "18:30 - 19:30"; // Weekdays time
for (int repeater = 0; repeater <= 13; repeater++) // 13 repeater count
{
for (int seans = 0; seans <= 2; seans++)
{
try
{
var hour = element.FindElement(By.Id($"pageContent_rptList_ChildRepeater_{repeater}_lblSeansSaat_{seans}"));
if (isSaturday && hour.Text == satHour)
{
return (repeater, seans);
}
else if (hour.Text == eachHours)
{
return (repeater, seans);
}
}
catch
{
continue;
}
}
}
return null;
}
}
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using SeleniumExtras.WaitHelpers;
const string username = "Kullanıcı Adınız";
const string password = "Parolanız";
const string sporIstUri = "https://online.spor.istanbul/";
ChromeOptions options = new ChromeOptions();
IWebDriver driver = new ChromeDriver(options);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(sporIstUri);
var closeModalButton = driver.FindElement(By.ClassName("modal-footer")).FindElement(By.TagName("button"));
if (closeModalButton is not null)
closeModalButton.Click();
driver.FindElement(By.Id("liUyeGiris"))
.FindElements(By.TagName("a"))[1]
.Click();
driver.FindElement(By.Id("txtTCPasaport")).SendKeys(username); // Replace with the correct id and your username
// Locate and fill the password field
driver.FindElement(By.Id("txtSifre")).SendKeys(password); // Replace with the correct id and your password
// Locate and click the login button
driver.FindElement(By.Id("btnGirisYap")).Click(); // Replace with the correct id
Thread.Sleep(1000);
driver.Navigate().GoToUrl("https://online.spor.istanbul/uyespor");
driver.FindElement(By.Id("pageContent_rptListe_lbtnSeansSecim_0")).Click();
var dayPanels = driver.FindElements(By.ClassName("col-md-1-5"));
foreach (var day in dayPanels)
{
(int, int)? item = null;
var dayName = day.FindElement(By.ClassName("panel-title")); // Because i going to the pool 3 time a week
if (dayName.Text.Contains("Pazartesi"))
{
item = HourSelector.SelectHour(day, false);
}
else if (dayName.Text.Contains("Çarşamba"))
{
item = HourSelector.SelectHour(day, false);
}
else if (dayName.Text.Contains("Cumartesi"))
{
item = HourSelector.SelectHour(day, true);
}
if (item is null)
continue;
try
{
var checkbox = driver.FindElement(By.Id($"pageContent_rptList_ChildRepeater_{item.Value.Item1}_cboxSeans_{item.Value.Item2}"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", checkbox);
}
catch
{
continue;
}
var accept = driver.FindElement(By.Name("ctl00$pageContent$cboxOnay"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", accept);
Thread.Sleep(1000);
// reCAPTCHA iframe'ine geçiş yapılıyor
wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//iframe[contains(@src, 'recaptcha') and not(@title='recaptcha challenge')]")));
// reCAPTCHA checkbox bulunuyor ve tıklanıyor
IWebElement recaptchaCheckbox = wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("div.recaptcha-checkbox-checkmark")));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", recaptchaCheckbox);
Thread.Sleep(1000);
driver.SwitchTo().DefaultContent();
var btnSave = driver.FindElement(By.Id("lbtnKaydet"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", btnSave);
Thread.Sleep(1000);
break;
}
driver.Quit();
@hsynkrcf
Copy link
Author

Yaklaşık 30 dk'da yaptığım bir konsol uygulamasıdır. Schedule edebilirsiniz. Randevu alarak spor yapan sporcular için randevu kontrolü yapar eğer uygun randevu var ise alır. Günleri ve saatleri kendinize göre ayarlayabilirsiniz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment