This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Geofence service
#1
Hi,
surfing on web I found this opportunity (https://openpaths.cc/api/1).

Here below is the script in Python. How can we traduce in lua? Thanks. 

#!/usr/bin/env python        

import oauth2, time, urllib, urllib2, json

ACCESS = "YOURACCESSKEY"
SECRET = "YOURSECRETKEY"
URL = "https://openpaths.cc/api/1"

def build_auth_header(url, method):
   params = {                                            
       'oauth_version': "1.0",
       'oauth_nonce': oauth2.generate_nonce(),
       'oauth_timestamp': int(time.time()),
   }
   consumer = oauth2.Consumer(key=ACCESS, secret=SECRET)
   params['oauth_consumer_key'] = consumer.key
   request = oauth2.Request(method=method, url=url, parameters=params)    
   signature_method = oauth2.SignatureMethod_HMAC_SHA1()
   request.sign_request(signature_method, consumer, None)
   return request.to_header()

# GET data (last 24 hours)
now = time.time()
params = {'start_time': now - 24*60*60, 'end_time': now}    # get the last 24 hours
query = "%s?%s" % (URL, urllib.urlencode(params))
print(query)
try:
   request = urllib2.Request(query)
   request.headers = build_auth_header(URL, 'GET')
   connection = urllib2.urlopen(request)
   data = json.loads(''.join(connection.readlines()))
   print(json.dumps(data, indent=4))
except urllib2.HTTPError as e:
   print(e.read())    
   
   

5. Use your data
The API returns JSON. You will get an array of objects — each one comprises a location object with lat, lon, and alt data and a timestamp. You will also see metadata on how the record was generated (if applicable), including the device model, its operating system version, and the version of the OpenPaths mobile app. Requests for project data will also include a participant identifier for each entry.
   
[
   {
       "lon": -73.99093,
       "lat": 40.751453,
       "alt": 0.0,
       "t": 1308274880,
       "device": "iPhone3,1",
       "os": "4.3.2",
       "version": "1.0"
   }
]    
Reply


Forum Jump: