Ejemplo n.º 1
0
        static public void updateAll()
        {
            List <News_Source> insertData = new List <News_Source>();

            var connection = SqliteHelper.DBContext("NewsRss_URL.db");

            using (connection)
            {
                connection.Open();

                //Read the newly inserted data
                var selectCmd = connection.CreateCommand();
                selectCmd.CommandText = "SELECT * FROM NewsRssURL";


                List <News_Source> tempList = new List <News_Source>();
                RssReader          rss      = new RssReader();
                using (var reader = selectCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tempList = rss.getNews(reader["rssURL"].ToString());
                        insertData.AddRange(tempList);
                    }
                }
            }
            post(insertData);
        }
Ejemplo n.º 2
0
        //
        // Send Lastest News URL to telegram
        //
        static public void send()
        {
            List <News_Source> newsdata = new List <News_Source>();

            var connection = SqliteHelper.DBContext("NewsRss_URL.db");

            using (connection)
            {
                connection.Open();

                //Get News Rss URL List
                var selectCmd = connection.CreateCommand();
                selectCmd.CommandText = "SELECT * FROM NewsRssURL";

                List <News_Source> tempList = new List <News_Source>();
                RssReader          rss      = new RssReader();
                using (var reader = selectCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tempList = rss.getNews(reader["rssURL"].ToString());
                        newsdata.AddRange(tempList);
                    }
                }
            }

            newsdata.ForEach(o => {
                var count = 0;
                //Get lastest Date of News in Database
                var lstDt = NewsFeeds.getLstDt(o) == "" ? "1911-01-01 00:00" : NewsFeeds.getLstDt(o);
                //send data
                o.newsList.ForEach(item => {
                    //only get newest news
                    if (DateTime.Compare(Convert.ToDateTime(item.pubDate), Convert.ToDateTime(lstDt)) > 0)
                    {
                        TelegramBot.send(item);
                        count++;
                    }
                });
                Console.WriteLine("{0} has {1} news", o.title, count);
            });
            NewsFeeds.updateAll();
        }