獨角獸
- 讓人思考未來會怎樣
- 使人自然改變自己
- 創造社會價值
承諾思維 (Thinking in Promises):以終為始來思考如何做事
from influxdb import InfluxDBClient
import random
import time
host = "localhost" #influxdb IP
port = 8086 #influxdb port
username = "root" #influxdb username
password = "root" #influxdb password
dbname = "sample" #database name
# json object template
obj = {'measurement':'temperature', 'tags':{'location':''}, 'fields':{'value':0}}
# arrays for location names and temperatures
locations = ['kitchen', 'bedroom', 'living room']
t = [20] * len(locations)
client = InfluxDBClient(host, port, username, password) # connect influxdb
client.create_database(dbname) # create database
while True:
for i in range(0,len(locations)):
t[i] = round(t[i] + random.uniform(-0.5, 0.5), 2) # generate temperature
# prepare data object
obj['tags']['location'] = locations[i]
obj['fields']['value'] = t[i]
print(obj)
# write data to influxdb
client.write_points([obj], 'ms', dbname)
time.sleep(1)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Welcome</title>
<link href="css/page.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Hello, welcome to static page.</h1>
</body>
</html>
h1 {
color: #ff7777;
font-style: italic;
}
@RestController
public class RequestHandler {
@RequestMapping(value="/func", method={RequestMethod.GET, RequestMethod.POST})
public String handler1(@RequestParam(value="name", required=false) String name,
HttpServletRequest request, HttpServletResponse response) {
String user = (name==null || name.isEmpty())? "world": name;
String host = request.getRemoteHost();
String result = String.format("Hello, %s! You are from %s", user, host);
return result;
}
}
java -jar greeting-0.0.1.jar
server.port = 88