Ejemplo n.º 1
0
        internal void AddShowSchedule(ShowEntry showentry)
        {
            string sql = string.Format("INSERT INTO TVGuide(Channel,Title,Description,StartTime,Date,Time,Day,Duration,Properties) VALUES ({0},{1},{2},{3},{4},{5},{6},{7},{8})",
                                       showentry.Channel, showentry.Title, showentry.Description, showentry.StartTime, showentry.Date, showentry.Time, showentry.Day, "", showentry.Properties);
            SQLiteResult sqliteResult = SQLite.Exec(DatabasePath, sql);

            if (!sqliteResult.success)
            {
                System.Windows.Forms.MessageBox.Show(String.Format("Error in AddShowSchedule. {0}", sqliteResult.message));
            }
            else
            {
                SQLite.CloseConnection(sqliteResult);
            }
        }
Ejemplo n.º 2
0
        private List <ShowEntry> GetShowList(Channel channel, HtmlAgilityPack.HtmlDocument pageresult, List <string> dateSeparatorList)
        {
            //HtmlAgilityPack.HtmlNodeCollection shows = pageresult.DocumentNode.SelectNodes("//*[starts-with(@id, \"tv\")]/div[contains(@class,\"w2\")]"); // Each node is a show entry.
            HtmlAgilityPack.HtmlNodeCollection shows = pageresult.DocumentNode.SelectNodes("//*/div[starts-with(@class,\"w2\")]"); // Each node is a show entry.
            string descriptionXPath  = "//*[contains(concat( \" \", @class, \" \" ), concat( \" \", \"w5\", \" \" ))]";
            string summaryTimeXPath  = "//*[contains(concat( \" \", @class, \" \" ), concat( \" \", \"w33\", \" \" ))]";
            string showPropertyXPath = "//*[contains(concat( \" \", @class, \" \" ), concat( \" \", \"w4\", \" \" ))]";

            // Iterate the list of shows and group by date
            string           dayoftheweekIndex = dateSeparatorList[0];
            List <ShowEntry> showsofthedayList = new List <ShowEntry>(); // Holds all of the shows for a given day
            string           formattedDate     = GetFormattedShowDate(dayoftheweekIndex);

            foreach (HtmlAgilityPack.HtmlNode show in shows)
            {
                if (String.IsNullOrEmpty(show.InnerText))
                {
                    continue;                                       // Make sure there is an entry
                }
                string match = null;
                try
                {
                    match = dateSeparatorList.Find(stringToCheck => stringToCheck.Equals(show.InnerText));  // Check if the item is a date separator
                }
                catch (Exception ex)
                {
                    match = null;
                }
                if (match != null) // The node is a date separator
                {
                    dayoftheweekIndex = match;
                    formattedDate     = GetFormattedShowDate(dayoftheweekIndex);
                }
                else
                {
                    string   showTitle = String.Empty;
                    DateTime timeStart; // nullable
                    string   description;
                    string   showProperty;
                    string   day  = String.Empty;
                    string   date = String.Empty;
                    string   time = String.Empty;

                    HtmlAgilityPack.HtmlDocument pr = new HtmlAgilityPack.HtmlDocument();
                    pr.LoadHtml(show.InnerHtml);
                    try
                    {
                        string[]    summaryTime = pr.DocumentNode.SelectSingleNode(summaryTimeXPath).InnerText.Split();
                        string      datetime    = formattedDate + " " + summaryTime[0].Trim() + ":00";
                        CultureInfo culture     = new CultureInfo("hu-HU");
                        timeStart    = Convert.ToDateTime(datetime, culture);
                        timeStart    = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(timeStart, TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time").Id, TimeZoneInfo.Local.Id); // Convert to localtime from CET
                        day          = timeStart.DayOfWeek.ToString();
                        date         = timeStart.ToString("d");
                        time         = timeStart.ToString("HH:mm");
                        showTitle    = String.Join(" ", summaryTime.Skip(1).ToArray()); // Remove first item after split
                        description  = pr.DocumentNode.SelectSingleNode(descriptionXPath).InnerText;
                        showProperty = pr.DocumentNode.SelectSingleNode(showPropertyXPath).InnerText;
                        ShowEntry showEntry = new ShowEntry()
                        {
                            Channel     = channel,
                            Title       = showTitle.Trim(),
                            Description = description.Trim(),
                            Properties  = showProperty.Trim(),
                            StartTime   = timeStart,
                            Day         = day,
                            Date        = date,
                            Time        = time,
                        };
                        showsofthedayList.Add(showEntry);
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
            }
            return(showsofthedayList);
        }