diff --git a/app/database/models.py b/app/database/models.py index 0e4f4aea..20df5947 100644 --- a/app/database/models.py +++ b/app/database/models.py @@ -382,6 +382,13 @@ def __repr__(self): ) +class Joke(Base): + __tablename__ = "jokes" + + id = Column(Integer, primary_key=True, index=True) + text = Column(String, nullable=False) + + # insert language data # Credit to adrihanu https://stackoverflow.com/users/9127249/adrihanu diff --git a/app/internal/jokes.py b/app/internal/jokes.py new file mode 100644 index 00000000..d8de9456 --- /dev/null +++ b/app/internal/jokes.py @@ -0,0 +1,24 @@ +from typing import Dict, Optional + +from sqlalchemy.orm import Session +from sqlalchemy.sql.expression import func + +from app.database.models import Joke + + +def get_joke(joke_: Dict[str, Optional[str]]) -> Joke: + """Returns a Joke object from the dictionary data. + + Args: + joke_: A dictionary joke related information. + + Returns: + A new Joke object. + """ + return Joke( + text=joke_['text'], + ) + + +def get_a_joke(session: Session): + return session.query(Joke).order_by(func.random()).first() diff --git a/app/internal/json_data_loader.py b/app/internal/json_data_loader.py index d67443e6..4e9d83e7 100644 --- a/app/internal/json_data_loader.py +++ b/app/internal/json_data_loader.py @@ -5,8 +5,8 @@ from loguru import logger from sqlalchemy.orm import Session -from app.database.models import Base, Quote, Zodiac -from app.internal import daily_quotes, zodiac +from app.database.models import Base, Joke, Quote, Zodiac +from app.internal import daily_quotes, jokes, zodiac def load_to_database(session: Session) -> None: @@ -35,6 +35,13 @@ def load_to_database(session: Session) -> None: daily_quotes.get_quote, ) + _insert_into_database( + session, + 'app/resources/jokes.json', + Joke, + jokes.get_joke, + ) + def _insert_into_database( session: Session, diff --git a/app/main.py b/app/main.py index 39e24cdc..e6e4af34 100644 --- a/app/main.py +++ b/app/main.py @@ -42,7 +42,7 @@ def create_tables(engine, psql_environment): from app.routers import ( # noqa: E402 about_us, agenda, calendar, categories, celebrity, credits, currency, dayview, email, event, export, four_o_four, friendview, - google_connect, invitation, login, logout, profile, + google_connect, invitation, joke, login, logout, profile, register, search, telegram, user, weekview, whatsapp, ) @@ -82,6 +82,7 @@ async def swagger_ui_redirect(): four_o_four.router, google_connect.router, invitation.router, + joke.router, login.router, logout.router, profile.router, diff --git a/app/resources/jokes.json b/app/resources/jokes.json new file mode 100644 index 00000000..4950d6c3 --- /dev/null +++ b/app/resources/jokes.json @@ -0,0 +1,368 @@ +[ + {"text": "Chuck Norris uses ribbed condoms inside out, so he gets the pleasure."}, + {"text": "MacGyver can build an airplane out of gum and paper clips. Chuck Norris can kill him and take it."}, + {"text": "Chuck Norris doesn't read books. He stares them down until he gets the information he wants."}, + {"text": "Chuck Norris lost his virginity before his dad did."}, + {"text": "Since 1940, the year Chuck Norris was born, roundhouse kick related deaths have increased 13,000 percent."}, + {"text": "Chuck Norris sheds his skin twice a year."}, + {"text": "When Chuck Norris goes to donate blood, he declines the syringe, and instead requests a hand gun and a bucket."}, + {"text": "Chuck Norris does not teabag the ladies. He potato-sacks them."}, + {"text": "In an average living room there are 1,242 objects Chuck Norris could use to kill you, including the room itself."}, + {"text": "Chuck Norris doesn't shower, he only takes blood baths."}, + {"text": "Time waits for no man. Unless that man is Chuck Norris."}, + {"text": "In the Bible, Jesus turned water into wine. But then Chuck Norris turned that wine into beer."}, + {"text": "Chuck Norris is not hung like a horse. Horses are hung like Chuck Norris."}, + {"text": "Chuck Norris has two speeds: Walk and Kill."}, + {"text": "Fool me once, shame on you. Fool Chuck Norris once and he will roundhouse kick you in the face."}, + {"text": "If you spell Chuck Norris in Scrabble, you win. Forever."}, + {"text": "Someone once videotaped Chuck Norris getting pissed off. It was called Walker: Texas Chain Saw Masacre."}, + {"text": "Chuck Norris will attain statehood in 2009. His state flower will be the Magnolia."}, + {"text": "Chuck Norris doesn't wash his clothes. He disembowels them."}, + {"text": "Chuck Norris doesn't churn butter. He roundhouse kicks the cows and the butter comes straight out."}, + {"text": "Police label anyone attacking Chuck Norris as a Code 45-11.... A suicide."}, + {"text": "Chuck Norris is the only man to ever defeat a brick wall in a game of tennis."}, + {"text": "What was going through the minds of all of Chuck Norris' victims before they died? His shoe."}, + {"text": "Chuck Norris once ate three 72 oz. steaks in one hour. He spent the first 45 minutes having sex with his waitress."}, + {"text": "There is no theory of evolution, just a list of creatures Chuck Norris allows to live."}, + {"text": "Chuck Norris can win a game of Connect Four in only three moves."}, + {"text": "The quickest way to a man's heart is with Chuck Norris' fist."}, + {"text": "Chuck Norris drives an ice cream truck covered in human skulls."}, + {"text": "Most people have 23 pairs of chromosomes. Chuck Norris has 72... and they're all poisonous."}, + {"text": "The Great Wall of China was originally created to keep Chuck Norris out. It failed miserably."}, + {"text": "Chuck Norris is ten feet tall, weighs two-tons, breathes fire, and could eat a hammer and take a shotgun blast standing."}, + {"text": "Crop circles are Chuck Norris' way of telling the world that sometimes corn needs to lie down."}, + {"text": "When Chuck Norris calls 1-900 numbers, he doesn't get charged. He holds up the phone and money falls out."}, + {"text": "Chuck Norris once ate a whole cake before his friends could tell him there was a stripper in it."}, + {"text": "Some people like to eat frogs' legs. Chuck Norris likes to eat lizard legs. Hence, snakes."}, + {"text": "There are no races, only countries of people Chuck Norris has beaten to different shades of black and blue."}, + {"text": "A Chuck Norris-delivered Roundhouse Kick is the preferred method of execution in 16 states."}, + {"text": "When Chuck Norris falls in water, Chuck Norris doesn't get wet. Water gets Chuck Norris."}, + {"text": "Chuck Norris' house has no doors, only walls that he walks through."}, + {"text": "When Chuck Norris has sex with a man, it won't be because he is gay. It will be because he has run out of women."}, + {"text": "How much wood would a woodchuck chuck if a woodchuck could Chuck Norris? All of it."}, + {"text": "Chuck Norris doesn't actually write books, the words assemble themselves out of fear."}, + {"text": "Chuck Norris can believe it's not butter."}, + {"text": "If tapped, a Chuck Norris roundhouse kick could power the country of Australia for 44 minutes."}, + {"text": "Chuck Norris can divide by zero."}, + {"text": "Chuck Norris invented his own type of karate. It's called Chuck-Will-Kill."}, + {"text": "While urinating, Chuck Norris is easily capable of welding titanium."}, + {"text": "When Chuck Norris talks, everybody listens. And dies."}, + {"text": "When Steven Seagal kills a ninja, he only takes its hide. When Chuck Norris kills a ninja, he uses every part."}, + {"text": "Contrary to popular belief, there is indeed enough Chuck Norris to go around."}, + {"text": "Chuck Norris doesnt shave; he kicks himself in the face. The only thing that can cut Chuck Norris is Chuck Norris."}, + {"text": "For some, the left testicle is larger than the right one. For Chuck Norris, each testicle is larger than the other one."}, + {"text": "Chuck Norris always knows the EXACT location of Carmen SanDiego."}, + {"text": "Chuck Norris invented black. In fact, he invented the entire spectrum of visible light. Except pink. Tom Cruise invented pink."}, + {"text": "When you're Chuck Norris, anything + anything is equal to 1. One roundhouse kick to the face."}, + {"text": "On his birthday, Chuck Norris randomly selects one lucky child to be thrown into the sun."}, + {"text": "Nobody doesn't like Sara Lee. Except Chuck Norris."}, + {"text": "Chuck Norris doesn't throw up if he drinks too much. Chuck Norris throws down!"}, + {"text": "Chuck Norris has 12 moons. One of those moons is the Earth."}, + {"text": "Chuck Norris grinds his coffee with his teeth and boils the water with his own rage."}, + {"text": "Chuck Norris ordered a Big Mac at Burger King, and got one."}, + {"text": "Chuck Norris can drink an entire gallon of milk in thirty-seven seconds."}, + {"text": "Chuck Norris doesn't bowl strikes, he just knocks down one pin and the other nine faint."}, + {"text": "It takes Chuck Norris 20 minutes to watch 60 Minutes."}, + {"text": "Chuck Norris has a deep and abiding respect for human life... unless it gets in his way."}, + {"text": "The Bermuda Triangle used to be the Bermuda Square, until Chuck Norris Roundhouse kicked one of the corners off."}, + {"text": "Chuck Norris doesn't believe in Germany."}, + {"text": "When Chuck Norris is in a crowded area, he doesn't walk around people. He walks through them."}, + {"text": "Chuck Norris once ate an entire bottle of sleeping pills. They made him blink."}, + {"text": "Chuck Norris can touch MC Hammer."}, + {"text": "Chuck Norris played Russian Roulette with a fully loaded gun and won."}, + {"text": "It takes 14 puppeteers to make Chuck Norris smile, but only 2 to make him destroy an orphanage."}, + {"text": "Some people wear Superman pajamas. Superman wears Chuck Norris pajamas."}, + {"text": "Simply by pulling on both ends, Chuck Norris can stretch diamonds back into coal."}, + {"text": "When Chuck Norris does a pushup, he isn't lifting himself up, he's pushing the Earth down."}, + {"text": "Chuck Norris invented the bolt-action rifle, liquor, sexual intercourse, and football-- in that order."}, + {"text": "A high tide means Chuck Norris is flying over your coast. The tide is caused by God pissing his pants."}, + {"text": "There is in fact an 'I' in Norris, but there is no 'team'. Not even close."}, + {"text": "An anagram for Walker Texas Ranger is KARATE WRANGLER SEX. I don't know what that is, but it sounds AWESOME."}, + {"text": "Chuck Norris doesn't stub his toes. He accidentally destroys chairs, bedframes, and sidewalks."}, + {"text": "Chuck Norris does not own a stove, oven, or microwave , because revenge is a dish best served cold."}, + {"text": "Chuck Norris can slam a revolving door."}, + {"text": "Chuck Norris built a better mousetrap, but the world was too frightened to beat a path to his door."}, + {"text": "Hellen Keller's favorite color is Chuck Norris."}, + {"text": "If, by some incredible space-time paradox, Chuck Norris would ever fight himself, he'd win. Period."}, + {"text": "Chuck Norris is currently suing myspace for taking the name of what he calls everything around you."}, + {"text": "Science Fact: Roundhouse kicks are comprised primarily of an element called Chucktanium."}, + {"text": "Chuck Norris proved that we are alone in the universe. We weren't before his first space expedition."}, + {"text": "Superman once watched an episode of Walker, Texas Ranger. He then cried himself to sleep."}, + {"text": "Chuck Norris doesn't step on toes. Chuck Norris steps on necks."}, + {"text": "There is no such thing as global warming. Chuck Norris was cold, so he turned the sun up."}, + {"text": "A study showed the leading causes of death in the United States are: 1. Heart disease, 2. Chuck Norris, 3. Cancer"}, + {"text": "Chuck Norris did in fact, build Rome in a day."}, + {"text": "Along with his black belt, Chuck Norris often chooses to wear brown shoes. No one has DARED call him on it. Ever."}, + {"text": "Once you go Norris, you are physically unable to go back."}, + {"text": "Ninjas want to grow up to be just like Chuck Norris. But usually they grow up just to be killed by Chuck Norris."}, + {"text": "The last thing you hear before Chuck Norris gives you a roundhouse kick? No one knows because dead men tell no tales."}, + {"text": "Chuck Norris doesn't play god. Playing is for children."}, + {"text": "Chuck Norris is the only person in the world that can actually email a roundhouse kick."}, + {"text": "Chuck Norris won super bowls VII and VIII singlehandedly before unexpectedly retiring to pursue a career in ass-kicking."}, + {"text": "Chuck Norris can set ants on fire with a magnifying glass. At night."}, + {"text": "Some kids play Kick the can. Chuck Norris played Kick the keg."}, + {"text": "'Icy-Hot' is too weak for Chuck Norris. After a workout, Chuck Norris rubs his muscles down with liquid-hot MAGMA."}, + {"text": "Chuck Norris cannot love, he can only not kill."}, + {"text": "When Chuck Norris was a baby, he didn't suck his mother's breast. His mother served him whiskey, straight out of the bottle."}, + {"text": "According to Einstein's theory of relativity, Chuck Norris can actually roundhouse kick you yesterday."}, + {"text": "Chuck Norris once pulled out a single hair from his beard and skewered three men through the heart with it."}, + {"text": "Chuck Norris? favourite cut of meat is the roundhouse."}, + {"text": "Chuck Norris recently had the idea to sell his urine as a canned beverage. We know this beverage as Red Bull."}, + {"text": "If at first you don't succeed, you're not Chuck Norris."}, + {"text": "If Chuck Norris were a calendar, every month would be named Chucktober, and every day he'd kick your ass."}, + {"text": "# Chuck Norris's show is called Walker: Texas Ranger, because Chuck Norris doesn't run."}, + {"text": "Behind every successful man, there is a woman. Behind every dead man, there is Chuck Norris."}, + {"text": "Chuck Norris brushes his teeth with a mixture of iron shavings, industrial paint remover, and wood-grain alcohol."}, + {"text": "The easiest way to determine Chuck Norris' age is to cut him in half and count the rings."}, + {"text": "There is endless debate about the existence of the human soul. Well it does exist and Chuck Norris finds it delicious."}, + {"text": "Most boots are made for walkin'. Chuck Norris' boots ain't that merciful."}, + {"text": "Chuck Norris wears a live rattlesnake as a condom."}, + {"text": "Chuck Norris began selling the Total Gym as an ill-fated attempt to make his day-to-day opponents less laughably pathetic."}, + {"text": "Do you know why Baskin Robbins only has 31 flavors? Because Chuck Norris doesn't like Fudge Ripple."}, + {"text": "Chuck Norris was what Willis was talkin' about."}, + {"text": "Google won't search for Chuck Norris because it knows you don't find Chuck Norris, he finds you."}, + {"text": "Chuck Norris can lead a horse to water AND make it drink."}, + {"text": "Nagasaki never had a bomb dropped on it. Chuck Norris jumped out of a plane and punched the ground"}, + {"text": "Chuck Norris destroyed the periodic table, because Chuck Norris only recognizes the element of surprise."}, + {"text": "It is believed dinosaurs are extinct due to a giant meteor. That's true if you want to call Chuck Norris a giant meteor."}, + {"text": "Chuck Norris shot the sheriff, but he round house kicked the deputy."}, + {"text": "That's not Chuck Norris doing push-ups -- that's Chuck Norris moving the Earth away from the path of a deadly asteroid."}, + {"text": "Chuck Norris can judge a book by its cover."}, + {"text": "How many Chuck Norris' does it take to change a light bulb? None, Chuck Norris prefers to kill in the dark."}, + {"text": "Crime does not pay - unless you are an undertaker following Walker, Texas Ranger, on a routine patrol."}, + {"text": "Chuck Norris invented the internet? just so he had a place to store his porn."}, + {"text": "Chuck Norris does not own a house. He walks into random houses and people move."}, + {"text": "It is better to give than to receive. This is especially true of a Chuck Norris roundhouse kick."}, + {"text": "Chuck Norris is the only person to ever win a staring contest against Ray Charles and Stevie Wonder."}, + {"text": "Industrial logging isn't the cause of deforestation. Chuck Norris needs toothpicks."}, + {"text": "Chuck Norris smells what the Rock is cooking... because the Rock is Chuck Norris' personal chef."}, + {"text": "Chuck Norris is the reason why Waldo is hiding."}, + {"text": "Chuck Norris does not eat. Food understands that the only safe haven from Chuck Norris' fists is inside his own body."}, + {"text": "One day Chuck Norris walked down the street with a massive erection. There were no survivors."}, + {"text": "Chuck Norris uses a night light. Not because Chuck Norris is afraid of the dark, but the dark is afraid of Chuck Norris."}, + {"text": "When Bruce Banner gets mad, he turns into the Hulk. When the Hulk gets mad, he turns into Chuck Norris."}, + {"text": "Chuck Norris once kicked a horse in the chin. Its descendants are known today as Giraffes."}, + {"text": "Sticks and stones may break your bones, but a Chuck Norris glare will liquefy your kidneys."}, + {"text": "Chuck Norris once went skydiving, but promised never to do it again. One Grand Canyon is enough."}, + {"text": "In a fight between Batman and Darth Vader, the winner would be Chuck Norris."}, + {"text": "Everybody loves Raymond. Except Chuck Norris."}, + {"text": "Chuck Norris got his drivers license at the age of 16. Seconds."}, + {"text": "Chuck Norris can win at solitaire with only 18 cards."}, + {"text": "Chuck Norris once shat blood - the blood of 11,940 natives he had killed and eaten."}, + {"text": "The truth will set you free. Unless Chuck Norris has you, in which case, forget it buddy!"}, + {"text": "Chuck Norris doesn't look both ways before he crosses the street... he just roundhouses any cars that get too close."}, + {"text": "How many roundhouse kicks does it take to get to the center of a tootsie pop? Just one. From Chuck Norris."}, + {"text": "Chuck Norris doesnt wear a watch, HE decides what time it is."}, + {"text": "When Chuck Norris does division, there are no remainders."}, + {"text": "Never look a gift Chuck Norris in the mouth, because he will bite your damn eyes off."}, + {"text": "Chuck Norris? roundhouse kick is so powerful, it can be seen from outer space by the naked eye."}, + {"text": "Ozzy Osbourne bites the heads off of bats. Chuck Norris bites the heads off of Siberian Tigers."}, + {"text": "He who lives by the sword, dies by the sword. He who lives by Chuck Norris, dies by the roundhouse kick."}, + {"text": "The best-laid plans of mice and men often go awry. Even the worst-laid plans of Chuck Norris come off without a hitch."}, + {"text": "Chuck Norris can taste lies."}, + {"text": "One time, Chuck Norris accidentally stubbed his toe. It destroyed the entire state of Ohio."}, + {"text": "Little Miss Muffet sat on her tuffet, until Chuck Norris roundhouse kicked her into a glacier."}, + {"text": "Chuck Norris can blow bubbles with beef jerky."}, + {"text": "Chuck Norris does, in fact, live in a round house."}, + {"text": "When Chuck Norris works out on the Total Gym, the Total Gym feels like it's been raped."}, + {"text": "Chuck Norris can skeletize a cow in two minutes."}, + {"text": "The only sure things are Death and Taxes and when Chuck Norris goes to work for the IRS, they'll be the same thing."}, + {"text": "Chuck Norris' first job was as a paperboy. There were no survivors."}, + {"text": "With the rising cost of gasoline, Chuck Norris is beginning to worry about his drinking habit."}, + {"text": "The square root of Chuck Norris is pain. Do not try to square Chuck Norris, the result is death."}, + {"text": "To be or not to be? That is the question. The answer? Chuck Norris."}, + {"text": "Chuck Norris has never been in a fight, ever. Do you call one roundhouse kick to the face a fight?"}, + {"text": "There are two types of people in the world... people that suck, and Chuck Norris."}, + {"text": "Chuck Norris never wet his bed as a child. The bed wet itself out of fear."}, + {"text": "Chuck Norris uses 8'x10' sheets of plywood as toilet paper."}, + {"text": "Noah was the only man notified before Chuck Norris relieved himself in the Atlantic Ocean."}, + {"text": "Chuck Norris eats steak for every single meal. Most times he forgets to kill the cow."}, + {"text": "The First Law of Thermodynamics states that energy can neither be created nor destroyed... unless it meets Chuck Norris."}, + {"text": "Fact: Chuck Norris doesn't consider it sex if the woman survives."}, + {"text": "Chuck Norris knows everything there is to know - Except for the definition of mercy."}, + {"text": "Chuck Norris never has to wax his skis because they're always slick with blood."}, + {"text": "182,000 Americans die from Chuck Norris-related accidents every year."}, + {"text": "Paper beats rock, rock beats scissors, and scissors beats paper, but Chuck Norris beats all 3 at the same time."}, + {"text": "Jesus can walk on water, but Chuck Norris can walk on Jesus."}, + {"text": "All roads lead to Chuck Norris. And by the transitive property, a roundhouse kick to the face."}, + {"text": "July 4th is Independence day. And the day Chuck Norris was born. Coincidence? I think not."}, + {"text": "Chuck Norris was once in a knife fight, and the knife lost."}, + {"text": "If you work in an office with Chuck Norris, don't ask him for his three-hole-punch."}, + {"text": "The First rule of Chuck Norris is: you do not talk about Chuck Norris."}, + {"text": "When Chuck Norris plays Monopoly, it affects the actual world economy."}, + {"text": "Chuck Norris drinks napalm to quell his heartburn."}, + {"text": "As an infant, Chuck Norris' parents gave him a toy hammer. He gave the world Stonehenge."}, + {"text": "Chuck Norris once ordered a steak in a restaurant. The steak did what it was told."}, + {"text": "There are only two things that can cut diamonds: other diamonds, and Chuck Norris."}, + {"text": "President Roosevelt once rode his horse 100 miles. Chuck Norris carried his the same distance in half the time."}, + {"text": "Chuck Norris qualified with a top speed of 324 mph at the Daytona 500, without a car."}, + {"text": "Chuck Norris likes his coffee half and half: half coffee grounds, half wood-grain alcohol."}, + {"text": "Chuck Norris uses tabasco sauce instead of visine."}, + {"text": "Chuck Norris' credit cards have no limit. Last weekend, he maxed them out."}, + {"text": "Think of a hot woman. Chuck Norris did her."}, + {"text": "Chuck Norris sleeps with a pillow under his gun."}, + {"text": "Chuck Norris doesn't chew gum. Chuck Norris chews tin foil."}, + {"text": "Aliens DO indeed exist. They just know better than to visit a planet that Chuck Norris is on."}, + {"text": "Some people ask for a Kleenex when they sneeze, Chuck Norris asks for a body bag."}, + {"text": "There?s an order to the universe: space, time, Chuck Norris.... Just kidding, Chuck Norris is first."}, + {"text": "Chuck Norris doesn't see dead people. He makes people dead."}, + {"text": "For undercover police work, Chuck Norris pins his badge underneath his shirt, directly into his chest."}, + {"text": "We live in an expanding universe. All of it is trying to get away from Chuck Norris."}, + {"text": "The word 'Kill' was invented by Chuck Norris. Other words were 'Die', 'Beer', and 'What'."}, + {"text": "Chuck Norris is his own line at the DMV."}, + {"text": "Two wrongs don't make a right. Unless you're Chuck Norris. Then two wrongs make a roundhouse kick to the face."}, + {"text": "Who let the dogs out? Chuck Norris let the dogs out... and then roundhouse kicked them through an Oldsmobile."}, + {"text": "When Chuck Norris goes to out to eat, he orders a whole chicken, but he only eats its soul."}, + {"text": "Chuck Norris has never won an Academy Award for acting... because he's not acting."}, + {"text": "If Chuck Norris wants your opinion, he'll beat it into you."}, + {"text": "Not everyone that Chuck Norris is mad at gets killed. Some get away. They are called astronauts."}, + {"text": "Godzilla is a Japanese rendition of Chuck Norris' first visit to Tokyo."}, + {"text": "They once made a Chuck Norris toilet paper, but there was a problem-- It wouldn't take shit from anybody."}, + {"text": "Chuck Norris once rode a nine foot grizzly bear through an automatic car wash, instead of taking a shower."}, + {"text": "Chuck Norris' sperm can be seen with the naked eye. Each one is the size of a quarter."}, + {"text": "Chuck Norris doesn't daydream. He's too busy giving other people nightmares."}, + {"text": "There are no such things as tornados. Chuck Norris just hates trailer parks."}, + {"text": "Chuck Norris' penis is a third degree blackbelt, and an honorable 32nd-degree mason."}, + {"text": "Chuck Norris once participated in the running of the bulls. He walked."}, + {"text": "The Drummer for Def Leppard's only got one arm. Chuck Norris needed a back scratcher."}, + {"text": "Chuck Norris once rode a bull, and nine months later it had a calf."}, + {"text": "For Spring Break '05, Chuck Norris drove to Madagascar, riding a chariot pulled by two electric eels."}, + {"text": "Chuck Norris has banned rainbows from the state of North Dakota."}, + {"text": "Divide Chuck Norris by zero and you will in fact get one........one bad-ass that is."}, + {"text": "TNT was originally developed by Chuck Norris to cure indigestion."}, + {"text": "Chuck Norris runs on batteries. Specifically, Die Hards."}, + {"text": "Chuck Norris will never have a heart attack. His heart isn't nearly foolish enough to attack him."}, + {"text": "Only Chuck Norris can prevent forest fires."}, + {"text": "When Chuck Norris makes a burrito, its main ingredient is real toes."}, + {"text": "Chuck Norris is not Irish. His hair is soaked in the blood of his victims."}, + {"text": "They say curiosity killed the cat. This is false. Chuck Norris killed the cat. Every single one of them."}, + {"text": "There is no such thing as a lesbian, just a woman who has never met Chuck Norris."}, + {"text": "Chuck Norris crossed the road. No one has ever dared question his motives."}, + {"text": "One time, at band camp, Chuck Norris ate a percussionist."}, + {"text": "Love does not hurt. Chuck Norris does."}, + {"text": "Chuck Norris once round-house kicked a salesman. Over the phone."}, + {"text": "The pen is mightier than the sword, but only if the pen is held by Chuck Norris."}, + {"text": "Chuck Norris knows the last digit of pi."}, + {"text": "The air around Chuck Norris is always a balmy 78 degrees."}, + {"text": "When Chuck Norris wants an egg, he cracks open a chicken."}, + {"text": "Chuck Norris plays racquetball with a waffle iron and a bowling ball."}, + {"text": "Chuck Norris doesn't believe in ravioli. He stuffs a live turtle with beef and smothers it in pig's blood."}, + {"text": "Count from one to ten. That's how long it would take Chuck Norris to kill you...Forty seven times."}, + {"text": "Chuck Norris is not Politically Correct. He is just Correct. Always."}, + {"text": "Mr. T pities the fool. Chuck Norris rips the fool's head off."}, + {"text": "Chuck Norris had to stop washing his clothes in the ocean. The tsunamis were killing people."}, + {"text": "Chuck Norris has volunteered to remain on earth after the Rapture; he will spend his time fighting the Anti-Christ."}, + {"text": "Chuck Norris is the only known mammal in history to have an opposable thumb. On his penis."}, + {"text": "Chuck Norris' favorite cereal is Kellogg's Nails 'N' Gravel."}, + {"text": "Chuck Norris does not wear a condom. Because there is no such thing as protection from Chuck Norris."}, + {"text": "Rules of fighting: 1) Don't bring a knife to a gun fight. 2) Don't bring a gun to a Chuck Norris fight."}, + {"text": "Chuck Norris is the only man who has, literally, beaten the odds. With his fists."}, + {"text": "Chuck Norris wipes his ass with chain mail and sandpaper."}, + {"text": "Chuck Norris likes his ice like he likes his skulls: crushed."}, + {"text": "Chuck Norris can kick through all 6 degrees of separation, hitting anyone, anywhere, in the face, at any time."}, + {"text": "Most tough men eat nails for breakfast. Chuck Norris does all of his grocery shopping at Home Depot."}, + {"text": "Everything King Midas touches turnes to gold. Everything Chuck Norris touches turns up dead."}, + {"text": "When Chuck Norris throws exceptions, it's across the room."}, + {"text": "All arrays Chuck Norris declares are of infinite size, because Chuck Norris knows no bounds."}, + {"text": "Chuck Norris doesn't have disk latency because the hard drive knows to hurry the hell up."}, + {"text": "Chuck Norris writes code that optimizes itself."}, + {"text": "Chuck Norris can't test for equality because he has no equal."}, + {"text": "Chuck Norris doesn't need garbage collection because he doesn't call .Dispose(), he calls .DropKick()."}, + {"text": "Chuck Norris's first program was kill -9."}, + {"text": "Chuck Norris burst the dot com bubble."}, + {"text": "All browsers support the hex definitions #chuck and #norris for the colors black and blue."}, + {"text": "MySpace actually isn't your space, it's Chuck's (he just lets you use it)."}, + {"text": "Chuck Norris can write infinite recursion functions and have them return."}, + {"text": "Chuck Norris can solve the Towers of Hanoi in one move."}, + {"text": "The only pattern Chuck Norris knows is God Object."}, + {"text": "Chuck Norris finished World of Warcraft."}, + {"text": "Project managers never ask Chuck Norris for estimations... ever."}, + {"text": "Chuck Norris doesn't use web standards as the web will conform to him."}, + {"text": "Whiteboards are white because Chuck Norris scared them that way."}, + {"text": "Chuck Norris can delete the Recycling Bin."}, + {"text": "Chuck Norris can unit test entire applications with a single assert."}, + {"text": "Chuck Norris doesn't bug hunt as that signifies a probability of failure, he goes bug killing."}, + {"text": "Chuck Norris's keyboard doesn't have a Ctrl key because nothing controls Chuck Norris."}, + {"text": "Chuck Norris doesn't need a debugger, he just stares down the bug until the code confesses."}, + {"text": "Chuck Norris can access private methods."}, + {"text": "The class object inherits from Chuck Norris"}, + {"text": "Bill Gates thinks he's Chuck Norris. Chuck Norris actually laughed. Once."}, + {"text": "No statement can catch the ChuckNorrisException."}, + {"text": "Chuck Norris can write multi-threaded applications with a single thread."}, + {"text": "Chuck Norris doesn't need to use AJAX because pages are too afraid to postback anyways."}, + {"text": "Chuck Norris doesn't use reflection, reflection asks politely for his help."}, + {"text": "There is no Esc key on Chuck Norris' keyboard, because no one escapes Chuck Norris."}, + {"text": "Chuck Norris can binary search unsorted data."}, + {"text": "Chuck Norris doesn't needs try-catch, exceptions are too afraid to raise."}, + {"text": "Chuck Norris went out of an infinite loop."}, + {"text": "If Chuck Norris writes code with bugs, the bugs fix themselves."}, + {"text": "Chuck Norris hosting is 101% uptime guaranteed."}, + {"text": "Chuck Norris's keyboard has the Any key."}, + {"text": "Chuck Norris can access the DB from the UI."}, + {"text": "Chuck Norris' programs never exit, they terminate."}, + {"text": "Chuck Norris protocol design method has no status, requests or responses, only commands."}, + {"text": "Chuck Norris programs occupy 150% of CPU, even when they are not executing."}, + {"text": "Chuck Norris programs do not accept input."}, + {"text": "Chuck Norris doesn't need an OS."}, + {"text": "Chuck Norris can compile syntax errors."}, + {"text": "Every SQL statement that Chuck Norris codes has an implicit COMMIT in its end."}, + {"text": "Chuck Norris does not code in cycles, he codes in strikes."}, + {"text": "Chuck Norris doesn't use a computer because a computer does everything slower than Chuck Norris."}, + {"text": "Chuck Norris compresses his files by doing a flying round house kick to the hard drive."}, + {"text": "Chuck Norris doesn't cheat death. He wins fair and square."}, + {"text": "Chuck Norris once won a game of connect four in 3 moves."}, + {"text": "Chuck Norris can do a wheelie on a unicycle."}, + {"text": "Chuck Norris can win in a game of Russian roulette with a fully loaded gun."}, + {"text": "No one has ever pair-programmed with Chuck Norris and lived to tell about it."}, + {"text": "No one has ever spoken during review of Chuck Norris' code and lived to tell about it."}, + {"text": "Chuck Norris doesn't use Oracle, he is the Oracle."}, + {"text": "Jesus can walk on water, but Chuck Norris can swim through land."}, + {"text": "A diff between your code and Chuck Norris's is infinite."}, + {"text": "The Chuck Norris Eclipse plugin made alien contact."}, + {"text": "Chuck Norris is the ultimate mutex, all threads fear him."}, + {"text": "Don't worry about tests, Chuck Norris's test cases cover your code too."}, + {"text": "When Chuck Norris break the build, you can't fix it, because there is not a single line of code left."}, + {"text": "Chuck Norris types with one finger. He points it at the keyboard and the keyboard does the rest."}, + {"text": "Chuck Norris's brain waves are suspected to be harmful to cell phones."}, + {"text": "Chuck Norris does infinite loops in 4 seconds."}, + {"text": "Product Owners never ask Chuck Norris for more features. They ask for mercy."}, + {"text": "Chuck Norris killed two stones with one bird."}, + {"text": "Chuck Norris can speak Braille."}, + {"text": "Chuck Norris knows the value of NULL, and he can sort by it too."}, + {"text": "Chuck Norris can install a 64 bit OS on 32 bit machines."}, + {"text": "Chuck Norris can write to an output stream."}, + {"text": "Chuck Norris can read from an input stream."}, + {"text": "Chuck Norris never has to build his program to machine code. Machines have learnt to interpret Chuck Norris code."}, + {"text": "Chuck Norris' unit tests don't run. They die."}, + {"text": "Chuck Norris sits at the stand-up."}, + {"text": "Chuck Norris doesn't need an account. He just logs in."}, + {"text": "Code runs faster when Chuck Norris watches it."}, + {"text": "Chuck Norris does not need a watch, he decides what time it is."}, + {"text": "Chuck Norris already went to Moon and Mars, that's why there are no signs of life."}, + {"text": "Once a police officer caught Chuck Norris, the cop was lucky enough to escape with a warning."}, + {"text": "Chuck Norris knows Victoria's secret."}, + {"text": "Dark spots on the Moon are the result of Chuck Norris' shooting practice."}, + {"text": "Chuck Norris died before 20 years, Death doesn't have the courage to tell him yet."}, + {"text": "There is no April 1st in Chuck Norris' calendar, because no one can fool him."}, + {"text": "Chuck Norris can make onions cry."}, + {"text": "Chuck Norris can watch the radio."}, + {"text": "Chuck Norris built the hospital he was born in."}, + {"text": "Once Chuck Norris signed a cheque and the bank bounced."}, + {"text": "Chuck Norris can drown a fish."}, + {"text": "Once death had a near Chuck Norris experience."}, + {"text": "Once Chuck Norris and Superman had a competition. The loser had to wear his underwear over his pants."}, + {"text": "Chuck Norris can make fire using two ice cubes."}, + {"text": "Chuck Norris tears can cure the cancer, but the sad thing is Chuck Norris never cries."}, + {"text": "Chuck Norris can remember the future."}, + {"text": "Chuck Norris doesn't age, because time cannot keep up with him."}, + {"text": "Ghosts are actually caused by Chuck Norris killing people faster than Death can process them."}, + {"text": "Chuck Norris doesn't need a keyboard he tells the computer to write something and it does."}, + {"text": "Chuck Norris plays pool with comets and astroids. He shoots them into black holes."}, + {"text": "There was never anything wrong with Achilles' heel until he got mad and decided to kick Chuck Norris."}, + {"text": "Tornados occur when Chuck Norris sneezes."}, + {"text": "Chuck Norris once sold eBay to eBay on eBay."}, + {"text": "Chuck Norris can build a snowman out of rain."}, + {"text": "Chuck Norris made the sun by rubbing his hands together."}, + {"text": "Chuck Norris puts sunglasses on to protect the sun from his eyes."}, + {"text": "Chuck Norris can lock a safe and keep the key inside it."} +] diff --git a/app/routers/joke.py b/app/routers/joke.py new file mode 100644 index 00000000..07b7b453 --- /dev/null +++ b/app/routers/joke.py @@ -0,0 +1,12 @@ +from fastapi import APIRouter, Depends, Request +from app.internal import jokes +from sqlalchemy.orm import Session +from app.dependencies import get_db + + +router = APIRouter() + + +@router.get("/joke") +async def joke(request: Request, db: Session = Depends(get_db)): + return jokes.get_a_joke(db) diff --git a/app/static/joke.js b/app/static/joke.js new file mode 100644 index 00000000..4cfd223b --- /dev/null +++ b/app/static/joke.js @@ -0,0 +1,14 @@ +function makejoke() { + fetch('/joke') + .then(response => response.json()) + .then(data => Swal.fire(data.text)); +} + + +function addEventsAfterPageLoaded() { + const element = document.getElementById("a-joke"); + element.addEventListener("click", makejoke, false); +} + + +document.addEventListener("DOMContentLoaded", addEventsAfterPageLoaded); \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html index c7431c71..95ebdf52 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -55,6 +55,9 @@ + @@ -75,6 +78,9 @@ + + + \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 4923a614..1d8a21d2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,6 +20,7 @@ 'smtpdfix', 'tests.quotes_fixture', 'tests.zodiac_fixture', + 'tests.jokes_fixture', 'tests.comment_fixture', ] diff --git a/tests/jokes_fixture.py b/tests/jokes_fixture.py new file mode 100644 index 00000000..d7e3258c --- /dev/null +++ b/tests/jokes_fixture.py @@ -0,0 +1,20 @@ +import pytest +from sqlalchemy.orm import Session + +from app.database.models import Joke +from app.internal.utils import create_model, delete_instance + + +def add_joke(session: Session, id_joke: int, text: str) -> Joke: + joke = create_model(session, Joke, id=id_joke, text=text) + yield joke + delete_instance(session, joke) + + +@pytest.fixture +def joke(session: Session) -> Joke: + yield from add_joke( + session=session, + id_joke=1, + text='Chuck Norris can slam a revolving door.', + ) diff --git a/tests/test_joke.py b/tests/test_joke.py new file mode 100644 index 00000000..df165802 --- /dev/null +++ b/tests/test_joke.py @@ -0,0 +1,17 @@ +from app.database.models import Joke +from app.internal import jokes + + +def get_jokes_amount(session): + return session.query(Joke).count() + + +def test_get_a_joke(session, joke): + assert jokes.get_a_joke(session).text == joke.text + + +def test_jokes_not_load_twice_to_db(session): + jokes.get_a_joke(session) + first_load_amount = get_jokes_amount(session) + jokes.get_a_joke(session) + assert first_load_amount == get_jokes_amount(session) diff --git a/tests/test_joke_route.py b/tests/test_joke_route.py new file mode 100644 index 00000000..6b2e3d02 --- /dev/null +++ b/tests/test_joke_route.py @@ -0,0 +1,4 @@ +def test_joke(client, session): + resp = client.get('/joke') + assert resp.ok + assert resp.json