Method | Description |
---|---|
clear() | Removes all items from the dictionary. |
copy() | Returns a shallow copy of the dictionary. |
fromkeys(seq[, v]) | Returns a new dictionary with keys from seq and value equal to v (defaults to None). |
get(key[,d]) | Returns the value of the key. If the key does not exist, returns d (defaults to None). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
from random import shuffle, choice | |
from rich.console import Console | |
console = Console() | |
def get_sentences(filename: str) -> List: | |
with open(filename) as f: | |
sentences = list(set(f.read().splitlines())) |
HTTP METHOD | API ENDPOINT | DESCRIPTION |
---|---|---|
GET | /products | Get a list of products. |
GET | /products?limit=x | Get only x products. |
GET | /products/<product_id> | Get a single product. |
POST | /products | Create a new product. |
PUT | /products/<product_id> | Update a product. |
PATCH | /products/<product_id> | Partially update a product. |
DELETE | /products/ | Delete a product. |
CODE RANGE | CATEGORY |
---|---|
1XX | Informational response |
2XX | Successful operation |
3XX | Redirection |
4XX | Client error |
5XX | Server error |
HTTP METHOD | DESCRIPTION |
---|---|
GET | Retrieve existing data |
POST | Add new data |
PUT | Update existing data |
PATCH | Partially update existing data |
DELETE | Delete data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
def get_horoscope(zodiac_sign: int, day: str): | |
if not "-" in day: | |
res = requests.get( | |
f"https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-{day}.aspx?sign={zodiac_sign}") | |
else: | |
day = day.replace("-", "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/<short_id>') | |
def redirect_url(short_id): | |
link = ShortUrls.query.filter_by(short_id=short_id).first() | |
if link: | |
return redirect(link.original_url) | |
else: | |
flash('Invalid URL') | |
return redirect(url_for('index')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from app.models import ShortUrls | |
from app import app, db | |
from flask import render_template, request, flash, redirect, url_for | |
@app.route('/', methods=['GET', 'POST']) | |
def index(): | |
if request.method == 'POST': | |
url = request.form['url'] | |
short_id = request.form['custom_id'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% block content %} | |
<h1 class="text-center mb-3">{% block title %} Welcome to Shorty {% endblock %}</h1> | |
<div class="row"> | |
<div class="col-md-2"></div> | |
<div class="col-md-8"> | |
<form method="post" action="{{url_for('index')}}"> | |
<div class="form-floating mb-3"> | |
<input type="text" name="url" id="url" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<!-- Bootstrap CSS --> | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous"> |