Skip to content

Instantly share code, notes, and snippets.

@lfoust
Created April 3, 2023 16:39
Show Gist options
  • Save lfoust/a12de47961b22856b17e17ff6d14517d to your computer and use it in GitHub Desktop.
Save lfoust/a12de47961b22856b17e17ff6d14517d to your computer and use it in GitHub Desktop.
Parse the recipes exported from the Paprika recipe manager
var results = new List<Recipe>();
string filePath = System.IO.Path.Combine(environment.ContentRootPath, "Recipes.zip");
if (File.Exists(filePath))
{
using (ZipArchive archive = ZipFile.OpenRead(filePath))
{
foreach (ZipArchiveEntry zipItem in archive.Entries)
{
using (var stream = zipItem.Open())
using (var inputStream = new GZipStream(stream, CompressionMode.Decompress))
using (var outStream = new MemoryStream())
{
inputStream.CopyTo(outStream);
string json = Encoding.UTF8.GetString(outStream.ToArray());
var recipe = JsonSerializer.Deserialize<Recipe>(json);
results.Add(recipe);
}
}
}
}
return results;
using System.Text.Json.Serialization;
using System.Collections.Generic;
public class Recipe
{
[JsonPropertyName("uid")]
public string Uid { get; set; }
[JsonPropertyName("created")]
public string Created { get; set; }
[JsonPropertyName("hash")]
public string Hash { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonPropertyName("ingredients")]
public string Ingredients { get; set; }
[JsonPropertyName("directions")]
public string Directions { get; set; }
[JsonPropertyName("notes")]
public string Notes { get; set; }
[JsonPropertyName("nutritional_info")]
public string NutritionalInfo { get; set; }
[JsonPropertyName("prep_time")]
public string Preptime { get; set; }
[JsonPropertyName("cook_time")]
public string CookTime { get; set; }
[JsonPropertyName("total_time")]
public string TotalTime { get; set; }
[JsonPropertyName("difficulty")]
public string Difficulty { get; set; }
[JsonPropertyName("servings")]
public string Servings { get; set; }
[JsonPropertyName("rating")]
public float Rating { get; set; }
[JsonPropertyName("source")]
public string Source { get; set; }
[JsonPropertyName("source_url")]
public string SourceUrl { get; set; }
[JsonPropertyName("photo")]
public string Photo { get; set; }
[JsonPropertyName("photo_large")]
public string PhotoLarge { get; set; }
[JsonPropertyName("photo_hash")]
public string PhotoHash { get; set; }
[JsonPropertyName("image_url")]
public string ImageUrl { get; set; }
[JsonPropertyName("photo_data")]
public string PhotoData { get; set; }
[JsonPropertyName("categories")]
public IReadOnlyList<string> Categories { get; set; } = new List<string>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment