如何将curl命令的结果设置为一个变量,(因此在此ip地址中。)
import subprocess; ip = subprocess.call("curl ident.me", shell=True)
120.12.12.12
ip returns "0"
答案 0 :(得分:2)
与通过外壳运行curl相比,使用>>> import requests
>>> r = requests.get('http://ident.me')
>>> r.text
'137.221.143.78'
>>>
模块效果更好
requests
如果由于某种原因您不能使用subprocess.check_output
模块,然后尝试使用>>> ip = subprocess.check_output("curl -s ident.me".split())
>>> ip
'137.221.143.78'
// For each room grab the pins.
foreach($rooms as $room) {
// Grab all inspiration_id's for a specific room.
$pins = Pins::where('room_id', $room['id'])->get();
// Inspirations array.
$inspirations = array();
// For each pin use inspiration_id to grab inspiration id.
foreach($pins as $pin) {
// Grab inspiration that matches the pin.
$pin = Inspirations::where('id', $pin['inspiration_id'])->get();
// Add a $pin to the array.
array_push($inspirations, $pin);
}
// Input inspirations into pins of this room.
$room['pins'] = $inspirations;
}