-
Notifications
You must be signed in to change notification settings - Fork 43
/
get_vtkjs_url.py
74 lines (53 loc) · 1.76 KB
/
get_vtkjs_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Use this script on the command line in a manner such as:
python get_vtkjs_url.py <web file host> <file link>
For Example:
python get_vtkjs_url.py dropbox https://www.dropbox.com/s/6m5ttdbv5bf4ngj/ripple.vtkjs\?dl\=0
python get_vtkjs_url.py github https://github.com/OpenGeoVis/PVGeo/raw/docs/ripple.vtkjs
Current file hosts supported:
- Dropbox
- GitHub
"""
import sys
class stf:
"""
String Formatting
"""
G = '\033[92m' # Green
R = '\033[91m' # Red
B = '\033[1m' # Bold
U = '\033[4m' # Underline
END = '\033[0m' # Normal
def convertDropboxURL(url):
return url.replace("https://www.dropbox.com", "https://dl.dropbox.com")
def convertGitHubURL(url):
url = url.replace("https://github.com", "https://rawgit.com")
url = url.replace("raw/", "")
return url
def generateViewerURL(dataURL):
viewerURL = "http://viewer.pvgeo.org/"
return viewerURL + '%s%s' % ("?fileURL=", dataURL)
def main():
if len(sys.argv) != 3:
print("%s--> Incorrect arguments for the script!" % stf.R)
print('--> Usage: %s <web file host> <file link>%s' % (sys.argv[0], stf.END))
sys.exit(1)
host = sys.argv[1]
inURL = sys.argv[2]
if host.lower() == "dropbox":
convertURL = convertDropboxURL(inURL)
elif host.lower() == "github":
convertURL = convertGitHubURL(inURL)
else:
print(
"%s%s--> Warning: Web host not specified or supported. URL is simply appended to standalone scene loader link.%s"
% (stf.R, stf.B, stf.END)
)
convertURL = inURL
print(
"--> Your link: %s%s%s%s"
% (stf.U, stf.G, generateViewerURL(convertURL), stf.END)
)
exit(0)
if __name__ == '__main__':
main()