Skip to content

Commit

Permalink
Fixed some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohansson committed Aug 19, 2024
1 parent 9932762 commit 5bea13c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion func-nyforvarvslistan/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Book
public List<Translator> Translator { get; set; }
public List<Publisher> PublisherName { get; set; }
public List<String> Extent { get; set; }
public List<String> PublicationCategory { get; set; }
// public List<String> PublicationCategory { get; set; }
public string Title { get; set; }
public string CoverHref { get; set; }
public string Description { get; set; }
Expand Down
20 changes: 13 additions & 7 deletions func-nyforvarvslistan/NyforvarvslistanFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,26 @@ public static class NyforvarvslistanFunction
});

private static readonly ElasticClient Client = new ElasticClient(ConnectionSettings);
private static DateTime? lastRunDate = null;

[FunctionName("NyforvarvslistanFunction")]
public static void Run([TimerTrigger("0 0 7 * * *", RunOnStartup = true)] TimerInfo myTimer, ILogger log)
{
try
{
bool isStartup = myTimer.IsPastDue;

if (isStartup || DateTime.UtcNow.Day == 1)
if (lastRunDate != DateTime.UtcNow.Date && DateTime.UtcNow.Day == 1)
{
lastRunDate = DateTime.UtcNow.Date;

SetBackMinervaLastRun(log);

Check warning on line 53 in func-nyforvarvslistan/NyforvarvslistanFunction.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 53 in func-nyforvarvslistan/NyforvarvslistanFunction.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
Task.Delay(30000).Wait();
CreateLists(log);

log.LogInformation("CreateLists executed successfully.");
}
else
{
SetBackMinervaLastRun(log);
log.LogInformation("CreateLists has already run today. Skipping execution.");
}
}
catch (RequestFailedException ex)
Expand Down Expand Up @@ -149,7 +152,7 @@ public static void CreateLists(ILogger log)
Description = source.SearchResultItem.Description,
LibraryId = source.SearchResultItem.LibraryId,
Category = getCategoryBasedOnClassification(source.Classification),
PublicationCategory = source.PublicationCategories,
// PublicationCategory = source.PublicationCategories,
AgeGroup = (source.SearchResultItem.AgeGroup == "Adult" || source.SearchResultItem.AgeGroup == "General") ? "Adult" : "Juvenile",
Language = source.SearchResultItem.Language,
LibrisId = source.SearchResultItem.LibrisId,
Expand All @@ -164,13 +167,16 @@ public static void CreateLists(ILogger log)
}).Where(book => book != null)
.ToList();

foreach (var book in books)
/*
* foreach (var book in books)
{
if (book.PublicationCategory.FirstOrDefault() == "Fiction")
{
book.Category = "Skönlitteratur";
}
}
*/


var talkingBooks = books.Where(b => b.Format == "Talbok" || b.Format == "Talbok med text").ToList();
var brailleBooks = books.Where(b => b.Format == "Punktskriftsbok").ToList();
Expand Down Expand Up @@ -295,7 +301,7 @@ public static void CreateLists(ILogger log)
if (generatedFiles.Any())
{
SendEmailWithAttachments(generatedFiles.ToArray(), "[email protected]");
// SendEmailWithAttachments(generatedFiles.ToArray(), "[email protected]");
SendEmailWithAttachments(generatedFiles.ToArray(), "[email protected]");
}
}

Expand Down
6 changes: 5 additions & 1 deletion func-nyforvarvslistan/XmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ public XElement GenerateBookDetailsXml(Book book, int level, string toLinkOrNotT

public XElement GenerateSwedishSectionXml(IEnumerable<Book> languageGroup, string toLinkOrNotToLink)
{
/*
foreach (var book in languageGroup)
{
if (book.PublicationCategory.FirstOrDefault() == "Fiction")
{
book.Category = "Skönlitteratur";
}
}
*/

XElement section = null;
var groupedByAgeGroup = languageGroup.GroupBy(b => b.AgeGroup).OrderBy(g => g.Key == "Adult" ? 0 : 1);
Expand Down Expand Up @@ -352,13 +354,15 @@ public void SaveToFile(IEnumerable<Book> books, string filePath)
}
public XElement GenerateNonSwedishSectionXml(IEnumerable<Book> languageGroup, string toLinkOrNotToLink)
{
foreach (var book in languageGroup)
/*
* foreach (var book in languageGroup)
{
if (book.PublicationCategory.FirstOrDefault() == "Fiction")
{
book.Category = "Skönlitteratur";
}
}
*/

var section = new XElement(ns + "level1", new XElement(ns + "h1", "Böcker på andra språk än svenska"));

Expand Down

0 comments on commit 5bea13c

Please sign in to comment.