Simulate streaming API with FastAPI

10 记录 Leave a Comment
The server code import asyncio import uvicorn from fastapi import FastAPI from fastapi.responses import StreamingResponse app = FastAPI() async def fake_text_streaming(): for i in range(1000): yield b"Fake text #" + str(i).encode() + b"\n" await asyncio.sleep(1) @app.post("/") @app…

Selenium infinite scrolling to bottom using python

106 记录 Leave a Comment
We have 3 kinds of infinite scrolling to bottom while using selenium. Simply scrolling - Stop until there is no more content. Meet scrolling - Stop until we meet a speciy element. Partial scrolling - Scrolling content in specify html container, stop until there are no more content. All these 3 scenses will use …

From PHP to Python In 10 Minutes

108 记录 Leave a Comment
PHP and Python are both high-level, interpreted programming languages with a variety of applications, but they have some significant differences in terms of syntax, design philosophy, and use cases. Here's a detailed comparison of the two languages: 1. Purpose and Use Cases PHP: Created by Rasmus Lerdorf in 199…

How to assert if Python enum contains specific string key or value

340 Uncategorized Leave a Comment
To assert if Python enum contains specific string key or value, we need helper function. class BaseEnum(Enum): @classmethod def has_name(cls, name): return name in cls._member_names_ @classmethod def has_value(cls, value): return value in cls._value2member_map_ class StatusEnum(str, BaseEnum): PUBLISHED = 1 PEN…

How to use Gmail to send email in Python

259 记录 Leave a Comment
1 Add "App password" Go to Google account "Security", navigate to "Signing in to Google" and click "App passwords". Then select a type, here we use "Mail" and custom the device name. Type device name as "airflow", or you can choose any other name. Then…