forked from ShuYuHuang/whisper-subtitle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permanent_url.py
38 lines (31 loc) · 980 Bytes
/
permanent_url.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
33
34
35
36
37
38
import requests
import os
import time
PERM_URL='https://your.url.com'
my_url=None
new_url=''
# you can check if the service is alive by:
# curl http://localhost:4040/api/tunnels
def get_ngrok_url():
response=requests.get("http://localhost:4040/api/tunnels")
return response.json()['tunnels'][0]['public_url']
# forword the curent url to the permanet url
def renew_forward(url):
requests.post(f"{PERM_URL}/?new_url={url}")
if __name__ == '__main__':
while 1:
# get the url if possible
try:
new_url = get_ngrok_url()
except:
# open the host if ngrok is not started
os.system("bash public_url.sh")
time.sleep(1)
new_url = get_ngrok_url()
# if the url changed
if (not my_url) | (my_url != new_url):
# update url record
my_url = new_url
# forward the url to PERM_URL
renew_forward(my_url)
time.sleep(600)