Created
April 3, 2023 16:39
-
-
Save lfoust/a12de47961b22856b17e17ff6d14517d to your computer and use it in GitHub Desktop.
Parse the recipes exported from the Paprika recipe manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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