Skip to content

Commit

Permalink
Initial working draft.
Browse files Browse the repository at this point in the history
  • Loading branch information
supakeen committed Mar 1, 2020
1 parent 474ab0b commit 88f95db
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
31 changes: 31 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[mypy]
# Specify the target platform details in config, so your developers are
# free to run mypy on Windows, Linux, or macOS and get consistent
# results.
python_version=3.6
platform=linux

# flake8-mypy expects the two following for sensible formatting
show_column_numbers=True

# show error messages from unrelated files
follow_imports=normal

# suppress errors about unsatisfied imports
ignore_missing_imports=True

# be strict
disallow_untyped_calls=True
warn_return_any=True
strict_optional=True
warn_no_return=True
warn_redundant_casts=True
warn_unused_ignores=True

# The following are off by default. Flip them on if you feel
# adventurous.
disallow_untyped_defs=True
check_untyped_defs=True

# No incremental mode
cache_dir=/dev/null
53 changes: 51 additions & 2 deletions steck.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
def main() -> int:
return 0
import pathlib

from typing import Tuple

import click
import requests
import magic


mime_map = {
"text/plain": "text",
"text/x-python": "python",
}


@click.group()
def main() -> None:
"""Steck, a pastebin client for pinnwand."""
return


@main.command()
@click.argument("files", nargs=-1)
def paste(files: Tuple[str]) -> None:
"""Paste some files matching a pattern."""
guesser = magic.Magic(mime=True)

collect = [
(
pathlib.Path(file).name,
open(file).read(),
mime_map.get(guesser.from_file(file), "text"),
)
for file in files
if pathlib.Path(file).is_file()
]

data = {
"expiry": "1day",
"files": [
{"name": name, "content": content, "lexer": lexer}
for name, content, lexer in collect
],
}

response = requests.post(
"https://bpaste.net/api/v1/paste", json=data
).json()

print("View Paste", response["link"])
print("Remove Paste", response["removal"])


if __name__ == "__main__":
Expand Down

0 comments on commit 88f95db

Please sign in to comment.