Created
February 18, 2017 00:44
-
-
Save anonymous/05400918dc68a8bbcefde003614f4e9c to your computer and use it in GitHub Desktop.
nucca
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 python | |
# -*- encoding:utf-8 -*- | |
import click | |
import joblib | |
from datetime import datetime, timedelta | |
import os | |
from time import sleep | |
repo_name = ".nucca" | |
@click.group() | |
def cli(): | |
pass | |
@cli.command(help="Create an empty Nucca-docco") | |
def init(): | |
os.mkdir(repo_name) | |
nucca = {} | |
nucca["started"] = datetime.now() | |
nucca["materials"] = [] | |
joblib.dump(nucca, os.path.join(repo_name, "default")) | |
click.echo("Created an empty Nucca repository") | |
@cli.command(help="Add materials to the Nucca-docco") | |
@click.argument("material") | |
def add(material): | |
nucca = load() | |
nucca["materials"].append(material) | |
save(nucca) | |
click.echo("Add {}".format(material)) | |
def load(): | |
nucca = joblib.load(os.path.join(repo_name, "default")) | |
return nucca | |
def save(nucca): | |
joblib.dump(nucca, os.path.join(repo_name, "default")) | |
@cli.command(help="Show the Nucca-docco status") | |
def status(): | |
nucca = load() | |
tdelta = datetime.now() - nucca["started"] | |
acid_option = 0 | |
if "biofermin" in nucca["materials"]: | |
acid_option += 1000 | |
if "nukamiso-karashi" in nucca["materials"]: | |
acid_option -= 500 | |
acidity = 100 * (tdelta.seconds + acid_option) / 3600.0 | |
click.echo("乳酸菌 {}".format(acidity)) | |
click.echo("中に入っているもの {}".format(", ".join(nucca["materials"]))) | |
@cli.command(help="Trace materials") | |
@click.argument("material") | |
def trace(material): | |
if material == "cucumber": | |
click.launch("https://cucumber.io/") | |
elif material == "letuce": | |
click.launch("http://lettuce.it/tutorial/simple.html") | |
else: | |
click.echo("unknown") | |
@cli.command(help="Mix Nucca-docco") | |
def mix(): | |
with click.progressbar(range(5), label='Mixing Nucca-docco') as bar: | |
for i in bar: | |
sleep(1) | |
if __name__ == '__main__': | |
cli() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment