示例#1
0
        private static void NormalizeAccount()
        {
            string[] acc = File.ReadAllLines("moreAccount.txt");
            foreach (var st in acc)
            {
                string[] tmp = st.Split(' ');
                string   username = tmp[0], password = tmp[1];

                OAuth o = new OAuth(DefaultSettings.AppKey, DefaultSettings.AppSecret, String.Empty);
                o.ClientLogin(username, password);
                Client client = new Client(o);

                try
                {
                    var s          = client.API.Entity.Account.GetUID();
                    var collection = WeiboAPI.GetFriendsIDs(s, Enums.SampleMethod.All);
                    foreach (var id in collection)
                    {
                        client.API.Entity.Friendships.Destroy(id);
                        Thread.Sleep(1000);
                    }
                    Console.WriteLine(username + " successed");
                    File.AppendAllText("accountResult.txt", username + " " + password + '\n');
                }
                catch (WeiboException ex)
                {
                    Console.WriteLine(username + " " + ex.ErrorCode + " " + ex.ErrorMessage);
                }
                Thread.Sleep(9000);
            }
        }
        public string DoOneJob(IPipeline Pipeline)
        {
            int      SuccCount = 0, ErrCount = 0;
            DateTime nextWorkTime = Utilities.Epoch;


            while (!StopFlag)
            {
                if (DateTime.Now > nextWorkTime)
                {
                    Author author = GetNextJob();
                    if (author != null)
                    {
                        try
                        {
                            //如果不是红人,那么只刷新一次就结束
                            if (WeiboUtilities.IsRedSkin(author.AuthorSource))
                            {
                                author.Fans_RefreshStatus = Enums.CrawlStatus.Normal;
                            }
                            else
                            {
                                author.Fans_RefreshStatus = Enums.CrawlStatus.Stop;
                            }

                            #region 用户粉丝刷新
                            List <NetDimension.Weibo.Entities.user.Entity> users = new List <NetDimension.Weibo.Entities.user.Entity>();
                            try
                            {
                                SendMsg(string.Format("正在刷新{0}的粉丝", author.AuthorName));
                                WeiboAPI.GetFollowers(author.AuthorID, author.FollowerSampleMethode, users);
                            }
                            catch (IOException)
                            {
                                ErrCount++;
                                nextWorkTime = WeiboAPI.rateLimitStatus.ResetTime;
                            }
                            catch (Exception ex)
                            {
                                SendMsg("获取粉丝列表时发生错误,见日志");
                                ErrCount++;
                                nextWorkTime = WeiboAPI.rateLimitStatus.ResetTime;
                                author.Fans_RefreshStatus = Enums.CrawlStatus.Normal;
                                Logger.Error(ex.ToString());
                            }

                            SendMsg(string.Format("{0}的粉丝抓取到{1}个,开始插入数据库", author.AuthorName, users.Count));
                            double avg = 0; //用户粉丝的粉丝平均数
                            for (int i = 0; i < users.Count; ++i)
                            {
                                var user = AuthorDBManager.ConvertToAuthor(users[i], Enums.AuthorSource.FansDiscover);
                                AuthorDBManager.InsertOrUpdateAuthorInfo(user);
                                CntData.Tick();
                                AuthorRelationDBManager.InsertOrUpdateRelation(user.AuthorID, author.AuthorID);
                                avg += (double)users[i].FollowersCount / (double)users.Count;
                            }
                            #endregion

                            #region 用户关注列表
                            try
                            {
                                IEnumerable <string> friends = null;
                                SendMsg(string.Format("{0}的粉丝插入完成,开始获取他的关注列表", author.AuthorName));
                                friends = WeiboAPI.GetFriendsIDs(author.AuthorID, author.FansSampleMethode);
                                if (friends != null)
                                {
                                    foreach (var user in friends)
                                    {
                                        AuthorRelationDBManager.InsertOrUpdateRelation(user, author.AuthorID);
                                    }
                                }
                            }
                            catch (IOException)
                            {
                                ErrCount++;
                                nextWorkTime = WeiboAPI.rateLimitStatus.ResetTime;
                            }
                            catch (Exception ex)
                            {
                                SendMsg("获取关注列表时发生错误,见日志");
                                ErrCount++;
                                nextWorkTime = WeiboAPI.rateLimitStatus.ResetTime;
                                author.Fans_RefreshStatus = Enums.CrawlStatus.Normal;
                                Logger.Error(ex.ToString());
                            }

                            SendMsg(string.Format("{0}的关系刷新任务完成", author.AuthorName));
                            #endregion

                            author.AvgFansCountOfFans = (int)avg;
                            SuccCount++;
                            continue;
                        }
                        catch (Exception ex)
                        {
                            ErrCount++;
                            nextWorkTime = WeiboAPI.rateLimitStatus.ResetTime;
                            author.Fans_RefreshStatus = Enums.CrawlStatus.Normal;
                            SendMsg(ex.ToString());
                            Logger.Error(ex.ToString());
                        }
                        finally
                        {
                            author.Fans_UpdateCount++;
                            author.Fans_NextRefreshTime = DateTime.Now.AddDays(author.Fans_IntervalDays);
                            AuthorDBManager.PushbackRelationshipJob(author);
                        }
                    }
                }
                Thread.Sleep(IntervalMS);
            }
            StopFlag = false;
            return(SuccCount == 0 && ErrCount == 0 ? "Nothing to do" : string.Format("OneJob Done. Succ {0} Err {1}", SuccCount, ErrCount));
        }
示例#3
0
        /// <summary>
        /// 定期检查账号情况
        /// </summary>
        private static void NormalizeAccount()
        {
            string where;
            try
            {
                #region 初始化账号
                where = "IsDisabled=FALSE AND SubscribeStatus>=0 AND AuthorID IS NULL";
                var result = LoginAccountBusiness.GetAllByWhere(where, null, LoginAccountMySqlDAL.OrderColumn.Default);
                foreach (var account in result)
                {
                    try
                    {
                        account.AuthorID = WeiboAPI.GetAuthorID(account.UserName);
                        var author = WeiboAPI.GetAuthorInfo(account.AuthorID);
                        var list   = WeiboAPI.GetFriendsIDs(account.AuthorID, Enums.SampleMethod.All);
                        account.FollowCount = 0;
                        foreach (var id in list)
                        {
                            AuthorDBManager.SubscribeAuthor(account.UserName, id);
                            account.FollowCount++;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(string.Format("Err@ Account: {0}, message: {1}", account.UserName, ex.ToString()));
                        account.FailCount++;
                        if (account.FailCount > DefaultSettings.MaxFailureCount)
                        {
                            account.IsDisabled = true;
                        }
                        LoginAccountBusiness.UpdateByAccountID(account);
                        continue;
                    }
                    account.FailCount                = 0;
                    account.SubscribeIntervalMins    = 15;
                    account.SubscribeLastTime        = Utilities.Epoch;
                    account.SubscribeNextTime        = Utilities.Epoch;
                    account.SubscribeSinceID         = null;
                    account.FollowCountLastClearTime = DateTime.Now;
                    account.FollowCountToday         = 0;
                    LoginAccountBusiness.UpdateByAccountID(account);
                }
                #endregion

                #region 关注次数和失效次数清零(每天一次)
                DateTime refreshtime = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
                where  = string.Format("IsDisabled=FALSE AND SubscribeStatus>=0 AND (FollowCountLastClearTime IS NULL OR FollowCountLastClearTime<'{0}')", refreshtime);
                result = LoginAccountBusiness.GetAllByWhere(where, null, LoginAccountMySqlDAL.OrderColumn.Default);
                foreach (var account in result)
                {
                    account.FollowCountLastClearTime = DateTime.Now;
                    account.FollowCountToday         = 0;
                    account.FailCount = 0;
                    LoginAccountBusiness.UpdateByAccountID(account);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
        }