mark as read and chat a message when done

This commit is contained in:
Adam R Grey 2023-07-06 22:31:53 -04:00
parent 9d252ee0d3
commit 5309609bfd
10 changed files with 77 additions and 15 deletions

View File

@ -10,6 +10,7 @@ namespace ttrss_co_client
public string PodcastTitlePrefix { get; set; } public string PodcastTitlePrefix { get; set; }
public string OnDoneCopy { get; set; } public string OnDoneCopy { get; set; }
public string WorkingDirectory { get; set; } = "./working/"; public string WorkingDirectory { get; set; } = "./working/";
public string ChatScript { get; set; }
public IEnumerable<FeedAction> feedActions { get; set; } public IEnumerable<FeedAction> feedActions { get; set; }
public class FeedAction public class FeedAction
{ {

View File

@ -116,6 +116,8 @@ namespace ttrss_co_client
phase2TaskConcretions.Add(concretion); phase2TaskConcretions.Add(concretion);
} }
ChatMessage.ChatScript = conf.ChatScript;
while (remainingWork.Count > 0) while (remainingWork.Count > 0)
{ {
//todo: solve the halting problem //todo: solve the halting problem
@ -134,6 +136,7 @@ namespace ttrss_co_client
if (appropriatePhase2Task != null) if (appropriatePhase2Task != null)
{ {
wo.Phase2TaskList.Remove(wo.Phase2TaskList.Keys.Min()); wo.Phase2TaskList.Remove(wo.Phase2TaskList.Keys.Min());
Console.WriteLine("launching phase 2 task: " + taskName);
Phase2Tasks.Add(appropriatePhase2Task.ActOn(wo)); Phase2Tasks.Add(appropriatePhase2Task.ActOn(wo));
} }
else else
@ -148,18 +151,19 @@ namespace ttrss_co_client
foreach (var lingeringTask in Phase2Tasks) foreach (var lingeringTask in Phase2Tasks)
{ {
var wo = await lingeringTask; var wo = await lingeringTask;
var wop = Path.Combine(conf.WorkingDirectory, wo.Item2.guid.ToString(), "workorder.json");
File.WriteAllText(wop, JsonConvert.SerializeObject(wo.Item2));
//if you tell me it's done, or you need to continue now.... I believe you. //if you tell me it's done, or you need to continue now.... I believe you.
//TODO: be smart enough to override?
switch (wo.Item1) switch (wo.Item1)
{ {
case Phase2Task.TaskStatus.Done: case Phase2Task.TaskStatus.Done:
File.Delete(wop);
Directory.Delete(Path.Combine(conf.WorkingDirectory, wo.Item2.guid.ToString())); Directory.Delete(Path.Combine(conf.WorkingDirectory, wo.Item2.guid.ToString()));
break; break;
case Phase2Task.TaskStatus.ContinueNow: case Phase2Task.TaskStatus.ContinueNow:
remainingWork.Add(wo.Item2); remainingWork.Add(wo.Item2);
break; break;
case Phase2Task.TaskStatus.TryLater: case Phase2Task.TaskStatus.TryLater:
File.WriteAllText(Path.Combine(conf.WorkingDirectory, wo.Item2.guid.ToString(), "workorder.json"), JsonConvert.SerializeObject(wo.Item2));
break; break;
} }
} }

View File

@ -5,6 +5,7 @@
"podcastTitlePrefix": "[podcast title] - ", "podcastTitlePrefix": "[podcast title] - ",
"onDoneCopy":"./", "onDoneCopy":"./",
"workingDirectory":"working/", "workingDirectory":"working/",
"chatScript": "miscChat.sh",
"feedActions": "feedActions":
[ [
{ {

22
tasks/ChatMessage.cs Normal file
View File

@ -0,0 +1,22 @@
namespace ttrss_co_client.tasks;
using System.Linq;
using System.Diagnostics;
using ttrss_co_client.ttrss;
using ttrss_co_client.ttrss.datastructures;
using System.Threading.Tasks;
using System;
public class ChatMessage : Phase2Task
{
public static string ChatScript { get; set; }
public override string TaskName => "chatmessage";
public override async Task<Tuple<TaskStatus, WorkOrder>> ActOn(WorkOrder workOrder)
{
await Process.Start(ChatScript,
workOrder.data["chatmessage"] + (await TtrssClient.GetArticles(workOrder.articleId)).First().feed_title
).WaitForExitAsync();
return new Tuple<TaskStatus, WorkOrder>(TaskStatus.Done, workOrder);
}
}

19
tasks/MarkRead.cs Normal file
View File

@ -0,0 +1,19 @@
namespace ttrss_co_client.tasks;
using System.Linq;
using System.Diagnostics;
using ttrss_co_client.ttrss;
using ttrss_co_client.ttrss.datastructures;
using System.Threading.Tasks;
using System;
public class MarkRead : Phase2Task
{
public override string TaskName => "markread";
public override async Task<Tuple<TaskStatus, WorkOrder>> ActOn(WorkOrder workOrder)
{
await TtrssClient.UpdateArticleField(ApiClient.UPDATEFIELD.unread, ApiClient.UPDATEMODE.SetFalse, workOrder.articleId);
return new Tuple<TaskStatus, WorkOrder>(TaskStatus.ContinueNow, workOrder);
}
}

View File

@ -70,6 +70,11 @@ namespace ttrss_co_client.tasks
toReturn.data["conversion-target"] = ".mp3"; toReturn.data["conversion-target"] = ".mp3";
} }
toReturn.Phase2TaskList[2] = "markread";
toReturn.Phase2TaskList[3] = "chatmessage";
toReturn.data["chatmessage"] = "new podcast from ";
return toReturn; return toReturn;
} }
} }

View File

@ -44,6 +44,12 @@ namespace ttrss_co_client.tasks
toReturn.Phase2TaskList[3] = "filemovePublish"; toReturn.Phase2TaskList[3] = "filemovePublish";
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/Podcasts/{podcastTitle}/"; toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/Podcasts/{podcastTitle}/";
toReturn.Phase2TaskList[4] = "markread";
toReturn.Phase2TaskList[5] = "chatmessage";
toReturn.data["chatmessage"] = "new podcast (via YT) from ";
await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id); await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id);
Console.WriteLine($" {headline.title}: download trigger label removed"); Console.WriteLine($" {headline.title}: download trigger label removed");

View File

@ -26,7 +26,7 @@ namespace ttrss_co_client.tasks
File.Move(workOrder.data["path"], outputFilename, true); File.Move(workOrder.data["path"], outputFilename, true);
var article = (await TtrssClient.GetArticles(workOrder.articleId))?.FirstOrDefault(); var article = (await TtrssClient.GetArticles(workOrder.articleId))?.FirstOrDefault();
await TtrssClient.UpdateArticleNote($"{article.note}\n[{DateTime.Now.ToString("o")}] - copied", article.id); await TtrssClient.UpdateArticleNote($"{article.note}\n[{DateTime.Now.ToString("o")}] - copied", article.id);
return new Tuple<TaskStatus, WorkOrder>(TaskStatus.Done, workOrder); return new Tuple<TaskStatus, WorkOrder>(TaskStatus.ContinueNow, workOrder);
} }
} }
} }

View File

@ -9,7 +9,6 @@ using ttrss_co_client.ttrss.datastructures;
namespace ttrss_co_client.tasks namespace ttrss_co_client.tasks
{ {
///<summary>Move to output</summary>
public class Sponsorblock : Phase2Task public class Sponsorblock : Phase2Task
{ {
public override string TaskName => "sponsorblock"; public override string TaskName => "sponsorblock";

View File

@ -35,6 +35,11 @@ namespace ttrss_co_client.tasks
toReturn.Phase2TaskList[3] = "filemovePublish"; toReturn.Phase2TaskList[3] = "filemovePublish";
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/recent episodes/"; toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/recent episodes/";
toReturn.Phase2TaskList[4] = "markread";
toReturn.Phase2TaskList[5] = "chatmessage";
toReturn.data["chatmessage"] = "new video from ";
await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id); await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id);
Console.WriteLine($" {headline.title}: download trigger label removed"); Console.WriteLine($" {headline.title}: download trigger label removed");