Skip to content

Commit d2c52d5

Browse files
committed
fixes #12 Added constructor to check the baseURL
1 parent 60299e0 commit d2c52d5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

loklak.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
print_function, unicode_literals)
66

77
import json
8+
import re
89
import requests
910

1011

@@ -26,6 +27,22 @@ class Loklak(object):
2627
action = None
2728
data = {}
2829

30+
def __init__(self, baseUrl='http://loklak.org/'):
31+
baseUrl = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', baseUrl)
32+
try:
33+
if baseUrl[0]:
34+
if baseUrl[0] != 'http://loklak.org/':
35+
url_test = self.hello()
36+
if url_test['status'] == 'ok':
37+
self.baseUrl = baseUrl[0]
38+
else:
39+
self.baseUrl = baseUrl[0]
40+
except IndexError:
41+
pass
42+
43+
def getBaseUrl(self):
44+
return self.baseUrl
45+
2946
def status(self):
3047
"""Returns the status of the server"""
3148
status_application = 'api/status.json'

0 commit comments

Comments
 (0)