Ejemplo n.º 1
0
            /// <summary>
            /// 获取实时数据
            /// </summary>
            private void GetRealTime()
            {
                Data tmp_data;
                bool IsChangeLast = false, IsError = false;

                if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0)
                {
                    IsChangeLast = true;
                    tmp_data     = new Data();
                }
                else
                {
                    tmp_data = new Data(data);
                }

                int pn = 1;
                Article_Real_Data_Template obj = new Article_Real_Data_Template();

                do
                {
                    try
                    {
                        string str = Bas.GetHTTPBodyThrow("https://api.bilibili.com/x/article/creative/article/list?group=0&sort=&pn=" + pn, Account.Instance.Cookies, "https://member.bilibili.com/v2");
                        if (!string.IsNullOrEmpty(str))
                        {
                            obj = JsonConvert.DeserializeObject <Article_Real_Data_Template>(str);
                            if (obj.code == 0)
                            {
                                foreach (Article_Real_Data_Template.Data_Template.Article_Template i in obj.artlist.articles)
                                {
                                    tmp_data._coin_real  += i.stats.coin;
                                    tmp_data._fav_real   += i.stats.favorite;
                                    tmp_data._like_real  += i.stats.like;
                                    tmp_data._reply_real += i.stats.reply;
                                    tmp_data._share_real += i.stats.share;
                                    tmp_data._view_real  += i.stats.view;

                                    if (IsChangeLast)
                                    {
                                        tmp_data._coin_real_last  += i.stats.coin;
                                        tmp_data._fav_real_last   += i.stats.favorite;
                                        tmp_data._like_real_last  += i.stats.like;
                                        tmp_data._reply_real_last += i.stats.reply;
                                        tmp_data._share_real_last += i.stats.share;
                                        tmp_data._view_real_last  += i.stats.view;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        IsError = true;
                    }
                } while (++pn * obj.artlist.page.ps <= obj.artlist.page.total && !IsError);

                //丢弃错误数据
                if (!IsError)
                {
                    data = tmp_data;
                    if (IsChangeLast)
                    {
                        LastTime = DateTime.Compare(DateTime.Now.Date.AddHours(12), DateTime.Now) <= 0 ? DateTime.Now.Date.AddHours(12) : DateTime.Now.Date.AddDays(-1).AddHours(12);//设定为当天12点数据
                    }
                }
            }
Ejemplo n.º 2
0
            /// <summary>
            /// 获取实时数据
            /// </summary>
            private void GetRealTime()
            {
                Data tmp_data;
                bool IsChangeLast = false, IsError = false;

                if (LastTime == null || DateTime.Compare(((DateTime)LastTime).AddDays(1), DateTime.Now) <= 0)
                {
                    tmp_data     = new Data();
                    IsChangeLast = true;
                }
                else
                {
                    tmp_data = new Data(data);
                }

                if (ChargeLastTime == null || DateTime.Compare(((DateTime)ChargeLastTime).AddDays(1), DateTime.Now) < 0)
                {
                    tmp_data._elec_last = GetCharge();
                    ChargeLastTime      = DateTime.Now.Date;//设定为当天0点数据
                }

                int pn                       = 1;
                Video_Real_Data_Template obj = new Video_Real_Data_Template();

                do
                {
                    try
                    {
                        string str = Bas.GetHTTPBodyThrow("https://member.bilibili.com/x/web/archives?status=pubed&pn=" + pn + "&ps=10&coop=1&interactive=1", Account.Instance.Cookies, "https://member.bilibili.com/v2");

                        if (!string.IsNullOrEmpty(str))
                        {
                            obj = JsonConvert.DeserializeObject <Video_Real_Data_Template>(str);

                            if (obj.code == 0)
                            {
                                foreach (Video_Real_Data_Template.Data_Template.Video_Template i in obj.data.arc_audits)
                                {
                                    tmp_data._coin_real    += i.stat.coin;
                                    tmp_data._dm_real      += i.stat.danmaku;
                                    tmp_data._fav_real     += i.stat.favorite;
                                    tmp_data._like_real    += i.stat.like;
                                    tmp_data._play_real    += i.stat.view;
                                    tmp_data._share_real   += i.stat.share;
                                    tmp_data._comment_real += i.stat.reply;

                                    if (IsChangeLast)
                                    {
                                        tmp_data._coin_real_last    += i.stat.coin;
                                        tmp_data._dm_real_last      += i.stat.danmaku;
                                        tmp_data._fav_real_last     += i.stat.favorite;
                                        tmp_data._like_real_last    += i.stat.like;
                                        tmp_data._play_real_last    += i.stat.view;
                                        tmp_data._share_real_last   += i.stat.share;
                                        tmp_data._comment_real_last += i.stat.reply;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        IsError = true;
                    }
                } while (++pn * obj.data.page.ps <= obj.data.page.count && !IsError);

                if (!IsError)
                {
                    data = tmp_data;
                    if (IsChangeLast)
                    {
                        LastTime = DateTime.Compare(DateTime.Now.Date.AddHours(12), DateTime.Now) <= 0 ? DateTime.Now.Date.AddHours(12) : DateTime.Now.Date.AddDays(-1).AddHours(12);//设定为当天12点数据
                    }
                }
            }