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",) |
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 random | |
import pytest | |
from script import get_random_emails | |
@pytest.fixture(autouse=True) | |
def set_random_seed(): | |
random.seed(123) |
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 csv | |
import random | |
DATA = "MOCK_DATA.csv" | |
def get_emails(data=DATA): | |
with open(data) as f: | |
reader = csv.reader(f) | |
next(reader) |
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 Dog: | |
... def __init__(self, breed, color): | |
... self.breed = breed | |
... self.color = color | |
... | |
>>> dog1 = Dog("bulldog", "brown") | |
>>> | |
>>> dog1 | |
<__main__.Dog object at 0x7fe114d36580> | |
>>> dog1.attr |
NewerOlder