All projects

Article Sync & Image Download

Image Downloader & Article Synchronizer

A C# console program that compares a current article list with a previous one, detects added and removed articles, saves the results as CSV and downloads the product image for every new article.

Status
Completed
Stack
C# · .NET · LINQ · CSV · HttpClient · Async/Await
Links
Source code not public
Placeholder artwork

Overview

The program compares two article lists and automatically downloads the product images for new articles. It is a C# console application on .NET.

Features

  • Reads the current and the previous article list from CSV files, skipping the header and empty lines
  • Compares them with LINQ, ignoring upper and lower case
  • Detects added and removed articles
  • Exports the results to two CSV files
  • Downloads the images of new articles asynchronously with HttpClient
  • Creates the image folder when needed
  • Reports for each article whether the download worked
  • Stores the current list as the basis for the next comparison

Problem

When a range of articles changes, images have to be found for the new articles and removed articles have to be identified. By hand, that means comparing lists, copying numbers and downloading images one at a time. It takes time and invites mistakes.

Solution

The program reads the current and the previous list, works out the added and the removed articles and saves both results as CSV. For every new article it fetches the image from an image service and stores it under the article number. Finally, the current list becomes the basis for the next run.

Technical implementation

The lists are read with File.ReadAllLines and cleaned with LINQ: skip the header, drop empty lines, trim spaces. Except with StringComparer.OrdinalIgnoreCase gives the differences in both directions. Downloads use HttpClient with async/await, and the status code of every response is checked before the image is saved.

Challenges

The article numbers in the list start with a "W", but the image service expects them without it. The program therefore removes the letter for the request only and keeps the original number as the file name. Also, an empty current list must not overwrite the stored basis for comparison, so this is checked before saving.

Limitations

Images are downloaded one after another, with no retry after an error, and are always saved as .jpg. File names are fixed in the code. The address and the access key of the image service are in the code; before the source code is published they belong in an environment variable. That is why the source code is not public.

Lessons learned

This section is still to be written.

Screenshots

A command-line program without a graphical interface. There are no screenshots of its output yet.