Example #1
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");
            }
        }
Example #2
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);
        }
Example #3
0
 public static void Main(string[] args)
 {
     Console.WriteLine("ThumbSync - Flickr Sync by Tristan Phillips   v0.4");
     if (!ParseArgs(args))
     {
         Console.WriteLine("usage: ThumbSync.exe -u <userIDs , seperated> -o <out directory>\n" +
                           "Optionals:\n" +
                           "-c <count, default 20> \n" +
                           "-s get small photos (default medium) \n" +
                           "-t get thumbnails (default medium) \n" +
                           "-l get large photos (default medium) \n" +
                           "-T <pre authenticated token> \n" +
                           "-O overwrite existing local copy \n" +
                           "-p <start at page> \n" +
                           "-th <throttle millisecs> \n" +
                           "-W use white average file validation");
         return;
     }
     string[]         userIDs = userIds.Split(',');
     FlickrNet.Flickr f       = new FlickrNet.Flickr("5f9dbe6d11086346eacc6d9b9d81a5f5", "826ddba13f621f18");
     if (token == "")
     {
         string frob = f.AuthGetFrob();
         string url  = f.AuthCalcUrl(frob, AuthLevel.Read);
         Console.WriteLine("Go here & authenticate: " + url);
         Console.WriteLine("When you are done, press return . . .  I'll be waiting . . .");
         try
         {
             /*
              * System.Diagnostics.Process p = new System.Diagnostics.Process();
              * p.StartInfo.FileName="c:\\program files\\internet explorer\\iExplore.exe";
              * p.StartInfo.Arguments = url;
              * p.Start();
              * System.Diagnostics.Process p2 = new System.Diagnostics.Process();
              * p2.StartInfo.FileName="/Applications/Safari.app/Contents/MacOS/Safari";
              * p2.StartInfo.Arguments = "\"" + url + "\"";
              * p2.Start();
              */
         }
         catch {}
         Console.ReadLine();
         FlickrNet.Auth auth = f.AuthGetToken(frob);
         Console.WriteLine("Token (you can re-use this with -T): " + auth.Token);
         token = auth.Token;
     }
     f.AuthToken = token;
     foreach (string userId in userIDs)
     {
         Person per        = f.PeopleGetInfo(userId);
         string personName = per.UserName;
         Console.WriteLine("Processing " + maxPerPerson + " from " + per.UserName + "(" + per.RealName + ")");
         while (collected < maxPerPerson)
         {
             PhotoCollection res = f.PeopleGetPhotos(userId, page, pageSize);
             collected += res.Count;
             if (res.Page == res.Pages)
             {
                 collected = maxPerPerson;
             }
             foreach (Photo p in res)
             {
                 bool processed     = false;
                 int  tries         = 0;
                 int  startSecsWait = 120;
                 int  maxTries      = 15;
                 while (!processed && tries < maxTries)
                 {
                     try
                     {
                         tries++;
                         Console.Write(". ");
                         if (x % 10 == 0)
                         {
                             Console.Write(x + " ");
                         }
                         PhotoInfo info = f.PhotosGetInfo(p.PhotoId);
                         string    tag  = info.Tags.Count > 0 ? info.Tags[0].Raw : "NotTagged";
                         if (!System.IO.Directory.Exists(OutDir + System.IO.Path.DirectorySeparatorChar + personName + "-" + tag))
                         {
                             System.IO.Directory.CreateDirectory(OutDir + System.IO.Path.DirectorySeparatorChar + personName + "-" + tag);
                         }
                         string url = smallPhotos ? p.SmallUrl : p.MediumUrl;
                         url = largeSize ? p.LargeUrl : url;
                         url = thumbnailSize ? p.ThumbnailUrl: url;
                         string[] pNames   = url.Split('/');
                         string   pName    = pNames[pNames.Length - 1];
                         string   fileName = OutDir + System.IO.Path.DirectorySeparatorChar + personName + "-" + tag + System.IO.Path.DirectorySeparatorChar + pName;
                         if (!System.IO.File.Exists(fileName) || overwrite)
                         {
                             new System.Net.WebClient().DownloadFile(url, fileName);
                             if (checkForWhiteFiles)
                             {
                                 WhiteCheck(fileName);
                             }
                         }
                         processed = true;
                         x++;
                     }
                     catch (Exception e)
                     {
                         int wait = startSecsWait * tries;
                         Console.WriteLine(String.Format("There was a problem processing page {0} (x={1}, page={2}, pageSize={3}, collected={4})", page, x, page, pageSize, collected));
                         Console.WriteLine(e.Message);
                         if (tries < maxTries)
                         {
                             Console.WriteLine("Will retry in " + wait / 60 + " mins . . .");
                         }
                         System.Threading.Thread.Sleep(wait * 1000);
                     }
                 }
                 if (throttle > 0)
                 {
                     System.Threading.Thread.Sleep(throttle);
                 }
             }
             page++;
         }
     }
     Console.WriteLine("Done");
 }