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 datetime import datetime | |
>>> def today(dt=datetime.now()): | |
... print(dt) | |
... | |
>>> today() | |
2020-12-12 22:18:26.432268 | |
# oops | |
>>> today() | |
2020-12-12 22:18:26.432268 | |
>>> today() |
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
#!/usr/bin/env python3.9 | |
import argparse | |
import importlib | |
import inspect | |
import pydoc | |
def get_callable(arg): | |
module_str, name = arg.rsplit(".", 1) | |
module = importlib.import_module(module_str) |
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 | |
import re | |
import pyperclip | |
def gen_affiliation_link(url): | |
if not re.search(r"amazon.*/dp/", url): | |
raise ValueError(f"{url} is not a valid Amazon product link") | |
asin = re.sub(r".*/dp/([^/]+).*", r"\1", url) |
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 | |
filename = 'homework.txt' | |
if not os.path.exists(filename): | |
with open(filename, 'w'): pass | |
answer1 = """1). | |
X | 3 | X | |
____|____|____ |
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 importlib import import_module | |
from keyword import kwlist | |
import builtins | |
from typing import Dict, List | |
scores = { | |
"builtin": 1, | |
"keyword": 2, | |
"module": 3, | |
} |
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 asyncio | |
import os | |
import aiofiles | |
import aiohttp | |
# saved links from https://pybit.es/archives in urls | |
URLS = [u.rstrip() for u in open('urls', 'r').readlines()] | |
async def fetch(session, url): |
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 to retrieve new titles from O'Reilly Media (formerly Safari Books Online)""" | |
from collections import namedtuple | |
from pathlib import Path | |
from datetime import datetime, timedelta | |
from urllib.request import urlretrieve | |
from xml.etree.ElementTree import parse | |
RSS_FEED = "https://www.oreilly.com/feeds/recently-added.rss" | |
NOW = datetime.now() | |
DT_FMT = "%a, %d %b %Y %H:%M:%S" |
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 concurrent.futures | |
import os | |
import re | |
from timeit import timeit | |
import requests | |
from tqdm import tqdm | |
URLS = 'urls' |
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
>>> def gen(): | |
... yield from [1, 2, 3] | |
... | |
>>> g = gen() | |
>>> for i in g: print(i) | |
... | |
1 | |
2 | |
3 | |
# generator exhausted: |
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 django.core.management.base import BaseCommand | |
import feedparser | |
from django.db.utils import IntegrityError | |
from blog.models import Article | |
FEED_URL = "https://pybit.es/feed/" | |
class Command(BaseCommand): |