Skip to content

Instantly share code, notes, and snippets.

@ynkdir
Last active December 22, 2015 13:58
Show Gist options
  • Save ynkdir/6482318 to your computer and use it in GitHub Desktop.
Save ynkdir/6482318 to your computer and use it in GitHub Desktop.
from subprocess import Popen, PIPE, STDOUT
import shlex
import json
class Pipeline:
def __init__(self, stdin=None):
self.returncode = None
self.stdout = stdin
self.stderr = None
def __or__(self, args):
if isinstance(args, str):
args = shlex.split(args)
if isinstance(args, list):
p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
self.stdout, self.stderr = p.communicate(self.stdout)
self.returncode = p.returncode
elif callable(args):
self.stdout = args(self.stdout)
else:
raise NotImplemented()
return self
P = Pipeline
def json_parse(o):
return json.loads(o.decode("utf-8"))
def f(o):
return "\n".join("{type} : {actor[login]}".format(**x) for x in o).encode("utf-8")
def printb(o):
print(o.decode("utf-8"))
p = P() | "curl https://api.github.com/orgs/vim-jp/events" | json_parse | f | "grep IssueCommentEvent" | printb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment