private static void updateEventDate(CampusEvent Event) { if (Event.Date.Hour == 0) { string time = Event.Time.Split('-')[0].Trim(); if (time.Contains("AM")) { int hour = Int32.Parse(time.Split('A')[0].Trim().Split(':')[0]); int minute = Int32.Parse(time.Split('A')[0].Trim().Split(':')[1]); if (hour == 12) { hour = 0; } Event.Date = Event.Date.AddHours(hour); Event.Date = Event.Date.AddMinutes(minute); CampusEventAPI.UpdateEventDate(Event); } else if (time.Contains("PM")) { int hour = Int32.Parse(time.Split('P')[0].Trim().Split(':')[0]); int minute = Int32.Parse(time.Split('P')[0].Trim().Split(':')[1]); if (hour != 12) { hour = hour + 12; } Event.Date = Event.Date.AddHours(hour); Event.Date = Event.Date.AddMinutes(minute); CampusEventAPI.UpdateEventDate(Event); } } }
private static void readEventFile() { //List<CampusEvent> events = new List<CampusEvent>(); if (File.Exists(event_file_name)) { string[] lines = File.ReadAllLines(event_file_name); CampusEvent Event = null; for (int i = 0; i < lines.Length; i++) { if (lines[i].Contains("id=\"EventTitle")) { Event = new CampusEvent(); Event.Title = lines[i].Split('>')[1].Split('<')[0].Trim(); } if (lines[i + 2].Contains("class=\"info-date\"")) { int month = 0; int day; int year; string temp = lines[i + 2].Split('>')[1].Split('<')[0]; string strmonth = temp.Split(' ')[1]; switch (strmonth) { case "January": month = 1; break; case "February": month = 2; break; case "March": month = 3; break; case "April": month = 4; break; case "May": month = 5; break; case "June": month = 6; break; case "July": month = 7; break; case "August": month = 8; break; case "September": month = 9; break; case "October": month = 10; break; case "November": month = 11; break; case "December": month = 12; break; } Int32.TryParse(lines[i + 2].Split('>')[1].Split(' ')[2].Split(',')[0], out day); Int32.TryParse(lines[i + 2].Split('>')[1].Split('<')[0].Split(' ')[3], out year); DateTime date = new DateTime(year, month, day); if (date < DateTime.Now) { break; } Event.Date = date; } if (lines[i + 2].Contains("class=\"info-time fl\"")) { Event.Time = lines[i + 2].Split('>')[3].Split('<')[0]; } if (lines[i + 3].Contains("class=\"info-location\"")) { Event.Location = lines[i + 3].Split('>')[2].Split('<')[0]; if (Event.Location.Trim() == "") { Event.Location = lines[i + 3].Split('>')[1].Split('<')[0]; } } if (lines[i + 5].Contains("EventType")) { if (Event != null) { Event.Type = new CampusEventType(lines[i + 5].Split('>')[4].Split('<')[0]); } } if (lines[i + 7].Contains("id=\"Department") && !lines[i + 7].Contains("id=\"DepartmentLabel\"")) { if (Event != null) { Event.Organization = lines[i + 7].Split('>')[2].Split('<')[0]; } } else if (lines[i + 9].Contains("id=\"Department")) { if (Event != null) { Event.Organization = lines[i + 9].Split('>')[2].Split('<')[0]; } } if (Event != null) { if (Event.Date == null) { Event.Date = new DateTime(); } if (Event.Location != null) { Event.Location = Event.Location.Replace("&", "&"); } if (Event.Title != null) { Event.Title = Event.Title.Replace("&", "&"); } if (Event.Organization != null) { Event.Organization = Event.Organization.Replace("&", "&"); } if (Event.Date >= DateTime.Now) { CampusEventAPI.AddEvent(Event); break; } } } } }
public static void SendNotifications() { Console.WriteLine("Sending Notifications" + DateTime.Now.ToShortTimeString()); List <string> campuseventtypes = CampusEventAPI.GetCampusEventTypes(); foreach (string str in campuseventtypes) { CampusEventCollection col = new CampusEventCollection(); if (str.Trim() != "") { try { col = CampusEventAPI.GetNextHourEvents(str); } catch { col = new CampusEventCollection(); } } foreach (CampusEvent Event in col.Events) { Process python = new Process(); python.StartInfo.FileName = @"python.exe"; try { if (Event.Organization != null && Event.Location != null) { if (Event.Organization.Trim() != "") { python.StartInfo.Arguments = string.Format("{0} \"{1}\" \"{2}\" \"{3}\" {4}", "C:\\Users\\ryanm\\Documents\\OneDrive\\Android\\notify.py", Event.Title + " - " + Event.Organization, "Today, " + Event.Time + " at " + Event.Location, "/topics/campusevent" + Event.CampusEventID, Event.CampusEventID); } } else if (Event.Location != null) { python.StartInfo.Arguments = string.Format("{0} \"{1}\" \"{2}\" \"{3}\" {4}", "C:\\Users\\ryanm\\Documents\\OneDrive\\Android\\notify.py", Event.Title, "Today, " + col.Events[0].Time + " at " + Event.Location, "/topics/campusevent" + Event.CampusEventID, Event.CampusEventID); } else { python.StartInfo.Arguments = string.Format("{0} \"{1}\" \"{2}\" \"{3}\" {4}", "C:\\Users\\ryanm\\Documents\\OneDrive\\Android\\notify.py", Event.Title, "Today, " + Event.Time, "/topics/campusevent" + Event.CampusEventID, Event.CampusEventID); } } catch (Exception) { } python.StartInfo.UseShellExecute = true; python.Start(); python.WaitForExit(); } } List <string> sports = SportEventAPI.GetSportTypes(); foreach (string str in sports) { string sport = ""; switch (str) { case "Women's Basketball": sport = "womenbasketball"; break; case "Men's Basketball": sport = "menbasketball"; break; case "Baseball": sport = "baseball"; break; case "Football": sport = "football"; break; case "Women's Gymnastics": sport = "womengymnastics"; break; case "Softball": sport = "softball"; break; case "Wrestling": sport = "wrestling"; break; case "Swimming & Diving": sport = "swimmingdiving"; break; } SportEventCollection col = new SportEventCollection(); if (str.Trim() != "") { try { col = SportEventAPI.GetNextHourEvents(str); } catch { col = new SportEventCollection(); } } if (str.Trim() != "" && !str.Contains("Swimming")) { col = SportEventAPI.GetNextHourEvents(str); } foreach (SportEvent Event in col.Events) { Process python = new Process(); python.StartInfo.FileName = @"python.exe"; try { python.StartInfo.Arguments = string.Format("{0} \"{1}\" \"{2}\" \"{3}\" {4}", "C:\\Users\\ryanm\\Documents\\OneDrive\\Android\\notify.py", Event.Sport.Name + " vs. " + Event.Opponent, "Today, " + String.Format("{0:t}", Event.Date) + " at " + Event.Location, "/topics/" + sport, Event.SportEventID); } catch (Exception) { } python.StartInfo.UseShellExecute = true; python.Start(); python.WaitForExit(); } } }