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 | |
from pathlib import Path | |
from scalpel import Configuration | |
from scalpel.green import StaticSpider, StaticResponse, read_mp | |
def parse(spider: StaticSpider, response: StaticResponse) -> None: | |
for quote in response.xpath('//div[@class="quote"]'): | |
data = { |
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 | |
from pathlib import Path | |
from scalpel import Configuration, datetime_decoder | |
from scalpel.green import SeleniumSpider, SeleniumResponse, read_mp | |
def parse(spider: SeleniumSpider, response: SeleniumResponse) -> None: | |
for block in response.driver.find_elements_by_xpath('//div[@class="opblock-tag-section"]'): | |
block.click() |
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 signal | |
import anyio | |
async def signal_handler(scope): | |
with anyio.open_signal_receiver(signal.SIGINT, signal.SIGTERM) as signals: | |
async for signum in signals: | |
if signum == signal.SIGINT: | |
print('Ctrl+C pressed!') |
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 re | |
import click | |
@click.command() | |
@click.option('-m', 'chars', is_flag=True, help='number of characters') | |
@click.option('-l', 'lines', is_flag=True, help='number of lines') | |
@click.option('-c', 'byte', is_flag=True, help='number of bytes') | |
@click.option('-w', 'words', is_flag=True, help='number of words') | |
@click.argument('filename', type=click.Path(exists=True, dir_okay=False)) |
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 click.testing import CliRunner | |
from scripts.pycat import cli | |
def test_pycat(tmp_path): | |
hello_file = tmp_path / 'hello.txt' | |
hello_file.write_text('hello world!') | |
runner = CliRunner() | |
result = runner.invoke(cli, [f'{hello_file.resolve()}']) |
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 click | |
@click.command() | |
@click.argument('file', type=click.File()) | |
def cli(file): | |
"""Read file part by part""" | |
click.echo_via_pager(file.read()) |
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 ipaddress | |
import click | |
class IPParamType(click.ParamType): | |
name = 'ip address' | |
def convert(self, value, param, ctx): | |
try: | |
return ipaddress.ip_address(value) |
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 | |
from typing import List | |
import anyio | |
import click | |
import httpx | |
from rich.console import Console | |
from rich.progress import Progress, TaskID | |
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 enum | |
from kifurushi import Packet, ShortField, ByteField, IntEnumField | |
class Mood(enum.Enum): | |
happy = 1 | |
cool = 2 | |
angry = 4 | |
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 socket | |
import enum | |
from kifurushi import Packet, ShortField, ByteField, IntEnumField | |
HOST = 'disney-stuff.com' | |
PORT = 14006 | |
class Mood(enum.Enum): | |
happy = 1 |
OlderNewer