| Hosted by CoCalc | Download
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
# This runs a demo-webservice inside CoCalc.
4
# Run by typing
5
# python3 main.py
6
# in a terminal (or just ./main.py).
7
# I tested this on June 26, 2020. -- William Stein
8
9
## **IMPORTANT:** only collaborators on the project where you run
10
## this can access this web server!
11
12
port = 12345
13
14
def project_id():
15
import json
16
import os
17
info = json.load(open(os.path.join(os.environ['HOME'], ".smc", "info.json"), 'r'))
18
return info['project_id']
19
20
base_url = "/%s/port/%s/" % (project_id(), port)
21
22
from flask import Flask
23
app = Flask(__name__)
24
25
@app.route(base_url)
26
def hello_world():
27
from datetime import datetime
28
return 'Hello World!\nThe current time is %s' % datetime.utcnow()
29
30
if __name__ == "__main__":
31
print("Try to open\n\n https://cocalc.com" + base_url + '\n\n')
32
app.run(host = '0.0.0.0', port = port)
33
import sys; sys.exit(0)
34
35