我的目标是以特定方式从www.worldtides.info检索潮汐时间。
我在网站上获得了一个API密钥,可以通过发出以下命令成功检索信息:
curl -s "http://www.worldtides.info/api?extremes&lat=my_latitude&lon=my_longitude&length=86400&key=my_api_key"| jq -r ".extremes[] | .date + .type"
我已经在我的树莓上安装了jq来解析" date"和"键入"来自json的结果。
终端的结果是:
2016-04-03T16:47+0000Low
2016-04-03T23:01+0000High
2016-04-04T05:18+0000Low
2016-04-04T11:29+0000High
为了获得更清晰的结果,我使用sed:
curl -s "http://www.worldtides.info/api?extremes&lat=my_latitude&lon=my_longitude&length=86400&key=my_api_key"| jq -r ".extremes[] | .date + .type" | sed 's/+0000/ /g' | sed 's/T/ /g'|
结果是:
2016-04-03 16:47 Low
2016-04-03 23:01 High
2016-04-04 05:18 Low
2016-04-04 11:29 High
我不知道如何用'#34;今天"这个词取代日期。如果它是今天的日期(2016-04-03,我现在正在写作)以及如何用“#34;明天"”替换日期。如果它是明天的日期。
我试过了:
curl -s "http://www.worldtides.info/api?extremes&lat=my_latitude&lon=my_longitude&length=86400&key=my_api_key"| jq -r ".extremes[] | .date + .type" | sed 's/date +"%Y-%m-%d"/Today/g' | sed 's/+0000/ /g' | sed 's/T/ /g'|
但没有运气,没有变化。你能帮助我吗 ?感谢
答案 0 :(得分:2)
某些精简版Linux发行版没有开箱即用的GNU render: function() {
var cars = this.state.loadedCars.map(function(loaded) {
return (
<div class="row">
<div class="col-md-7">
<a href="#">
<img class="img-responsive" src="http://placehold.it/700x300" alt=""></img>
</a>
</div>
<div class="col-md-5">
<ul class="list-group">
<li class="list-group-item"><b>Brand: {loaded.brand}</b></li>
<li class="list-group-item"><b>Model: {loaded.model}</b></li>
<li class="list-group-item"><b>Fuel: </b></li>
<li class="list-group-item"><b>Mileage: </b></li>
<li class="list-group-item"><b>Location: </b></li>
<li class="list-group-item"><b>Price: </b></li>
</ul>
<a class="btn btn-primary" href="#">Buy it! <span class="glyphicon glyphicon-chevron-right"></span></a>
</div>
</div>
)
});
console.log(cars);
return (
<div>
{cars};
</div>
);
}
,但使用POSIX date
而没有明天的功能。因此,如果要将date
与sed
一起使用,则可能必须先安装它。或者,如果GNU date
可用,您也可以
awk
答案 1 :(得分:1)
您可以这样做替换:
today=`date +%Y-%m-%d`
tomorrow=`date --date="tomorrow" +%Y-%m-%d`
echo $today $tomorrow
sed "s/$today/today/g; s/$tomorrow/tomorrow/g;" your_last_result
其中your_last_result
是包含以下问题中数据的文件“结果是:”