Reputation: 39
I need make simple script on python with get-server-time, which can get time from server, how a can got it?
Upvotes: 0
Views: 391
Reputation: 6719
First, you need to create a server. One of the simplest options would be using a third-party module for this. For instance, flask is a popular web framework with a built-in server:
from datetime import datetime
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
return current_time
Save it to server.py
and then run using:
> export FLASK_APP=server.py
> flask run
* Running on http://127.0.0.1:5000/
Access http://127.0.0.1:5000/
from your browser or using wget http://127.0.0.1:5000/
or curl http://127.0.0.1:5000/
.
Upvotes: 1