xxxxxxxxxx
"""
A Bare Bones Slack API
Illustrates basic usage of FastAPI.
"""
from fastapi import FastAPI, HTTPException, status
from pydantic import BaseModel
from typing import List
class Message(BaseModel):
"""Message class defined in Pydantic."""
channel: str
author: str
text: str
# Instantiate the FastAPI
app = FastAPI()
# In a real app, we would have a database.
# But, let's keep it super simple for now!
channel_list = ["general", "dev", "marketing"]
message_map = {}
for channel in channel_list:
message_map[channel] = []
@app.get("/status")
def get_status():
"""Get status of messaging server."""
return ({"status": "running"})
@app.get("/channels", response_model=List[str])
def get_channels():
"""Get all channels in list form."""
return channel_list
@app.get("/messages/{channel}", response_model=List[Message])
def get_messages(channel: str):
"""Get all messages for the specified channel."""
return message_map.get(channel)
@app.post("/post_message", status_code=status.HTTP_201_CREATED)
def post_message(message: Message):
"""Post a new message to the specified channel."""
channel = message.channel
if channel in channel_list:
message_map[channel].append(message)
return message
else:
raise HTTPException(status_code=404, detail="channel not found")
xxxxxxxxxx
Y
.-^-.
/ \ .- ~ ~ -.
() () / _ _ `. _ _ _
\_ _/ / / \ \ . ~ _ _ ~ .
| | / / \ \ .' .~ ~-. `.
| | / / ) ) / / `.`.
\ \_ _/ / / / / / `'
\_ _ _.' / / ( (
/ / \ \
/ / \ \
/ / ) )
( ( / /
`. `. .' /
`. ~ - - - - ~ .'
~ . _ _ _ _ . ~
xxxxxxxxxx
Python is an interpreted, high-level,
general-purpose programming language.
//as you can also see to your right --------------------->
but also note interpreted, not compiled.
xxxxxxxxxx
Python is a High level and multi-purpose Programming language. It is commonly
used in data science ,AI(Artificial intelligence) and ML(Machine Learning).
If you are a beginner in programming it is mostly prefered because its
code is very simple and somehow similar to English Language.Even master level
people use python. Encourage you to learn it.
xxxxxxxxxx
Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.
xxxxxxxxxx
'''Python is an interpreted, high-level and general-purpose programming
language.Python's design philosophy emphasizes code readability with its
notable use of significant whitespace. '''
#Examples
print("Hello World")
repeat = 5
for i in range(repeat):
print("This is the %i iteration" % i)
#2nd variation - print("This is the " + i + "iteration")
#3rd variation - print(f"This is the {i!r} iteration")
#4th variation - print(("This is the {} iteration).format(i))
import random #In order to use the random functions
class Person:
def __init__(self, name, age, height):
self.name = str(name)
self.age = int(age)
self.height = str(height)
person1 = Person("Name", random.randint(1, 100), str(random.randint(0, 7)) + "'" + str(random.randint(0, 11)) + '"')
print(f"Your name is {person1.name} and you are {person1.age} years old. You are also {person1.height}.")