예제 #1
0
        public CDB Exec()
        {
            if (_DB.GetOAuthToken == null)
            {
                AccessToken.FullName     = "Cloud2013";
                AccessToken.Token        = "72157644879828272-04fe2e4af1f40866";
                AccessToken.UserId       = "26095572@N07";
                AccessToken.TokenSecret  = "02947f478d4b0cc1";
                FlickrManager.OAuthToken = AccessToken;
                _F = FlickrManager.GetAuthInstance("2c67273e05ae10a7001e5b569df4f7d1", "d8906735118cab71");

                _DB.SetUser(AccessToken.FullName, AccessToken.UserId);
                _DB.APIKey       = "2c67273e05ae10a7001e5b569df4f7d1";
                _DB.SharedSecret = "d8906735118cab71";
                _DB.Token        = AccessToken.Token;
                _DB.TokenSecret  = AccessToken.TokenSecret;
            }
            else
            {
                FlickrManager.OAuthToken = _DB.GetOAuthToken;
                _F = FlickrManager.GetAuthInstance(_DB.APIKey, _DB.SharedSecret);
            }
            int ndx    = 0;
            int update = 0;
            int insert = 0;
            int dup    = 0;

            while (true)
            {
                PhotoCollection photo = _F.PeopleGetPhotos(PhotoSearchExtras.Views, ndx++, 500);
                if (photo.Count == 0)
                {
                    break;
                }


                foreach (FlickrNet.Photo p in photo)
                {
                    if (p.Views == null)
                    {
                        p.Views = 0;
                    }
                    if (CWorker.NewEntry(p.PhotoId, _DB))
                    {
                        _DB.Photos.Add(new CPhoto(p.PhotoId, p.Title, p.ThumbnailUrl, p.LargeUrl, p.Views));
                    }
                    else
                    {
                        CPhoto thisPhoto = CWorker.GetPhotoRecord(p.PhotoId, _DB);
                        CStats record    = CWorker.GetStatsRecord(thisPhoto, System.DateTime.Now);
                        if (record == null)
                        {
                            if (p.Views != 0)//add only if non-zero
                            {
                                thisPhoto.Stats.Add(new CStats(p.Views));
                                insert++;
                            }
                        }
                        else
                        {
                            string dt = CWorker.DT2Str(System.DateTime.Now);
                            for (int xdx = 0; ndx != thisPhoto.Stats.Count; xdx++)
                            {
                                if (thisPhoto.Stats[xdx].Date == dt)
                                {
                                    if (thisPhoto.Stats[xdx].Views != record.Views)
                                    {
                                        thisPhoto.Stats[xdx].Views = record.Views;
                                        update++;
                                    }
                                    else
                                    {
                                        dup++;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(_DB);
        }
예제 #2
0
        static void Main(string[] args)
        {
            OAuthAccessToken accessToken = new OAuthAccessToken();

            FlickrNet.Flickr f = null;
            CWorker.BasePath         = @"C:\TEMP\";
            CWorker.DataBaseRootName = "FLICKRDB";
            CDB db = CWorker.ReadDB();

            if (db.GetOAuthToken == null)
            {
                accessToken.FullName     = "Cloud2013";
                accessToken.Token        = "72157644879828272-04fe2e4af1f40866";
                accessToken.UserId       = "26095572@N07";
                accessToken.TokenSecret  = "02947f478d4b0cc1";
                FlickrManager.OAuthToken = accessToken;
                f = FlickrManager.GetAuthInstance("2c67273e05ae10a7001e5b569df4f7d1", "d8906735118cab71");
                db.SetUser(accessToken.FullName, accessToken.UserId);
                db.APIKey       = "2c67273e05ae10a7001e5b569df4f7d1";
                db.SharedSecret = "d8906735118cab71";
                db.Token        = accessToken.Token;
                db.TokenSecret  = accessToken.TokenSecret;
            }
            else
            {
                FlickrManager.OAuthToken = db.GetOAuthToken;
                f = FlickrManager.GetAuthInstance(db.APIKey, db.SharedSecret);
            }
            int ndx = 0;

            while (true)
            {
                PhotoCollection photo = f.PeopleGetPhotos(PhotoSearchExtras.Views, ndx++, 500);
                if (photo.Count == 0)
                {
                    break;
                }
                foreach (FlickrNet.Photo p in photo)
                {
                    if (CWorker.NewEntry(p.PhotoId, db))
                    {
                        db.Photos.Add(new CPhoto(p.PhotoId, p.Title, p.ThumbnailUrl, p.LargeUrl, p.Views));
                    }
                    else
                    {
                        CPhoto thisPhoto = CWorker.GetPhotoRecord(p.PhotoId, db);
                        CStats record    = CWorker.GetStatsRecord(thisPhoto, System.DateTime.Now);
                        if (record == null)
                        {
                            thisPhoto.Stats.Add(new CStats(p.Views));
                        }
                        else
                        {
                            if (p.Views == null)
                            {
                                p.Views = 0;
                            }
                            if (record.Views != Convert.ToInt32(p.Views))
                            {
                                record.Views = Convert.ToInt32(p.Views);
                            }
                        }
                    }
                }
            }
            CWorker.StoreDB(db);
            if (args.Length != 0)
            {
                CWorker.Exit(0, "Success");
            }
        }