Skip to content

Commit

Permalink
Merge pull request #87 from playing-god/master
Browse files Browse the repository at this point in the history
Added Harry Potter card following all the required steps.
  • Loading branch information
akanshSirohi authored Oct 12, 2024
2 parents bfdd417 + 73ae7fb commit 1df1e5b
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ Here is a list of cards that can currently be used:
| `fun-fact-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/fun-fact-card?theme=dark)` |
| `github-facts-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/github-facts-card?theme=dark)` |
| `random-facts-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/random-facts-card?theme=dark)` |
| `harry-potter-spell-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/harry-potter-spell-card?theme=dark)` |
| `breaking-bad-quote-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/breaking-bad-quote-card?theme=dark)` |
| `got-quotes-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/got-quotes-card?theme=dark)` |


## Themes

### Options
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const available_cards = {
"/random-facts-card": require("./src/cards/random-facts"),
"/fun-fact-card": require("./src/cards/fun-fact-card"),
"/got-quotes-card": require("./src/cards/got-quotes"),
"/harry-potter-spell-card": require("./src/cards/harry-potter-spells"),
};

app.use(express.json());
Expand Down
49 changes: 49 additions & 0 deletions src/cards/harry-potter-spells.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const express = require("express");
const router = express.Router();
const fs = require("fs").promises;
const { generateCard, CARD_AGE, Languages } = require("../card-generator");
const { parseOptions } = require("../options-parser");

const DATA_FILE_PATH = "./src/data/harry-potter-spells.json";
const DEFAULT_THEME = "dark";

const handleTheme = (req, res, next) => {
req.theme = req.query.theme || DEFAULT_THEME;
next();
};

const handleOptions = (req, res, next) => {
if (req.theme === "custom") {
req.options = parseOptions(req.query);
}
next();
};

router.get("/", handleTheme, handleOptions, async (req, res) => {
try {
const harryPotterSpellsData = JSON.parse(
await fs.readFile(DATA_FILE_PATH, "utf8")
);
const randomSpell =
harryPotterSpellsData[Math.floor(Math.random() * harryPotterSpellsData.length)];
const spellContent = `"${randomSpell.spell}"\n\nEffect: ${randomSpell.effect}`;

const spellCard = await generateCard(
spellContent,
req.theme,
req.options,
Languages.ENGLISH
);

res.writeHead(200, {
"Content-Type": "image/svg+xml",
"Cache-Control": `public, max-age=${CARD_AGE}`,
});
res.end(spellCard);
} catch (error) {
console.error("Error:", error);
res.status(500).send("Internal Server Error");
}
});

module.exports = router;
168 changes: 168 additions & 0 deletions src/data/harry-potter-spells.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
[
{ "index": 1, "spell": "Aberto", "type": "Charm", "effect": "Opens objects" },
{ "index": 2, "spell": "Accio", "type": "Charm", "effect": "Summons an object" },
{ "index": 3, "spell": "Age Line", "type": "Enchantment", "effect": "Hides things from younger people" },
{ "index": 4, "spell": "Aguamenti", "type": "Charm", "effect": "Shoots water from wand." },
{ "index": 5, "spell": "Alarte Ascendare", "type": "Spell", "effect": "Shoots things high in the air" },
{ "index": 6, "spell": "Alohomora", "type": "Charm", "effect": "Opens locked objects" },
{ "index": 7, "spell": "Anapneo", "type": "Spell", "effect": "Clears the target’s airway." },
{ "index": 8, "spell": "Anteoculatia", "type": "Hex", "effect": "Turns head hair into antlers" },
{ "index": 9, "spell": "Anti-Cheating", "type": "Spell", "effect": "Prevents Cheating on Exams" },
{ "index": 10, "spell": "Aparecium", "type": "Spell", "effect": "Reveals invisible ink" },
{ "index": 11, "spell": "Apparate", "type": "Spell", "effect": "Teleportation Spell" },
{ "index": 12, "spell": "Appare Vestigium", "type": "Spell", "effect": "Shows traces of recently used spells in the area" },
{ "index": 13, "spell": "Arania Exumai", "type": "Spell", "effect": "Blasts away Spiders" },
{ "index": 14, "spell": "Aqua Eructo", "type": "Spell", "effect": "Shoots water from wand" },
{ "index": 15, "spell": "Arresto Momentum", "type": "Spell", "effect": "Slows down objects" },
{ "index": 16, "spell": "Ascendio", "type": "Spell", "effect": "Moves an object upward" },
{ "index": 17, "spell": "Avada Kedavra", "type": "Curse", "effect": "Murders opponent – Unforgivable" },
{ "index": 18, "spell": "Avenseguim", "type": "Curse", "effect": "Tracking Spell" },
{ "index": 19, "spell": "Avifors", "type": "Charm", "effect": "Turns small objects into birds" },
{ "index": 20, "spell": "Avis", "type": "Spell", "effect": "Launches birds from your wand" },
{ "index": 21, "spell": "Babbling Curse", "type": "Curse", "effect": "Makes a person babble" },
{ "index": 22, "spell": "Baubillious", "type": "Spell", "effect": "Damages Opponent or Creatures (TCG)" },
{ "index": 23, "spell": "Bluebell Flames", "type": "Spell", "effect": "Shoots blue flames at opponent (TCG)" },
{ "index": 24, "spell": "Bombarda", "type": "Spell", "effect": "Causes explosions" },
{ "index": 25, "spell": "Bombarda Maxima", "type": "Spell", "effect": "Causes Large Explosions" },
{ "index": 26, "spell": "Bubble Head", "type": "Charm", "effect": "Puts a person's head in a protective air bubble" },
{ "index": 27, "spell": "Calvario", "type": "Spell", "effect": "Causes Hair Loss (Lego Video Games)" },
{ "index": 28, "spell": "Cantis", "type": "Spell", "effect": "Forces a person to sing (Lego Video Games)" },
{ "index": 29, "spell": "Carpe Retractum", "type": "Spell", "effect": "Shoots a rope from wand to snag things" },
{ "index": 30, "spell": "Cascading", "type": "Jinx", "effect": "Damages opponents (Video Games)" },
{ "index": 31, "spell": "Caterwauling", "type": "Charm", "effect": "Detects enemies and emits a scream" },
{ "index": 32, "spell": "Cave Inimicum", "type": "Charm", "effect": "Detects enemies and emits an alarm" },
{ "index": 33, "spell": "Cheering", "type": "Charm", "effect": "Makes a person happy and giddy" },
{ "index": 34, "spell": "Cistem Aperio", "type": "Spell", "effect": "Opens things" },
{ "index": 35, "spell": "Colloportus", "type": "Spell", "effect": "Locks Doors" },
{ "index": 36, "spell": "Colloshoo", "type": "Spell", "effect": "Makes a person’s shoes stick to the ground" },
{ "index": 37, "spell": "Colovaria", "type": "Charm", "effect": "Makes an object change color" },
{ "index": 38, "spell": "Combat Bolt", "type": "Spell", "effect": "Shoots a Bolt of energy (Wizards United Game)" },
{ "index": 39, "spell": "Confringo", "type": "Curse", "effect": "Explode Flames on target" },
{ "index": 40, "spell": "Confundus", "type": "Charm", "effect": "Used to confuse opponent" },
{ "index": 41, "spell": "Conjunctivitis", "type": "Curse", "effect": "Damages opponents eyesight" },
{ "index": 42, "spell": "Cornflake Skin", "type": "Curse", "effect": "Gives a person cereal skin" },
{ "index": 43, "spell": "Crucio", "type": "Curse", "effect": "Tortures opponent – Unforgivable" },
{ "index": 44, "spell": "Cushioning", "type": "Charm", "effect": "Helps cushion a fall" },
{ "index": 45, "spell": "Defodio", "type": "Spell", "effect": "Dig out materials" },
{ "index": 46, "spell": "Deletrius", "type": "Spell", "effect": "Counters 'Prior Incatato'" },
{ "index": 47, "spell": "Densaugeo", "type": "Spell", "effect": "Enlarges Teeth" },
{ "index": 48, "spell": "Deprimo", "type": "Spell", "effect": "Wind Damaging Spell" },
{ "index": 49, "spell": "Depulso", "type": "Charm", "effect": "Drives an object away" },
{ "index": 50, "spell": "Descendo", "type": "Spell", "effect": "Moves an object downwards" },
{ "index": 51, "spell": "Diffindo", "type": "Spell", "effect": "Splits seams" },
{ "index": 52, "spell": "Diminuendo", "type": "Spell", "effect": "Shrinks the target" },
{ "index": 53, "spell": "Dissendium", "type": "Spell", "effect": "Opens passageways" },
{ "index": 54, "spell": "Disillusionment", "type": "Charm", "effect": "Makes the target blend in to the surroundings" },
{ "index": 55, "spell": "Duro", "type": "Spell", "effect": "Makes Objects Hard" },
{ "index": 56, "spell": "Draconifors", "type": "Spell", "effect": "Turns target into a dragon (video games)" },
{ "index": 57, "spell": "Drought", "type": "Charm", "effect": "Dries up puddles" },
{ "index": 58, "spell": "Ducklifors", "type": "Spell", "effect": "Turns things into ducks (video games)" },
{ "index": 59, "spell": "Ears to Kumquats", "type": "Spell", "effect": "Give a person kumquat ears" },
{ "index": 60, "spell": "Ebublio", "type": "Spell", "effect": "Turns target into a bubble" },
{ "index": 61, "spell": "Engorgio", "type": "Charm", "effect": "Enlarges an item" },
{ "index": 62, "spell": "Engorgio Skullus", "type": "Spell", "effect": "Enlarges the skull (LEGO Harry Potter)" },
{ "index": 63, "spell": "Entomorphis", "type": "Spell", "effect": "Turns a target into an insect" },
{ "index": 64, "spell": "Episkey", "type": "Spell", "effect": "Heals minor injuries" },
{ "index": 65, "spell": "Epoximise", "type": "Spell", "effect": "Binds objects together" },
{ "index": 66, "spell": "Erecto", "type": "Spell", "effect": "Builds a structure" },
{ "index": 67, "spell": "Evanesco", "type": "Spell", "effect": "Vanishes objects" },
{ "index": 68, "spell": "Everte Statum", "type": "Spell", "effect": "Throws a victim backward" },
{ "index": 69, "spell": "Expecto Patronum", "type": "Charm", "effect": "Summons a Patronus to chase Dementors" },
{ "index": 70, "spell": "Expelliarmus", "type": "Charm", "effect": "Disarms your opponent" },
{ "index": 71, "spell": "Expulso", "type": "Curse", "effect": "Causes objects to explode" },
{ "index": 72, "spell": "Extinguishing", "type": "Spell", "effect": "Puts out fires" },
{ "index": 73, "spell": "Ferula", "type": "Charm", "effect": "Creates bandages" },
{ "index": 74, "spell": "Fianto Duri", "type": "Charm", "effect": "Strengthens shield spells" },
{ "index": 75, "spell": "Fidelius", "type": "Charm", "effect": "Hides a secret within a person" },
{ "index": 76, "spell": "Fiendfyre", "type": "Curse", "effect": "Unleashes large enchanted flames" },
{ "index": 77, "spell": "Finestra", "type": "Spell", "effect": "Shatters glass" },
{ "index": 78, "spell": "Finite", "type": "Spell", "effect": "Stops ongoing spells" },
{ "index": 79, "spell": "Finite Incantatem", "type": "Spell", "effect": "Stops all ongoing spells" },
{ "index": 80, "spell": "Flagrante", "type": "Curse", "effect": "Causes objects to burn those who touch them" },
{ "index": 81, "spell": "Flagrate", "type": "Charm", "effect": "Allows the user to write with fire" },
{ "index": 82, "spell": "Flipendo", "type": "Jinx", "effect": "Knocks an object backward" },
{ "index": 83, "spell": "Flying", "type": "Charm", "effect": "Makes objects fly" },
{ "index": 84, "spell": "Fumos", "type": "Spell", "effect": "Creates a cloud of smoke" },
{ "index": 85, "spell": "Furnunculus", "type": "Curse", "effect": "Produces boils on opponent" },
{ "index": 86, "spell": "Geminio", "type": "Spell", "effect": "Duplicates objects" },
{ "index": 87, "spell": "Glacius", "type": "Charm", "effect": "Freezes objects" },
{ "index": 88, "spell": "Glisseo", "type": "Charm", "effect": "Turns stairs into a slide" },
{ "index": 89, "spell": "Gripping", "type": "Charm", "effect": "Makes it easier to hold things" },
{ "index": 90, "spell": "Herbifors", "type": "Hex", "effect": "Grows flowers from the victim" },
{ "index": 91, "spell": "Homenum Revelio", "type": "Charm", "effect": "Reveals human presence" },
{ "index": 92, "spell": "Homonculous", "type": "Charm", "effect": "Tracks the movements of an individual" },
{ "index": 93, "spell": "Horcrux", "type": "Curse", "effect": "Allows wizard to put part of their soul into an object" },
{ "index": 94, "spell": "Horn Tongue", "type": "Hex", "effect": "Gives a person a horned tongue" },
{ "index": 95, "spell": "Illegibilus", "type": "Spell", "effect": "Makes writing impossible to read" },
{ "index": 96, "spell": "Immobulus", "type": "Charm", "effect": "Renders target immobile" },
{ "index": 97, "spell": "Impedimenta", "type": "Charm", "effect": "Slows an advancing object" },
{ "index": 98, "spell": "Imperio", "type": "Curse", "effect": "Controls a person’s actions – Unforgivable" },
{ "index": 99, "spell": "Impervius", "type": "Charm", "effect": "Makes an object waterproof" },
{ "index": 100, "spell": "Incarcerous", "type": "Spell", "effect": "Conjures ropes" },
{ "index": 101, "spell": "Incendio", "type": "Spell", "effect": "Starts a fire" },
{ "index": 102, "spell": "Inflatus", "type": "Charm", "effect": "Inflates objects" },
{ "index": 103, "spell": "Lacarnum Inflamarae", "type": "Charm", "effect": "Shoots fireballs" },
{ "index": 104, "spell": "Langlock", "type": "Spell", "effect": "Glues opponent’s tongue to roof of mouth" },
{ "index": 105, "spell": "Lapifors", "type": "Spell", "effect": "Turns small objects into rabbits" },
{ "index": 106, "spell": "Levicorpus", "type": "Spell", "effect": "Dangles a person upside-down" },
{ "index": 107, "spell": "Liberacorpus", "type": "Spell", "effect": "Counteracts Levicorpus" },
{ "index": 108, "spell": "Locomotor", "type": "Charm", "effect": "Moves objects through the air" },
{ "index": 109, "spell": "Locomotor Mortis", "type": "Curse", "effect": "Locks opponent’s legs" },
{ "index": 110, "spell": "Lumos", "type": "Charm", "effect": "Creates light at the tip of the caster's wand" },
{ "index": 111, "spell": "Lumos Maxima", "type": "Charm", "effect": "Creates an intense ball of light" },
{ "index": 112, "spell": "Lumos Solem", "type": "Charm", "effect": "Produces sunlight" },
{ "index": 113, "spell": "Maledictus", "type": "Curse", "effect": "Curses the victim to permanently transform into an animal" },
{ "index": 114, "spell": "Melofors", "type": "Jinx", "effect": "Gives a person a pumpkin for a head" },
{ "index": 115, "spell": "Meteolojinx Recanto", "type": "Spell", "effect": "Stops weather effects" },
{ "index": 116, "spell": "Mobiliarbus", "type": "Charm", "effect": "Moves trees" },
{ "index": 117, "spell": "Mobilicorpus", "type": "Charm", "effect": "Moves bodies" },
{ "index": 118, "spell": "Morsmordre", "type": "Spell", "effect": "Conjures the Dark Mark" },
{ "index": 119, "spell": "Muffliato", "type": "Charm", "effect": "Prevents others from overhearing conversations" },
{ "index": 120, "spell": "Nox", "type": "Charm", "effect": "Counters Lumos by extinguishing light" },
{ "index": 121, "spell": "Obliterate", "type": "Charm", "effect": "Erases tracks and footprints" },
{ "index": 122, "spell": "Obliviate", "type": "Charm", "effect": "Erases memories" },
{ "index": 123, "spell": "Obscuro", "type": "Spell", "effect": "Blindfolds the victim" },
{ "index": 124, "spell": "Oppugno", "type": "Spell", "effect": "Directs objects to attack a target" },
{ "index": 125, "spell": "Orchideous", "type": "Spell", "effect": "Conjures a bouquet of flowers" },
{ "index": 126, "spell": "Pack", "type": "Spell", "effect": "Packs a suitcase or bag" },
{ "index": 127, "spell": "Partis Temporus", "type": "Charm", "effect": "Creates a gap in magical barriers" },
{ "index": 128, "spell": "Periculum", "type": "Charm", "effect": "Creates red sparks as a signal for help" },
{ "index": 129, "spell": "Petrificus Totalus", "type": "Spell", "effect": "Full body-bind curse" },
{ "index": 130, "spell": "Piertotum Locomotor", "type": "Spell", "effect": "Animates statues and suits of armor" },
{ "index": 131, "spell": "Point Me", "type": "Charm", "effect": "Makes the wand act like a compass" },
{ "index": 132, "spell": "Portus", "type": "Charm", "effect": "Turns objects into Portkeys" },
{ "index": 133, "spell": "Priori Incantatem", "type": "Spell", "effect": "Reveals the last spell cast by a wand" },
{ "index": 134, "spell": "Protego", "type": "Charm", "effect": "Casts a magical shield to block spells" },
{ "index": 135, "spell": "Protego Diabolica", "type": "Charm", "effect": "Creates protective black fire" },
{ "index": 136, "spell": "Protego Horribilis", "type": "Charm", "effect": "Protects against dark magic" },
{ "index": 137, "spell": "Protego Maxima", "type": "Charm", "effect": "Creates a very strong magical barrier" },
{ "index": 138, "spell": "Protego Totalum", "type": "Charm", "effect": "Provides protection for a specific area" },
{ "index": 139, "spell": "Quietus", "type": "Charm", "effect": "Reverses the effects of Sonorus" },
{ "index": 140, "spell": "Reducio", "type": "Spell", "effect": "Shrinks objects" },
{ "index": 141, "spell": "Reducto", "type": "Spell", "effect": "Blasts solid objects aside" },
{ "index": 142, "spell": "Relashio", "type": "Spell", "effect": "Releases a user from bindings or chains" },
{ "index": 143, "spell": "Rennervate", "type": "Spell", "effect": "Revives someone from unconsciousness" },
{ "index": 144, "spell": "Reparo", "type": "Spell", "effect": "Repairs broken objects" },
{ "index": 145, "spell": "Repello Muggletum", "type": "Charm", "effect": "Keeps Muggles away" },
{ "index": 146, "spell": "Repello Inimicum", "type": "Charm", "effect": "Keeps enemies away from a large area" },
{ "index": 147, "spell": "Rictusempra", "type": "Charm", "effect": "Causes the victim to laugh uncontrollably" },
{ "index": 148, "spell": "Riddikulus", "type": "Charm", "effect": "Defeats a Boggart by making it comical" },
{ "index": 149, "spell": "Salvio Hexia", "type": "Charm", "effect": "Protects an area against hexes" },
{ "index": 150, "spell": "Scourgify", "type": "Charm", "effect": "Cleans an object" },
{ "index": 151, "spell": "Sectumsempra", "type": "Curse", "effect": "Causes deep cuts" },
{ "index": 152, "spell": "Serpensortia", "type": "Spell", "effect": "Conjures a snake" },
{ "index": 153, "spell": "Silencio", "type": "Spell", "effect": "Silences the target" },
{ "index": 154, "spell": "Sonorus", "type": "Charm", "effect": "Amplifies the caster's voice" },
{ "index": 155, "spell": "Specialis Revelio", "type": "Spell", "effect": "Reveals hidden magical properties" },
{ "index": 156, "spell": "Stupefy", "type": "Spell", "effect": "Stuns the target" },
{ "index": 157, "spell": "Tarantallegra", "type": "Spell", "effect": "Forces the target to dance" },
{ "index": 158, "spell": "Tergeo", "type": "Spell", "effect": "Clears up messes" },
{ "index": 159, "spell": "Ventus", "type": "Spell", "effect": "Conjures a gust of wind" },
{ "index": 160, "spell": "Vera Verto", "type": "Spell", "effect": "Turns animals into goblets" },
{ "index": 161, "spell": "Verdimillious", "type": "Spell", "effect": "Reveals hidden objects" },
{ "index": 162, "spell": "Vipera Evanesca", "type": "Spell", "effect": "Makes snakes disappear" },
{ "index": 163, "spell": "Vulnera Sanentur", "type": "Spell", "effect": "Heals deep wounds" },
{ "index": 164, "spell": "Waddiwasi", "type": "Spell", "effect": "Shoots small objects at a target" },
{ "index": 165, "spell": "Wingardium Leviosa", "type": "Charm", "effect": "Makes objects float" }
]

Loading

0 comments on commit 1df1e5b

Please sign in to comment.