Hoarding.cs

Few words about custom code that should be a bash script but became a C# code that looks like a Shit#.

Ok, first of all: I know that it should be just a .sh or .py script... for you all purists. But I'm a guy who is doing things using tools that he know the best. So YES I am using .net and c# in many projects that it doesn't fit great, but its easier for me.

Also when I'm writing script like things in .net I do NOT do all stuff that we all are learned to do. I do not do OOP, I do not do SOLID etc. I am just making few functions that are combined together, often with dynamic objects to ease up my development and put it onto final machine in few dozens of minutes.

But what my newest tool does?

It is runned in Cron on the twice a day basis. Then it goes to the local DB of my personal freshRSS instance and gets an answer for a simple answer:

select * from freshrss_{{username}}_entry where is_favourite is '1';

then we do a second level magic of ...

foreach (var item in selectionAnswer) {
  if (!DoesFileContains(item.id)){
    PushOntoLinkwarden(item);
  }
}

that is that simple...

Also DoesFileContains is just a function that crawls thru a "movedItems.myFile" which is a file with a structure od "id={{freshRssEntryId}}\n" and this function checks if this string exist in file.

And PushOntoLinkwarden is a function that do two things:

  1. https://docs.linkwarden.app/api/create-link <<– adds link onto my linkwarden instance
  2. if POST method succeeded it adds item.id to the end of "movedItems.myFile".

So this is about 100 lines of code in total. It works. And that's it. And as it runs on the same Pi that both freshRss and Linkwarden instances I dont care too much about hardcoding logins, apiKeys, passwords etc inside the code. And its still 100 lines instead of 40 because of my laziness. I do some stuff in a longer way just to be able to maintain it in future.

I want this code to be easily readable by me after a year or two of not touching it. So long function names that describes everything. Not using lambdas and any shortcuts that are really nice and so pushed in programmers social media, for staying in line with this most important request: readable.

Have a nice day.

PS but it still is not solving my most important issue: having a single place to go thru all links that I marked as "to check" in many different tools. FreshRSS is posting to linkwarden to preserve what link contains. Not to be readed. But that is a different story for different day.

PS between writing and publishing that post I have rewrote this mess. Now instead of a file I have a second table in DB with two columns: EntryId and LinkwardenSynchronised (Nullable), so I can add another syncs in future with ease.