Пример #1
0
 //分析数据
 private void analysePage(JObject jq, PageFeed pg, bool isSevenDay)
 {
     foreach (var jb in jq["data"]["vHomePageFeed"])
     {
         //判断是否为文章
         if (jb["eFeedType"].ToString() == "1")
         {
             //看是否需要判断七天内
             if (isSevenDay)
             {
                 if (CheckDate(jb["stPostSummary"]["elapseTime"].ToString()))
                 {
                     //文章ID作为唯一值
                     string postID = jb["stPostSummary"]["postId"].ToString();
                     //添加一行数据
                     pg.allPages.Add(postID, new OnePage(postID));
                     pg.pageIDList.Add(postID);
                     //pg.allPages[postID]
                     pg.allPages[postID].nickName   = jb["stPostSummary"]["postUser"]["nickname"].ToString();
                     pg.allPages[postID].PageID     = jb["stPostSummary"]["postId"].ToString();
                     pg.allPages[postID].PageName   = jb["stPostSummary"]["postField"]["title"].ToString();
                     pg.allPages[postID].Date       = jb["stPostSummary"]["elapseTime"].ToString();
                     pg.allPages[postID].praiseNum  = jb["stPostSummary"]["praiseNum"].ToString();
                     pg.allPages[postID].commentNum = jb["stPostSummary"]["commentNum"].ToString();
                     pg.allPages[postID].viewNum    = jb["stPostSummary"]["viewNum"].ToString();
                     pg.allPages[postID].quanName   = jb["stPostSummary"]["simpleInfo"]["circleName"].ToString();
                     pg.allPages[postID].quanID     = jb["stPostSummary"]["simpleInfo"]["circleId"].ToString();
                     pg.allPages[postID].quanUrl    = "https://quan.qq.com/circle/" + pg.allPages[postID].quanID;
                     pg.allPages[postID].pageUrl    = "https://quan.qq.com/post/" + pg.allPages[postID].quanID + "/" + postID;
                 }
                 else
                 {
                     if (End)
                     {
                         break;
                     }
                 }
             }
             else
             {
                 //文章ID作为唯一值
                 string postID = jb["stPostSummary"]["postId"].ToString();
                 //添加一行数据
                 pg.allPages.Add(postID, new OnePage(postID));
                 pg.pageIDList.Add(postID);
                 //pg.allPages[postID]
                 pg.allPages[postID].nickName   = jb["stPostSummary"]["postUser"]["nickname"].ToString();
                 pg.allPages[postID].PageID     = jb["stPostSummary"]["postId"].ToString();
                 pg.allPages[postID].PageName   = jb["stPostSummary"]["postField"]["title"].ToString();
                 pg.allPages[postID].Date       = jb["stPostSummary"]["elapseTime"].ToString();
                 pg.allPages[postID].praiseNum  = jb["stPostSummary"]["praiseNum"].ToString();
                 pg.allPages[postID].commentNum = jb["stPostSummary"]["commentNum"].ToString();
                 pg.allPages[postID].viewNum    = jb["stPostSummary"]["viewNum"].ToString();
                 pg.allPages[postID].quanName   = jb["stPostSummary"]["simpleInfo"]["circleName"].ToString();
                 pg.allPages[postID].quanID     = jb["stPostSummary"]["simpleInfo"]["circleId"].ToString();
                 pg.allPages[postID].quanUrl    = "https://quan.qq.com/circle/" + pg.allPages[postID].quanID;
                 pg.allPages[postID].pageUrl    = "https://quan.qq.com/post/" + pg.allPages[postID].quanID + "/" + postID;
             }
         }
     }
 }
Пример #2
0
        //合并所有data目录下的excel文件为一个,方便统计
        private void FileToOne_Click(object sender, RoutedEventArgs e)
        {
            UnEnabledButton();
            //保存所有数据
            PageFeed      pgFeed        = new PageFeed();
            string        AppDomainPath = AppDomain.CurrentDomain.BaseDirectory;
            string        DataPath      = AppDomainPath + "data\\";
            DirectoryInfo root          = new DirectoryInfo(DataPath);

            //遍历目录下所有文件
            foreach (FileInfo f in root.GetFiles())
            {
                if (f.Name.Split('_')[0] == "merge")
                {
                    f.Delete();
                }
                else
                {
                    try
                    {
                        IWorkbook  workbook   = null;                //新建IWorkbook对象
                        FileStream fileStream = new FileStream(f.FullName, FileMode.Open, FileAccess.Read);
                        if (f.FullName.IndexOf(".xlsx") > 0)         // 2007版本
                        {
                            workbook = new XSSFWorkbook(fileStream); //xlsx数据读入workbook
                        }
                        else if (f.FullName.IndexOf(".xls") > 0)     // 2003版本
                        {
                            workbook = new HSSFWorkbook(fileStream); //xls数据读入workbook
                        }
                        ISheet sheet = workbook.GetSheetAt(0);       //获取第一个工作表
                        IRow   row;                                  // = sheet.GetRow(0);            //新建当前工作表行数据
                        for (int i = 1; i <= sheet.LastRowNum; i++)  //对工作表每一行
                        {
                            row = sheet.GetRow(i);                   //row读入第i行数据
                            if (row != null)
                            {
                                //读取pageID
                                string temp = row.GetCell(2).ToString();
                                pgFeed.allPages.Add(temp, new OnePage(temp));
                                pgFeed.pageIDList.Add(temp);
                                for (int j = 0; j < 11; j++)
                                {
                                    pgFeed.allPages[temp].SetCell(j, row.GetCell(j).ToString());
                                }
                            }
                        }
                        fileStream.Close();
                        workbook.Close();
                    }
                    catch (Exception x)
                    {
                        MessageBox.Show(x.ToString());
                    }
                }
            }
            string mergeName = "merge_" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

            pgFeed.Save2Excel(mergeName);
            //如果全部都
            if (isCustomFormat.IsChecked == true)
            {
                pgFeed.CustomFormat(mergeName);
            }
            MessageBox.Show("合并完成");
            EnabledButton();
        }
Пример #3
0
        //获取所有数据
        private void GetAllData(string _UserID, string userType, bool isSevenDay)
        {
            JObject Jobject = null;

            End = false;
            bool     isEnd    = false;
            string   lasttime = null;
            string   nickName = "";
            PageFeed pgFeed   = new PageFeed();

            //JArray array = (JArray)_tempJObject["data"]["vHomePageFeed"];
            //o9GiTuCSz6w4uJRkPUvZeSNo-2_U
            //o9GiTuOaGdgD_-ZS4YWn5f-p8ZiE
            for (int i = 1; !isEnd; i++)
            {
                //第一次没有lasttime
                Jobject = GetQuanData(_UserID, i, userType);
                //101_c4707a5494b0db899f5c7d073ef6b1c3
                if (Jobject.ToString().Length > 150)
                {
                    if (i == 1)
                    {
                        //为lasttime赋值,以便获得后续数据
                        lasttime = Jobject["data"]["lLastTime"].ToString();
                        if (Jobject["data"]["vHomePageFeed"][0] != null)
                        {
                            nickName = (string)Jobject["data"]["vHomePageFeed"][0]["stPostSummary"]["postUser"]["nickname"];
                        }
                    }
                    else
                    {
                        Jobject = GetQuanData(_UserID, i, userType, lasttime);
                        if (Jobject.ToString().Length > 150)
                        {
                            lasttime = Jobject["data"]["lLastTime"].ToString();
                        }
                        else
                        {
                            isEnd = true;
                        }
                    }
                    //判断是否为此用户所有数据的最后一次
                    if (Jobject["data"]["lLastTime"].ToString() == "0")
                    {
                        isEnd = true;
                    }
                    else
                    {
                        //有效数据,进行分析
                        analysePage(Jobject, pgFeed, isSevenDay);
                        if (End)
                        {
                            isEnd = true;
                        }
                    }
                }
                else
                {
                    isEnd = true;
                }
            }
            pgFeed.Save2Excel(nickName);
        }