From 0cbe75e9ac0941c9ccbecd10b7b84d00aca8cf84 Mon Sep 17 00:00:00 2001 From: H_vik Date: Thu, 10 Oct 2024 08:34:38 +0530 Subject: [PATCH 1/5] game of thrones quotes --- index.js | 3 +- src/cards/got-quotes.js | 47 ++++ src/data/got-quotes.json | 502 +++++++++++++++++++++++++++++++++++++++ src/help.js | 9 + 4 files changed, 560 insertions(+), 1 deletion(-) create mode 100644 src/cards/got-quotes.js create mode 100644 src/data/got-quotes.json diff --git a/index.js b/index.js index 2105394..2b0aa5d 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,8 @@ const available_cards = { "/programming-facts-card": require("./src/cards/programming-facts"), "/spanish-quote-card": require("./src/cards/spanish-quote"), "/top-tweets-card": require("./src/cards/top-tweets"), - "/github-facts-card": require("./src/cards/github-facts") + "/github-facts-card": require("./src/cards/github-facts"), + "/got-quotes-card": require("./src/cards/got-quotes") }; app.use(express.json()); diff --git a/src/cards/got-quotes.js b/src/cards/got-quotes.js new file mode 100644 index 0000000..30c9f5b --- /dev/null +++ b/src/cards/got-quotes.js @@ -0,0 +1,47 @@ +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/got-quotes.json"; +const DEFAULT_THEME = "dark_2"; + +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 gotquotes = JSON.parse(await fs.readFile(DATA_FILE_PATH, "utf8")); + const random_quotes = gotquotes[Math.floor(Math.random() * gotquotes.length)]; + + const quotes_content = `${random_quotes.sentence}\n\n- ${random_quotes.character}`; + const got_card = await generateCard( + quotes_content, + req.theme, + req.options, + Languages.ENGLISH + ); + + res.writeHead(200, { + "Content-Type": "image/svg+xml", + "Cache-Control": `public, max-age=${CARD_AGE}`, + }); + res.end(got_card); + } catch (error) { + console.error("Error:", error); + res.status(500).send("Internal Server Error"); + } +}); + +module.exports = router; \ No newline at end of file diff --git a/src/data/got-quotes.json b/src/data/got-quotes.json new file mode 100644 index 0000000..778d6d9 --- /dev/null +++ b/src/data/got-quotes.json @@ -0,0 +1,502 @@ +[ + { + "index": 1, + "sentence": "I did not kill Joffrey, but I wish that I had! Watching your vicious bastard die gave me more relief than a thousand lying whores!", + "character": "Tyrion Lannister" + }, + { + "index": 2, + "sentence": "I am your son. I have always been your son.", + "character": "Tyrion Lannister" + }, + { + "index": 3, + "sentence": "Never forget what you are. The rest of the world will not. Wear it like armour, and it can never be used to hurt you.", + "character": "Tyrion Lannister" + }, + { + "index": 4, + "sentence": "Thoros isn't here anymore, so I hope you're not about to give a sermon. Because if you are, the Lord of Light's gonna wonder why he brought you back 19 times just to watch you die when I chuck you over this fucking wall.", + "character": "Sandor Clegane" + }, + { + "index": 5, + "sentence": "I am the dragon's daughter, and I swear to you that those who would harm you will die screaming.", + "character": "Daenerys Targaryen" + }, + { + "index": 6, + "sentence": "Fighting bravely for a losing cause is admirable. Fighting for a winning cause is far more rewarding.", + "character": "Jaime Lannister" + }, + { + "index": 7, + "sentence": "No matter who you are, no matter how strong you are, sooner or later, you'll face circumstances beyond your control.", + "character": "Tyrion Lannister" + }, + { + "index": 8, + "sentence": "A Lannister always pays his debts.", + "character": "Tyrion Lannister" + }, + { + "index": 9, + "sentence": "You love your children. It's your one redeeming quality. That and your cheekbones.", + "character": "Tyrion Lannister" + }, + { + "index": 10, + "sentence": "Well, my brother has his sword, and I have my mind, and a mind needs books like a sword needs a whetstone, if it's to keep its edge.", + "character": "Tyrion Lannister" + }, + { + "index": 11, + "sentence": "You love your children. It's why you'll never win.", + "character": "Cersei Lannister" + }, + { + "index": 12, + "sentence": "Tell your father I'm here. And tell him the Lannisters aren't the only ones who pay their debts.", + "character": "Oberyn Martell" + }, + { + "index": 13, + "sentence": "All I ever wanted was to fight for a lord I believed in. But the good lords are dead and the rest are monsters.", + "character": "Brienne of Tarth" + }, + { + "index": 14, + "sentence": "It's not easy being drunk all the time. Everyone would do it, if it were easy.", + "character": "Tyrion Lannister" + }, + { + "index": 15, + "sentence": "All men must die, but we are not men.", + "character": "Daenerys Targaryen" + }, + { + "index": 16, + "sentence": "I was nothing at all. And when you're nothing at all, there's no reason to be afraid.", + "character": "Samwell Tarly" + }, + { + "index": 17, + "sentence": "The more people you love, the weaker you are.", + "character": "Cersei Lannister" + }, + { + "index": 18, + "sentence": "I will shield your back and keep your counsel, and give my life for yours if need be.", + "character": "Brienne of Tarth" + }, + { + "index": 19, + "sentence": "Leave one wolf alive and the sheep are never safe.", + "character": "Arya Stark" + }, + { + "index": 20, + "sentence": "Any man who must say 'I am the King' is no true King.", + "character": "Tywin Lannister" + }, + { + "index": 21, + "sentence": "I have a tender spot in my heart for cripples, bastards and broken things.", + "character": "Tyrion Lannister" + }, + { + "index": 22, + "sentence": "Never forget what you are. The rest of the world will not. Wear it like armor, and it can never be used to hurt you.", + "character": "Tyrion Lannister" + }, + { + "index": 23, + "sentence": "The day will come when you think you are safe and happy, and your joy will turn to ashes in your mouth.", + "character": "Tyrion Lannister" + }, + { + "index": 24, + "sentence": "Power, is power", + "character": "Cersei Lannister" + }, + { + "index": 25, + "sentence": "He's a Lannister! Maybe the lowest of the Lannisters, but he's one of us. And everyday that he remains a prisoner, the less our name commands respect.", + "character": "Tywin Lannister" + }, + { + "index": 26, + "sentence": "You want to lead one day? Then learn how to follow", + "character": "Joer Mormont" + }, + { + "index": 27, + "sentence": "I'm the King, I get what I want. I never loved my brothers. Sad thing for a man to admit, but it's true. You were the brother I chose.", + "character": "Robert Baratheon" + }, + { + "index": 28, + "sentence": "'Tis a big and beautiful world. Most of us live and die in the same corner where we were born and never get to see any of it. I don't want to be most of us.", + "character": "Oberyn Martell" + }, + { + "index": 29, + "sentence": "If you can't protect yourself, die and get out of the way of those who can. Sharp steel and strong arms rule this world, don't ever believe any different.", + "character": "Sandor Clegane" + }, + { + "index": 30, + "sentence": "It's better to be cruel than weak.", + "character": "Theon Greyjoy" + }, + { + "index": 31, + "sentence": "I have a lot of experience in losing.", + "character": "Tyrion Lannister" + }, + { + "index": 32, + "sentence": "People often claim to hunger for truth, but seldom like the taste when it's served up.", + "character": "Tyrion Lannister" + }, + { + "index": 33, + "sentence": "Why is it that when one man builds a wall, the next man immediately needs to know what's on the other side?", + "character": "Tyrion Lannister" + }, + { + "index": 34, + "sentence": "Fear cuts deeper than swords.", + "character": "Arya Stark" + }, + { + "index": 35, + "sentence": "Whilst Lord Janos was hiding with the women and children, Jon Snow was leading.", + "character": "Samwell Tarly" + }, + { + "index": 36, + "sentence": "By what right does the wolf judge the lion?", + "character": "Jaime Lannister" + }, + { + "index": 37, + "sentence": "No need to seize the last word, Lord Baelish. I'll assume it was something clever.", + "character": "Sansa Stark" + }, + { + "index": 38, + "sentence": "The storms come and go, the big fish eat the little fish and I keep on paddling.", + "character": "Lord Varys" + }, + { + "index": 39, + "sentence": "All this horror that has come to my family, it's all because I couldn't love a motherless child.", + "character": "Catelyn Stark" + }, + { + "index": 40, + "sentence": "My sword is yours, in victory and defeat, from this day until my last day.", + "character": "Theon Greyjoy" + }, + { + "index": 41, + "sentence": "I hate the king more than any of them.", + "character": "Sansa Stark" + }, + { + "index": 42, + "sentence": "Gingers are beautiful. We've been kissed by fire.", + "character": "Tormund" + }, + { + "index": 43, + "sentence": "Everything before the word \"but\" is horseshit.", + "character": "Jon Snow" + }, + { + "index": 44, + "sentence": "I may not know the north, but I know men. They're more or less the same in any corner of the world and even the bravest of them don't want to see their wives and children skinned for a lost cause.", + "character": "Davos Seaworth" + }, + { + "index": 45, + "sentence": "If I fall, don't bring me back.", + "character": "Jon Snow" + }, + { + "index": 46, + "sentence": "I was told you were drunk, impertinent and thoroughly debauched. You can imagine my disappointment at finding nothing but a browbeaten bookkeeper.", + "character": "Olenna Tyrell" + }, + { + "index": 47, + "sentence": "The things I do for love.", + "character": "Jaime Lannister" + }, + { + "index": 48, + "sentence": "We are only human, and the gods have fashioned us for love. That is our great glory, and our great tragedy.", + "character": "Aemon Targaryen" + }, + { + "index": 49, + "sentence": "Your lips are moving and you're complaining about something. That's whinging. This one's been killed six times. (points to Beric) You don't hear him bitching about it.", + "character": "Sandor Clegane" + }, + { + "index": 50, + "sentence": "The fall breaks them. And some are given a chance to climb; they cling to the real or the gods or love.", + "character": "Petyr Baelish" + }, + { + "index": 51, + "sentence": "If another house can seize one of our own and hold him captive with impunity, we are no longer a house to be feared.", + "character": "Tywin Lannister" + }, + { + "index": 52, + "sentence": "A man with no motive is a man no one suspects. Always keep your foes confused.", + "character": "Petyr Baelish" + }, + { + "index": 53, + "sentence": "There are no men like me. Only me.", + "character": "Jaime Lannister" + }, + { + "index": 54, + "sentence": "I swore a vow to the Night's Watch. If I don't take my own word seriously, what sort of \"Lord of Winterfell\" would I be?", + "character": "Jon Snow" + }, + { + "index": 55, + "sentence": "Hold the door.", + "character": "Hodor" + }, + { + "index": 56, + "sentence": "When the snows fall and the white winds blow, the lone wolf dies but the pack survives.", + "character": "Eddard \"Ned\" Stark" + }, + { + "index": 57, + "sentence": "Tears aren't a woman's only weapon. The best one's between your legs.", + "character": "Cersei Lannister" + }, + { + "index": 58, + "sentence": "If you think this has a happy ending, you haven't been paying attention.", + "character": "Ramsay Bolton" + }, + { + "index": 59, + "sentence": "A ruler who hides behind paid executioners soon forgets what death is.", + "character": "Eddard \"Ned\" Stark" + }, + { + "index": 60, + "sentence": "The man who passes the sentence should swing the sword.", + "character": "Eddard \"Ned\" Stark" + }, + { + "index": 61, + "sentence": "Chaos isn't a pit. Chaos is a ladder.", + "character": "Petyr Baelish" + }, + { + "index": 62, + "sentence": "You are being counseled at this very moment.", + "character": "Tywin Lannister" + }, + { + "index": 63, + "sentence": "I want our baby to live. Don't let me die, Jaime. Please don't let me die.", + "character": "Cersei Lannister" + }, + { + "index": 64, + "sentence": "Say what you will about the Targaryens, they were conquerors.", + "character": "Joffrey Baratheon" + }, + { + "index": 65, + "sentence": "It doesn’t matter what we want. Once we get it, then we want something else.", + "character": "Petyr Baelish" + }, + { + "index": 66, + "sentence": "I am Daenerys Stormborn of the Blood of old Valyria and I will take what is mine, with fire and blood I will take it.", + "character": "Daenerys Targaryen" + }, + { + "index": 67, + "sentence": "When you tear out a man's tongue, you are not proving him a liar, you're only telling the world that you fear what he might say.", + "character": "Tyrion Lannister" + }, + { + "index": 68, + "sentence": "How did a mad fucker like you live this long?", + "character": "Sandor Clegane" + }, + { + "index": 69, + "sentence": "The North remembers! We know no king but the King in the North whose name is Stark.", + "character": "Lyanna Mormont" + }, + { + "index": 70, + "sentence": "Yes, well I suppose life is irregular.", + "character": "Samwell Tarly" + }, + { + "index": 71, + "sentence": "There is only one war that matters. The Great War. And it is here.", + "character": "Jon Snow" + }, + { + "index": 72, + "sentence": "Can a man still be brave if he's afraid? That is the only time a man can be brave.", + "character": "Bran Stark" + }, + { + "index": 73, + "sentence": "Which war was won without deceit and mass murder?", + "character": "Daenerys Targaryen" + }, + { + "index": 74, + "sentence": "A lion does not concern himself with the opinion of sheep.", + "character": "Tywin Lannister" + }, + { + "index": 75, + "sentence": "I have always found revenge to be the purest of motivations.", + "character": "Petyr Baelish" + }, + { + "index": 76, + "sentence": "All my life men like you have sneered at me, and all my life I've been knocking men like you into the dust.", + "character": "Brienne of Tarth" + }, + { + "index": 77, + "sentence": "Thousands of men don't need to die. Only one of us. Let's end this the old way. You against me.", + "character": "Jon Snow" + }, + { + "index": 78, + "sentence": "I'm guilty of being a dwarf.", + "character": "Tyrion Lannister" + }, + { + "index": 79, + "sentence": "We don't have time for all this. The Night King has your dragon. He's one of them now. The Wall has fallen. The dead march south.", + "character": "Bran Stark" + }, + { + "index": 80, + "sentence": "The freedom to make my own mistakes was all I ever wanted.", + "character": "Mance Rayder" + }, + { + "index": 81, + "sentence": "Burn them all!", + "character": "Aerys II Targaryen" + }, + { + "index": 82, + "sentence": "If you ever call me sister again, I'll have you strangled in your sleep.", + "character": "Cersei Lannister" + }, + { + "index": 83, + "sentence": "You're a dragon. Be a dragon.", + "character": "Olenna Tyrell" + }, + { + "index": 84, + "sentence": "The war is not over. And I promise you, friend, the true enemy won't wait out the storm. He brings the storm.", + "character": "Jon Snow" + }, + { + "index": 85, + "sentence": "A hound will die for you, but never lie to you.", + "character": "Sandor Clegane" + }, + { + "index": 86, + "sentence": "He was no dragon. Fire cannot kill a dragon.", + "character": "Daenerys Targaryen" + }, + { + "index": 87, + "sentence": "It's always seemed there was an impossible choice I had to make...Stark or Greyjoy.", + "character": "Theon Greyjoy" + }, + { + "index": 88, + "sentence": "You're shit at dying you know that?.", + "character": "Sandor Clegane" + }, + { + "index": 89, + "sentence": "Hate's as good a thing as any to keep a person going. Better than most. We come across my brother, maybe we can both cross a name off our list.", + "character": "Sandor Clegane" + }, + { + "index": 90, + "sentence": "I wish I was the monster you think I am! I wish I had enough poison for the whole pack of you! I would gladly give my life to watch you all swallow it!", + "character": "Tyrion Lannister" + }, + { + "index": 91, + "sentence": "That bit of theatre will haunt our family for a generation.", + "character": "Tyrion Lannister" + }, + { + "index": 92, + "sentence": "Laughter is poison to fear.", + "character": "Catelyn Stark" + }, + { + "index": 93, + "sentence": "But sometimes before we can usher in the new, the old must be put to rest.", + "character": "Qyburn" + }, + { + "index": 94, + "sentence": "Everyone who makes a joke about a dwarf's height thinks he's the only person ever to make a joke about a dwarf's height.", + "character": "Tyrion Lannister" + }, + { + "index": 95, + "sentence": "I'm a constant disappointment to my own father, and I have learned to live with it.", + "character": "Tyrion Lannister" + }, + { + "index": 96, + "sentence": "When the snows fall and the white winds blow, the lone wolf dies, but the pack survives.", + "character": "Sansa Stark" + }, + { + "index": 97, + "sentence": "It doesn't matter what we want. Once we get it, then we want something else.", + "character": "Petyr Baelish" + }, + { + "index": 98, + "sentence": "When people ask you what happened here, tell them the North remembers. Tell them winter came for House Frey.", + "character": "Arya Stark" + }, + { + "index": 99, + "sentence": "Everyone is mine to torment.", + "character": "Joffrey Baratheon" + }, + { + "index": 100, + "sentence": "The night is dark and full of terrors.", + "character": "Melisandre" + } + ] \ No newline at end of file diff --git a/src/help.js b/src/help.js index 91c54d5..6ee6f1d 100644 --- a/src/help.js +++ b/src/help.js @@ -164,6 +164,15 @@ router.get("/", (req, res) => { example: [`${baseurl}/team-work-quote-card`], }, }, + "got-quotes-card": { + info: "Generate random motivational quote related to the game of thrones.", + api: { + args: { + theme: "Theme of card. All themes. Default: dark_2 [Optional]", + }, + example: [`${baseurl}/got-quotes-card`], + }, + }, "bhagavad-geeta-card": { info: "Generate a random quote from the bhagavad-geeta-card", api: { From c5c43d9d7a0f1df1bf077425bbd7ae6d53bf1f5d Mon Sep 17 00:00:00 2001 From: H_Vik <149999573+HritvikBhatia@users.noreply.github.com> Date: Fri, 11 Oct 2024 06:19:07 +0530 Subject: [PATCH 2/5] resolved conflict and error --- src/help.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/help.js b/src/help.js index fdc8f8f..de05a68 100644 --- a/src/help.js +++ b/src/help.js @@ -173,6 +173,7 @@ router.get("/", (req, res) => { example: [`${baseurl}/team-work-quote-card`], }, }, + "got-quotes-card": { info: "Generate random motivational quote related to the game of thrones.", api: { @@ -180,6 +181,9 @@ router.get("/", (req, res) => { theme: "Theme of card. All themes. Default: dark_2 [Optional]", }, example: [`${baseurl}/got-quotes-card`], + }, + }, + "breaking-bad-quote-card": { info: "Generate random motivational quote related to the breaking bad.", api: { @@ -189,6 +193,7 @@ router.get("/", (req, res) => { example: [`${baseurl}/breaking-bad-quote-card`], }, }, + "bhagavad-geeta-card": { info: "Generate a random quote from the bhagavad-geeta-card", api: { From 020265bfb5a9b8d80250b074265fcd2da9935d0b Mon Sep 17 00:00:00 2001 From: H_vik Date: Sat, 12 Oct 2024 00:37:32 +0530 Subject: [PATCH 3/5] modified readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index bc60f2a..a5037c3 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ Here is a list of cards that can currently be used: | `spanish-quote-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/spanish-quote-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/spanish-quote-card?theme=dark) | | `github-facts-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/github-facts-card?theme=dark)` | ![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)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/random-facts-card?theme=dark) | +| `brealing-bad-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/breaking-bad-quote-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/breaking-bad-quote-card?theme=dark) | +| `got-quote-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/got-quotes-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/got-quotes-card?theme=dark) | ## Themes From cee2967978e98b311cbf3d225335cff80ab9934b Mon Sep 17 00:00:00 2001 From: H_vik Date: Sat, 12 Oct 2024 00:44:20 +0530 Subject: [PATCH 4/5] conflict fix --- README.md | 4 ++-- index.js | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dfbe5f9..6dc338a 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,13 @@ Here is a list of cards that can currently be used: | `github-facts-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/github-facts-card?theme=dark)` | ![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)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/random-facts-card?theme=dark) | -| `brealing-bad-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/breaking-bad-quote-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/breaking-bad-quote-card?theme=dark) | +| `breaking-bad-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/breaking-bad-quote-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/breaking-bad-quote-card?theme=dark) | | `got-quote-card` | `![Card](https://afraid-ninnetta-github-cards.koyeb.app/got-quotes-card?theme=dark)` | ![Card](https://afraid-ninnetta-github-cards.koyeb.app/got-quotes-card?theme=dark) | ## Themes -### Options +### Options:wq You can customize the appearance of the cards by selecting one of the following themes: diff --git a/index.js b/index.js index dd90d88..335778a 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,6 @@ const available_cards = { "/spanish-quote-card": require("./src/cards/spanish-quote"), "/top-tweets-card": require("./src/cards/top-tweets"), "/github-facts-card": require("./src/cards/github-facts"), - "/random-facts-card": require("./src/cards/random-facts") "/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"), From 7d8fdb3116c47156cd210da0dc667cf0ced2fb03 Mon Sep 17 00:00:00 2001 From: Akansh Sirohi Date: Sat, 12 Oct 2024 22:51:53 +0530 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6471567..a9ea43a 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Here is a list of cards that can currently be used: ## Themes -### Options:wq +### Options You can customize the appearance of the cards by selecting one of the following themes: