예제 #1
0
        public async Task SearchPhotosTest()
        {
            var query       = "mountains";
            var client      = new UnsplasharpClient(Credentials.ApplicationId);
            var photosFound = await client.SearchPhotos(query);

            var photosFoundPaged = await client.SearchPhotos(query, 2);

            Assert.IsTrue(photosFound.Count > 0);
            Assert.IsTrue(photosFoundPaged.Count > 0);

            Assert.IsNotNull(client.LastPhotosSearchQuery);
            Assert.IsTrue(client.LastPhotosSearchTotalPages > 0);
            Assert.IsTrue(client.LastPhotosSearchTotalResults > 0);
        }
예제 #2
0
        private async void GetSearchedPhotos(int page)
        {
            EnableControls(false);
            _photos = await _client.SearchPhotos(_searchQuery, page, 4);

            DisplayPhotos();
        }
예제 #3
0
파일: Program.cs 프로젝트: sttrox/Wallee
 private static async void getImg()
 {
     UnsplasharpClient client = new UnsplasharpClient(
         "93123f0db401f8367e061a60e9b0976b9bc9c3cafe5133f344bba4010c97a4de",
         "ec8401ec0727226a41f9fea4ef184c10f7efef4b009ee910dbf3ca386a");
     await client.SearchPhotos("new");
 }
예제 #4
0
        private async Task SearchImagesTask()
        {
            var client = new UnsplasharpClient(_apiToken);


            List <Photo> photosFound = null;

            if (!string.IsNullOrEmpty(_collectionId))
            {
                photosFound = await client.GetCollectionPhotos(_collectionId, 1, _maxResultCount);
            }
            else
            {
                photosFound = await client.SearchPhotos(_searchQuery, 1, _maxResultCount);
            }

            _photos = photosFound;
            Log.Debug($"got {photosFound.Count} images from Unsplash");
            _urls.Clear();
            foreach (var p in photosFound)
            {
                _urls.Add(p.Urls.Regular);
            }
            ResultList.Value = _urls;
            _photoIndex      = -1;
            ResultList.DirtyFlag.Invalidate();
        }
        public async Task <Image> GetImageAsync(string query)
        {
            var random  = new Random();
            var imageId = random.Next(0, 9);

            var results = await _client.SearchPhotos(query, 1, 10);

            var image = new Image
            {
                Id  = results[imageId].Id,
                Url = results[imageId].Urls.Regular,
                Alt = string.IsNullOrEmpty(results[imageId].Description) ? query : results[imageId].Description
            };

            return(image);
        }
예제 #6
0
        static void Main(string[] args)
        {
            //var key = "b698bd6365f99a2d28ff5f2953d9de804742cf47baccb1890719397253564652";
            //var key = "e5457c652514029496f7eda5d48fbad171d94b74747f59bc2f592e1a4adc762a";
            //var key = "07fbb153f650b9a882fd916f59d3b84c694b3f6457174cdab8e3470f380c4e7c";
            var key          = "1c8949783fd75ec3a72bbcc3a668eb378f780292c04fd5803d305076dc080036";
            var destination  = @"..\KeesTalksTech.Assessments.Wehkamp.Store.StoreApi\data\products.xml";
            var imagesBackup = @"..\KeesTalksTech.Assessments.Wehkamp.Store.WebApp\wwwroot\images\backup\";

            var client     = new UnsplasharpClient(key);
            var randomizer = new Random();

            List <PhotoProduct> products = new List <PhotoProduct>();

            Console.WriteLine("This tool will generate a products.xml database based on Unsplash photos.");
            Console.WriteLine("Unsplash has a rate limit of 50 request / hour.");

            string[] keywords =
            {
                "lights",   "cloths", "Berlin",  "Paris", "computer", "phone",
                "building", "food",   "love",    "smile", "music",
                "animal",   "car",    "sports",  "bird",  "Beauty",
                "fashion",  "tools",  "working", "wild",  "water",    "portrait",
                "winter",   "summer"
            };

            foreach (var keyword in keywords)
            {
                Console.WriteLine();
                Console.WriteLine($"Downloading '{keyword}' photos from Unsplash.com...");

                var photosTask = client.SearchPhotos(keyword, 1, 30);
                var photos     = photosTask.Result;

                var photosTask2 = client.SearchPhotos(keyword, 2, 30);
                var photos2     = photosTask.Result;

                photos.AddRange(photos2);

                var processed = photos
                                //skip photos without a description
                                .Where(p => !String.IsNullOrEmpty(p.Description))
                                .Where(p => products.FirstOrDefault(p2 => p2.Id == p.Id) == null)
                                .Select(p => new PhotoProduct
                {
                    Id           = p.Id,
                    Name         = p.Description,
                    Description  = $"Photo was taken by {p.User.Name} on {p.CreatedAt}. The primary color of this photo is {p.Color}. Original is {p.Height}x{p.Width}.",
                    PictureUrl   = p.Urls.Regular,
                    ThumbnailUrl = p.Urls.Small,
                    Price        = new PhotoProductPrice()
                    {
                        Amount = Randomizer.GenerateRandomNumber(1, 25, 2)
                    },
                    Keywords    = GetKeywords(p, keyword),
                    Orientation = GetOrientation(p)
                })
                                .ToList();

                processed.ForEach(p => products.Add(p));

                Console.WriteLine($"{processed.Count} downloaded.");
            }

            Console.WriteLine();
            Console.WriteLine($"{products.Count} photo records downloaded.");
            Console.WriteLine();
            Console.WriteLine($"Writing products to file...");

            var path = Directory.GetCurrentDirectory();

            path = Path.Combine(path, destination);

            XmlSerializationHelper.SerializeToFile(path, products);

            Console.WriteLine();
            Console.WriteLine("Downloading backup images...");

            Directory.CreateDirectory(imagesBackup);
            using (var downloader = new HttpClient())
            {
                products.ForEach(p =>
                {
                    Console.WriteLine("Downloading " + p.Id);
                    var s1 = DownloadFile(downloader, p.ThumbnailUrl, Path.Combine(imagesBackup, p.Id + "_tn.jpg")).Result;
                    var s2 = DownloadFile(downloader, p.PictureUrl, Path.Combine(imagesBackup, p.Id + ".jpg")).Result;
                });
            }


            Console.WriteLine();
            Console.WriteLine("Ready!");
            Console.ReadLine();
        }
예제 #7
0
        public async Task <List <InstaBot.Models.Photo> > SearchPhotosAsync(string stockCategoryName, int page = ApiConstans.PHOTO_SEARCH_DEFAULT_PAGE, int perPage = ApiConstans.PHOTO_SEARCH_DEFAULT_PER_PAGE)
        {
            List <Unsplasharp.Models.Photo> searchList = await stockClient.SearchPhotos(stockCategoryName, page, perPage);

            return(searchList.ToPhotoList());
        }