Beispiel #1
0
        private static void readSportsFile(string filename)
        {
            int               day         = 1;
            List <string>     events      = new List <string>();
            List <SportEvent> sportevents = new List <SportEvent>();

            if (File.Exists(filename))
            {
                string[] lines = File.ReadAllLines(filename);
                for (int i = 0; i < lines.Length; i++)
                {
                    string eventtype = "";
                    string school    = "";
                    string result    = "";
                    string location  = "";
                    string tvhosting = "";
                    string imageloc  = "";
                    bool   home      = false;
                    int    hour      = 0;
                    int    minute    = 0;
                    int    second    = 0;

                    if (lines[i].Contains("class=\"daynumber\""))
                    {
                        bool valid = false;
                        valid = Int32.TryParse(lines[i].Split('>')[1].Split('<')[0], out day);
                        if (!valid)
                        {
                            day = 1;
                        }
                    }

                    if (lines[i].Contains("=\"LiveEvent"))
                    {
                        eventtype = lines[i].Split('>')[1].Split('<')[0];
                        if (lines[i + 1].Contains("calopplogo"))
                        {
                            school = lines[i + 1].Split('>')[1].Split('<')[0];
                            if (lines[i + 1].Contains("img"))
                            {
                                imageloc = lines[i + 1].Split('=')[1].Split('\"')[1];
                            }
                            if (lines[i + 2].Contains("href="))
                            {
                                result = lines[i + 2].Split('>')[2].Split('<')[0];
                                if (lines[i + 3].Contains("<br>"))
                                {
                                    location = lines[i + 3].Split('>')[1];
                                    if (lines[i + 4].Contains("<br>"))
                                    {
                                        tvhosting = lines[i + 4].Split('>')[1];
                                    }
                                }
                            }
                            else if (lines[i + 2].Contains("<br>") && !lines[i + 2].Contains("href"))
                            {
                                result = lines[i + 2].Split('>')[1];
                                if (lines[i + 3].Contains("<br>"))
                                {
                                    location = lines[i + 3].Split('>')[1];
                                    if (lines[i + 4].Contains("<br>"))
                                    {
                                        tvhosting = lines[i + 4].Split('>')[1];
                                    }
                                }
                            }
                        }
                    }
                    eventtype = eventtype.Replace("&amp;", "&");
                    result    = result.Replace("&amp;", "&");
                    school    = school.Replace("&amp;", "&");
                    location  = location.Replace("&amp;", "&");
                    string homeloc = location.ToLower().Trim();
                    if (homeloc == "pittsburgh, pa" || homeloc == "petersen events center" || homeloc == "pittsburgh, pa." || homeloc == "petersen event center" || homeloc == "charles l. cost field" || homeloc == "vartabedian field")
                    {
                        home = true;
                    }
                    tvhosting = tvhosting.Replace("&amp;", "&");
                    string newevent = eventtype + "!" + school + "!" + result + "!" + location + "!" + tvhosting;
                    newevent = newevent.Replace("&amp;", "&");
                    if (result.Trim() != "")
                    {
                        if (result.Contains(":"))
                        {
                            if (result.Contains("AM"))
                            {
                                hour = Int32.Parse(result.Split(':')[0]);
                            }
                            else
                            {
                                hour = Int32.Parse(result.Split(':')[0]);
                                if (hour != 12)
                                {
                                    hour = hour + 12;
                                }
                            }
                        }
                    }
                    if (newevent.Trim().Length > 4)
                    {
                        SportEvent current = new SportEvent(new DateTime(year, month, day, hour, minute, second), new Sport(eventtype.Trim()), school, result, location, tvhosting, imageloc, home);
                        if (!sportevents.Contains(current) && tvhosting.Trim().Length > 0)
                        {
                            SportEventAPI.AddSportEvent(current);
                        }
                        //SportEventAPI.AddSportEvent(current);
                        events.Add(newevent);
                        sportevents.Add(current);
                    }
                }
            }
            File.WriteAllLines("data.txt", events.ToArray());
        }
        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();
                }
            }
        }