4
4
from __future__ import (absolute_import , division ,
5
5
print_function , unicode_literals )
6
6
7
- import copy
8
- import math
9
- import sys
10
- import time
11
- from collections import namedtuple
12
- import requests
13
7
import json
8
+ import requests
14
9
15
10
16
11
class Loklak (object ):
@@ -30,7 +25,7 @@ class Loklak(object):
30
25
limit = None
31
26
action = None
32
27
data = {}
33
-
28
+
34
29
def status (self ):
35
30
"""Returns the status of the server"""
36
31
status_application = 'api/status.json'
@@ -66,17 +61,18 @@ def geocode(self, places=None):
66
61
return_to_user = {}
67
62
return json .dumps (return_to_user )
68
63
69
- def map (self , latitude , longitude , width = 500 , height = 500 , zoom = 8 , text = "" ):
70
- """Returns a map of size 500x500"""
71
- map_application = 'vis/map.png'
72
- params = {'text' : text , 'mlat' : latitude , 'mlon' : longitude ,\
73
- 'width' : width , 'height' : height , 'zoom' : zoom }
74
- return_to_user = requests .get (self .baseUrl + map_application , \
75
- params = params , stream = True )
76
- if return_to_user .status_code == 200 :
77
- return return_to_user .raw .read ()
78
- else :
79
- return ''
64
+ def get_map (self , latitude , longitude , width = 500 , height = 500 ,
65
+ zoom = 8 , text = "" ):
66
+ """Returns a map of size 500x500"""
67
+ map_application = 'vis/map.png'
68
+ params = {'text' : text , 'mlat' : latitude , 'mlon' : longitude ,
69
+ 'width' : width , 'height' : height , 'zoom' : zoom }
70
+ return_to_user = requests .get (self .baseUrl + map_application ,
71
+ params = params , stream = True )
72
+ if return_to_user .status_code == 200 :
73
+ return return_to_user .raw .read ()
74
+ else :
75
+ return ''
80
76
81
77
def peers (self ):
82
78
"""Gives the peers of a user"""
@@ -113,13 +109,14 @@ def user(self, name=None, followers=None, following=None):
113
109
return json .dumps (return_to_user )
114
110
else :
115
111
return_to_user = {}
116
- return_to_user ['error' ] = 'No user name given to query. Please check and try again'
112
+ return_to_user ['error' ] = ('No user name given to query. Please '
113
+ 'check and try again' )
117
114
return json .dumps (return_to_user )
118
115
119
116
def settings (self ):
120
117
"""Gives the settings of the application"""
121
- settings_application = 'settings.json'
122
- url_to_give = 'http://localhost:9000/api/' + settings_application
118
+ settings_application = 'api/ settings.json'
119
+ url_to_give = self . baseUrl + settings_application
123
120
return_to_user = requests .get (url_to_give )
124
121
if return_to_user .status_code == 200 :
125
122
return return_to_user .json ()
@@ -151,21 +148,24 @@ def search(self, query=None, since=None, until=None, from_user=None):
151
148
return return_to_user .json ()
152
149
else :
153
150
return_to_user = {}
154
- return_to_user ['error' ] = 'Something went wrong, Looks like the server is down.'
151
+ return_to_user ['error' ] = ('Something went wrong, Looks like'
152
+ ' the server is down.' )
155
153
return json .dumps (return_to_user )
156
154
else :
157
155
return_to_user = {}
158
- return_to_user ['error' ] = 'No Query string has been given to run a query for'
156
+ return_to_user ['error' ] = ('No Query string has been'
157
+ ' given to run a query for' )
159
158
return json .dumps (return_to_user )
160
159
161
- def aggregations (self , query = None , since = None , until = None , fields = None , limit = None ):
160
+ def aggregations (self , query = None , since = None , until = None ,
161
+ fields = None , limit = None ):
162
162
"""Gives the aggregations of the application"""
163
163
aggregations_application = 'api/search.json'
164
164
url_to_give = self .baseUrl + aggregations_application
165
165
self .query = query
166
166
self .since = since
167
167
self .until = until
168
- self .fields = fields # Array seperated values to be passed
168
+ self .fields = fields
169
169
self .limit = limit
170
170
if query :
171
171
params = {}
@@ -177,11 +177,11 @@ def aggregations(self, query=None, since=None, until=None, fields=None, limit=No
177
177
if fields :
178
178
field_string = ''
179
179
for i in self .fields :
180
- field_string += i + ','
180
+ field_string += i + ','
181
181
params ['fields' ] = field_string
182
182
if limit :
183
183
params ['limit' ] = self .limit
184
- if limit == None :
184
+ if limit is None :
185
185
limit = 6
186
186
params ['limit' ] = self .limit
187
187
params ['count' ] = 0
@@ -191,7 +191,8 @@ def aggregations(self, query=None, since=None, until=None, fields=None, limit=No
191
191
return return_to_user
192
192
else :
193
193
return_to_user = {}
194
- return_to_user ['error' ] = 'Something went wrong, Looks like the server is down.'
194
+ return_to_user ['error' ] = ('Something went wrong, '
195
+ 'Looks like the server is down.' )
195
196
return json .dumps (return_to_user )
196
197
else :
197
198
return_to_user = {}
@@ -208,32 +209,38 @@ def account(self, name=None, action=None, data=None):
208
209
self .action = action
209
210
# Simple GET Query
210
211
headers = {
211
- 'User-Agent' : 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0' ,
212
+ 'User-Agent' : ('Mozilla/5.0 (Android 4.4; Mobile; rv:41.0)'
213
+ ' Gecko/41.0 Firefox/41.0' ),
212
214
213
215
}
214
216
if name :
215
217
params = {}
216
218
params ['screen_name' ] = self .name
217
- return_to_user = requests .get (url_to_give , params = params , headers = headers )
219
+ return_to_user = requests .get (url_to_give , params = params ,
220
+ headers = headers )
218
221
if return_to_user .status_code == 200 :
219
222
return return_to_user .json ()
220
223
else :
221
224
return_to_user = {}
222
- return_to_user ['error' ] = 'Something went wrong, Looks query is wrong.'
225
+ return_to_user ['error' ] = ('Something went wrong, '
226
+ 'Looks query is wrong.' )
223
227
return json .dumps (return_to_user )
224
228
# if action = update and data is provided, then make request
225
229
elif self .action == 'update' and data :
226
230
params = {}
227
231
params ['action' ] = self .action
228
232
params ['data' ] = self .data
229
- return_to_user = requests .post (url_to_give , params = params , headers = headers )
233
+ return_to_user = requests .post (url_to_give ,
234
+ params = params , headers = headers )
230
235
if return_to_user .status_code == 200 :
231
236
return return_to_user .json ()
232
237
else :
233
238
return_to_user = {}
234
- return_to_user ['error' ] = 'Something went wrong, Looks query is wrong.'
239
+ return_to_user ['error' ] = ('Something went wrong,'
240
+ ' Looks query is wrong.' )
235
241
return json .dumps (return_to_user )
236
242
else :
237
243
return_to_user = {}
238
- return_to_user ['error' ] = 'No Query string has been given to run an query for account'
244
+ return_to_user ['error' ] = ('No Query string has been given'
245
+ ' to run an query for account' )
239
246
return json .dumps (return_to_user )
0 commit comments