Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
#27 Changed grabbing setup method and added console parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
BoDmiSer committed Dec 9, 2020
1 parent 257c142 commit db1fb4c
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 49 deletions.
27 changes: 0 additions & 27 deletions ImageBase.GrabbingImages/Converter/CSVBase.cs

This file was deleted.

5 changes: 2 additions & 3 deletions ImageBase.GrabbingImages/Dtos/ImageDto.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using ImageBase.GrabbingImages.Converter;
using System;
using System;
using System.Collections.Generic;
using System.Text;

namespace ImageBase.GrabbingImages.Dtos
{
public class ImageDto : CSVBase
public class ImageDto
{
public int id { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions ImageBase.GrabbingImages/Grabber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public Grabber(IConfiguration configuration)
}
private PexelsClient pexelsClient;

public async Task<PhotoPage> SearchPhotosAsync(string tema = "Nature", int pagestart=1,int count = 1)
public async Task<PhotoPage> SearchPhotosAsync(string theme = "Nature", int pagestart=1,int count = 1)
{
PhotoPage photoPage = await pexelsClient.SearchPhotosAsync(tema, "ru-RU", pagestart, count);
PhotoPage photoPage = await pexelsClient.SearchPhotosAsync(theme, "ru-RU", pagestart, count);
return photoPage;
}
}
Expand Down
1 change: 1 addition & 0 deletions ImageBase.GrabbingImages/ImageBase.GrabbingImages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.0" />
<PackageReference Include="PexelsDotNetSDK" Version="1.0.5" />
<PackageReference Include="ServiceStack.Text" Version="5.10.2" />
</ItemGroup>

</Project>
54 changes: 45 additions & 9 deletions ImageBase.GrabbingImages/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,60 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;
using ServiceStack.Text;
using System;

namespace ImageBase.GrabbingImages
{
public class Program
{
private static List<ImageDto> _listImageDtos;
private static string KeyWord;

static async Task Main(string[] args)
{
if (args.Length == 0)
{
await GrabbingFromPexels();
}
else
{
switch (args.Length)
{
case 1:
if (args[0] == "Pexels")
{
await GrabbingFromPexels();
}
break;
case 2:
if (args[0] == "Pexels")
{
await GrabbingFromPexels(args[1]);
}
break;
case 3:
if (args[0] == "Pexels")
{
await GrabbingFromPexels(args[1],Convert.ToInt32(args[2]));
}
break;
case 4:
if (args[0] == "Pexels")
{
await GrabbingFromPexels(args[1], Convert.ToInt32(args[2]),args[3]);
}
break;
default:
break;
}
}
}
static async Task GrabbingFromPexels(string theme="Nature",int countImages=5,string outputfile= "AllImages.csv")
{
Grabber grabber = InicializeGrabber();
KeyWord = "Nature";
PhotoPage photoPage = await grabber.SearchPhotosAsync(KeyWord, 1,5);

PhotoPage photoPage = await grabber.SearchPhotosAsync(theme, 1, countImages);
_listImageDtos = CreateListImages(photoPage);
ConvertToCSVAndSaveInFile(_listImageDtos,"AllImages.csv");
ConvertToCSVAndSaveInFile(_listImageDtos, outputfile);
}
static Grabber InicializeGrabber()
{
Expand Down Expand Up @@ -56,10 +95,7 @@ static void ConvertToCSVAndSaveInFile(List<ImageDto> imageDtos,string destinatio
{
using (var sw = new StreamWriter(destination))
{
foreach (var item in imageDtos)
{
sw.WriteLine(item.ToCsv());
}
sw.WriteCsv(imageDtos);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions ImageBase.GrabbingImages/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"ImageBase.GrabbingImages": {
"commandName": "Project"
}
}
}
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,26 @@ _ImageBase.ImageHash_ - this project calculates hashes images
_ImageBase.WebApp_ - this project contains rest API requests to manage your images collection
## Usage
ImageBase.GrabbingImages

If you are using the Pexels open service set parameters then you need to enter the command line arguments.
For example

```bash
ImageBase.GrabbingImages.exe Pexels Sun 3 Out.csv
```
It configures parameters for you request
1) Pexels - name services
2) Sun - chosen name topic
3) 3 - count required images
4) Out.csv - name of the output file with csv data
```ccharp
static async Task Main(string[] args)
{
Grabber grabber = InicializeGrabber();
KeyWord = "Nature";
PhotoPage photoPage = await grabber.SearchPhotosAsync(KeyWord, 1,5); //Set 3 parameters: tema, start page and count image
_listImageDtos = CreateListImages(photoPage);
ConvertToCSVAndSaveInFile(_listImageDtos,"AllImages.csv"); //Set 2 parameters: list with your images and output saving file
}
static async Task GrabbingFromPexels(string theme="Nature",int countImages=5,string outputfile= "AllImages.csv")
{
Grabber grabber = InicializeGrabber();
PhotoPage photoPage = await grabber.SearchPhotosAsync(theme, 1, countImages);
_listImageDtos = CreateListImages(photoPage);
ConvertToCSVAndSaveInFile(_listImageDtos, outputfile);
}
```
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Expand Down

0 comments on commit db1fb4c

Please sign in to comment.