This file contains 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
# /// script | |
# dependencies = [ | |
# "marvin", | |
# ] | |
# /// | |
import os | |
import sys | |
import argparse | |
import marvin | |
from pydantic import BaseModel, Field |
This file contains 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
# /// script | |
# dependencies = [ | |
# "marvin", | |
# ] | |
# /// | |
import os | |
import sys | |
import argparse | |
from pydantic import BaseModel, Field |
This file contains 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
# /// script | |
# dependencies = [ | |
# "bs4", | |
# "httpx", | |
# "typer" | |
# ] | |
# /// | |
import textwrap | |
from bs4 import BeautifulSoup |
This file contains 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 pathlib import Path | |
import csv | |
# set MARVIN_OPENAI_API_KEY in your environment variables | |
import marvin | |
from pydantic import BaseModel | |
import folium | |
class Location(BaseModel): |
This file contains 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
# initial code | |
def process_data(name, age, address, phone, email): | |
print(f"Processing data for {name}, {age}, living at {address}. Contact info: {phone}, {email}") | |
process_data("Alice", 30, "123 Main St", "555-1234", "[email protected]") | |
# refactored using dataclass | |
from dataclasses import dataclass |
This file contains 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 os | |
from flask import Flask | |
import sentry_sdk | |
from dotenv import load_dotenv | |
load_dotenv() | |
SENTRY_DSN = os.getenv("SENTRY_DSN") | |
sentry_sdk.init(SENTRY_DSN) |
This file contains 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
repos: | |
- repo: https://github.com/psf/black | |
rev: 23.7.0 | |
hooks: | |
- id: black | |
args: [--line-length, "79"] | |
- repo: https://github.com/pycqa/flake8 | |
rev: 6.1.0 | |
hooks: |
This file contains 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
class TransactionLimitExceededError(Exception): | |
"""Raised when a transaction exceeds the allowed limit.""" | |
def __init__(self, amount, limit): | |
self.amount = amount | |
self.limit = limit | |
super().__init__(f"Transaction amount of {amount} exceeds the limit of {limit}.") | |
try: |
This file contains 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
# ok | |
def create_person(*args): | |
first_name, last_name, age = args | |
return { | |
'First Name': first_name, | |
'Last Name': last_name, | |
'Age': age | |
} | |
# Caller assumes the order: first name, last name, age. |
This file contains 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 urllib.parse import urlparse | |
from bs4 import BeautifulSoup | |
import httpx | |
API_URL = "https://codechalleng.es/api/articles/" | |
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" | |
HEADERS = {"User-Agent": USER_AGENT} | |
PYBITES_DOMAINS = ("pybit.es",) |
NewerOlder