forked from philip-zhan/decentralized-social-network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
32 lines (24 loc) · 873 Bytes
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import subprocess
import requests
from tracker import tracker
from server import server
def main():
my_address = run_ngrok()
peers = tracker.get_peers()
run_server(my_address, peers)
def run_ngrok():
subprocess.Popen(['./ngrok', 'http', '8000'], stdout=subprocess.PIPE)
response = requests.get('http://localhost:4040/api/tunnels')
if response.ok and len(response.json()['tunnels']) > 0:
tunnels = response.json()['tunnels']
for tunnel in tunnels:
if tunnel['proto'] == 'http' and tunnel['config']['addr'] == 'localhost:8000':
public_url = tunnel['public_url']
print('Public URL:', public_url)
return public_url
print('Failed to start ngrok')
exit()
def run_server(my_address, peers):
server.main(my_address, peers)
if __name__ == '__main__':
main()