Skip to content

Commit

Permalink
Remove CDATA
Browse files Browse the repository at this point in the history
  • Loading branch information
laudebugs committed Oct 14, 2024
1 parent 0e88794 commit 0346b91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
15 changes: 11 additions & 4 deletions FeedParser/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// See https://aka.ms/new-console-template for more information
using System.Xml;
using System.Xml.Linq;
using CodeHollow.FeedReader;
using Newtonsoft.Json;
using OPMLCore.NET;
Expand Down Expand Up @@ -43,10 +44,16 @@
{
var parsedFeed = await FeedReader.ReadAsync(xmlUrl);
Console.WriteLine($"Parsed Feed {parsedFeed.Title}");
// Write to file
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(parsedFeed.OriginalDocument);
var feedAsJson = JsonConvert.SerializeXmlNode(xmlDocument, Newtonsoft.Json.Formatting.Indented);
// How to remove #cdata-section when convert xml to json using Linq
// https://gist.github.com/micheletolve/4b511875bfff23fe6970960d6ec3d175
var doc = XElement.Parse(parsedFeed.OriginalDocument);
var node_cdata = doc.DescendantNodes().OfType<XCData>().ToList();
foreach (var node in node_cdata)
{
node.Parent.Add(node.Value);

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.

Check warning on line 53 in FeedParser/Program.cs

View workflow job for this annotation

GitHub Actions / generate-podcast-data (8.x)

Dereference of a possibly null reference.
node.Remove();
}
var feedAsJson = JsonConvert.SerializeXNode(doc, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText($"{workingDir}/tmp/dist/podcasts/{helper.GenerateSlug(parsedFeed.Title)}.json", feedAsJson);

return parsedFeed;
Expand Down
12 changes: 9 additions & 3 deletions scripts/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ def first_3_colors(palette):
logFile.write("## Color Palette Generation: \n")

def log_error(podcast, error):
logFile.write("An exception occurred for: "+ podcast['title']+"\n: "+ str(error) + "\n")
print ("An exception occurred for: ", podcast['rss']['channel']['title'], "\n: ", error)
logFile.write("An exception occurred for: "+ podcast['rss']['channel']['title'] +"\n: "+ str(error) + "\n")

def generate_color_palette(podcast_image):
palette = []
try:
if ( 'url' in podcast_image):
if ('url' in podcast_image):
image = download_image(podcast_image['url'])
palette = get_color_palette(image)
palette = first_3_colors(palette)
Expand All @@ -57,10 +58,15 @@ def generate_color_palette(podcast_image):
for index, podcastFile in enumerate(podcastFileNames):
podFile = open(podcastsFolder+'/'+podcastFile,'r')
data = podFile.read()
try:
json.loads(data)
except Exception as error:
log_error(podcast, error)
continue
podcast = json.loads(data)
palette = []
if('image' in podcast['rss']['channel']):
print('Generating palette for: ', podcast['rss']['channel']['image'])
print('Generating palette for: ', podcast['rss']['channel']['title'])
palette = generate_color_palette(podcast['rss']['channel']['image'])
podcast['rss']['channel']['image']['palette'] = palette

Expand Down

0 comments on commit 0346b91

Please sign in to comment.