Skip to content

Commit

Permalink
Merge pull request #95 from Chhavi9700225780/master
Browse files Browse the repository at this point in the history
French Word Of The Day Card
  • Loading branch information
akanshSirohi authored Oct 15, 2024
2 parents 4b98d30 + 98787a4 commit cd317a7
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 176 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Here is a list of cards that can currently be used:
| `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)` |
| `french-word-of-the-day-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/french-word-of-the-day-card)` |

## Themes

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const available_cards = {
"/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"),
"/french-word-of-the-day-card": require("./src/cards/french_word_of_the_day"),
};

app.use(express.json());
Expand Down
1 change: 1 addition & 0 deletions src/cards/breaking-bad-quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require("fs").promises;
const { generateCard, CARD_AGE, Languages } = require("../card-generator");
const { parseOptions } = require("../options-parser");


const DATA_FILE_PATH = "./src/data/breaking-bad-quotes.json";
const DEFAULT_THEME = "dark_2";

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

const CARD_AGE = 86400;

const DATA_FILE_PATH = "./src/data/french_word_of_the_day.json";
const DEFAULT_THEME = "light";

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 FrenchwordOfTheDayData = JSON.parse(
await fs.readFile(DATA_FILE_PATH, "utf8")
);
const randomWord =
FrenchwordOfTheDayData[Math.floor(Math.random() * FrenchwordOfTheDayData.length)];
const FrenchwordContent = `${randomWord.french}\n\nMeaning: ${randomWord.english}`;

const FrenchwordCard = await generateCard(
FrenchwordContent,
req.theme,
req.options,
Languages.ENGLISH
);

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

module.exports = router;
120 changes: 120 additions & 0 deletions src/data/french_word_of_the_day.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
[
{ "french": "Bonjour", "english": "Hello" },
{ "french": "Merci", "english": "Thank you" },
{ "french": "S'il vous plaît", "english": "Please" },
{ "french": "Oui", "english": "Yes" },
{ "french": "Non", "english": "No" },
{ "french": "Au revoir", "english": "Goodbye" },
{ "french": "Amour", "english": "Love" },
{ "french": "Famille", "english": "Family" },
{ "french": "Ami", "english": "Friend" },
{ "french": "Maison", "english": "House" },
{ "french": "Chat", "english": "Cat" },
{ "french": "Chien", "english": "Dog" },
{ "french": "Voiture", "english": "Car" },
{ "french": "Fleur", "english": "Flower" },
{ "french": "Eau", "english": "Water" },
{ "french": "Pain", "english": "Bread" },
{ "french": "Soleil", "english": "Sun" },
{ "french": "Lune", "english": "Moon" },
{ "french": "Étoile", "english": "Star" },
{ "french": "Ciel", "english": "Sky" },
{ "french": "Terre", "english": "Earth" },
{ "french": "Montagne", "english": "Mountain" },
{ "french": "Mer", "english": "Sea" },
{ "french": "Plage", "english": "Beach" },
{ "french": "Ville", "english": "City" },
{ "french": "École", "english": "School" },
{ "french": "Travail", "english": "Work" },
{ "french": "Livre", "english": "Book" },
{ "french": "Musique", "english": "Music" },
{ "french": "Film", "english": "Movie" },
{ "french": "Chanson", "english": "Song" },
{ "french": "Art", "english": "Art" },
{ "french": "Danse", "english": "Dance" },
{ "french": "Jeu", "english": "Game" },
{ "french": "Sport", "english": "Sport" },
{ "french": "Nature", "english": "Nature" },
{ "french": "Histoire", "english": "History" },
{ "french": "Culture", "english": "Culture" },
{ "french": "Langue", "english": "Language" },
{ "french": "Pays", "english": "Country" },
{ "french": "Ville", "english": "Town" },
{ "french": "Route", "english": "Road" },
{ "french": "Pont", "english": "Bridge" },
{ "french": "Château", "english": "Castle" },
{ "french": "Parc", "english": "Park" },
{ "french": "Jardin", "english": "Garden" },
{ "french": "Chocolat", "english": "Chocolate" },
{ "french": "Glace", "english": "Ice cream" },
{ "french": "Fête", "english": "Party" },
{ "french": "Vacances", "english": "Vacation" },
{ "french": "Rêve", "english": "Dream" },
{ "french": "Espoir", "english": "Hope" },
{ "french": "Joie", "english": "Joy" },
{ "french": "Tristesse", "english": "Sadness" },
{ "french": "Colère", "english": "Anger" },
{ "french": "Peur", "english": "Fear" },
{ "french": "Confiance", "english": "Trust" },
{ "french": "Savoir", "english": "Knowledge" },
{ "french": "Réalité", "english": "Reality" },
{ "french": "Liberté", "english": "Freedom" },
{ "french": "Égalité", "english": "Equality" },
{ "french": "Fraternité", "english": "Brotherhood" },
{ "french": "École", "english": "School" },
{ "french": "Fleur", "english": "Flower" },
{ "french": "Café", "english": "Coffee" },
{ "french": "Thé", "english": "Tea" },
{ "french": "Fruits", "english": "Fruits" },
{ "french": "Légumes", "english": "Vegetables" },
{ "french": "Bureau", "english": "Office" },
{ "french": "Chaise", "english": "Chair" },
{ "french": "Table", "english": "Table" },
{ "french": "Fenêtre", "english": "Window" },
{ "french": "Porte", "english": "Door" },
{ "french": "Manteau", "english": "Coat" },
{ "french": "Chapeau", "english": "Hat" },
{ "french": "Chaussures", "english": "Shoes" },
{ "french": "Pantalon", "english": "Pants" },
{ "french": "Chemise", "english": "Shirt" },
{ "french": "Soleil", "english": "Sun" },
{ "french": "Lune", "english": "Moon" },
{ "french": "Cœur", "english": "Heart" },
{ "french": "Esprit", "english": "Mind" },
{ "french": "Corps", "english": "Body" },
{ "french": "Chanson", "english": "Song" },
{ "french": "Poème", "english": "Poem" },
{ "french": "Cadeau", "english": "Gift" },
{ "french": "Souvenir", "english": "Memory" },
{ "french": "Avion", "english": "Plane" },
{ "french": "Train", "english": "Train" },
{ "french": "Bateau", "english": "Boat" },
{ "french": "Vélo", "english": "Bicycle" },
{ "french": "Monde", "english": "World" },
{ "french": "Étoile", "english": "Star" },
{ "french": "Saison", "english": "Season" },
{"french": "travail", "english": "work"},
{"french": "valeur", "english": "value"},
{"french": "vérité", "english": "truth"},
{"french": "voix", "english": "voice"},
{"french": "absolu", "english": "absolute"},
{"french": "aventure", "english": "adventure"},
{"french": "bonté", "english": "kindness"},
{"french": "chance", "english": "luck"},
{"french": "défi", "english": "challenge"},
{"french": "énergie", "english": "energy"},
{"french": "esprit", "english": "spirit"},
{"french": "fantaisie", "english": "fantasy"},
{"french": "gentillesse", "english": "kindness"},
{"french": "intelligence", "english": "intelligence"},
{"french": "joie", "english": "joy"},
{"french": "libération", "english": "liberation"},
{"french": "mémoire", "english": "memory"},
{"french": "mystère", "english": "mystery"},
{"french": "noblesse", "english": "nobility"},
{"french": "optimisme", "english": "optimism"},
{"french": "persévérance", "english": "perseverance"}
]



9 changes: 9 additions & 0 deletions src/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ router.get("/", (req, res) => {
example: [`${baseurl}/word-of-the-day-card`],
},
},
"french-word-of-the-day-card": {
info: "Generates random french word of the day with their english meanings.",
api: {
args: {
theme: "Theme of card. All themes. Default: light [Optional]",
},
example: [`${baseurl}/french-word-of-the-day-card`],
},
},
"challenge-of-the-week-card": {
info: "Generates a random challenge for you to take on in that week.",
api: {
Expand Down
Loading

0 comments on commit cd317a7

Please sign in to comment.