Author Topic: showing points from Python  (Read 2492 times)

Offline lamer

  • Newbie
  • *
  • Posts: 3
    • View Profile
showing points from Python
« on: April 14, 2011, 10:59:08 »
I tried to supply points from python using your data structure. Unfortunaly i get Errors because the SL4A backend tries to parse the 'extra data' as JSON or to encode it to JSON.
Code: [Select]
import android
import sqlite3
import struct

def geostd(droid,lat,lon):
url='geo:%s,%s'% (lat,lon)
droid.startActivity('android.intent.action.VIEW',url)

def javautf(str1):
str2=str1.encode('utf8')
return struct.pack('>h',len(str2))+str2

def points2locus(points):
'''Takes a list of tuples
Name,HTML-desc,extradata,latitude,longitude,image
'''
return struct.pack('>i',len(points))+
''.join([struct.pack('>i',len(point[5]))+point[5]+
''.join([javautf(str3) for str3 in point[0:3]])+
struct.pack('>dd',point[3],point[4]) for point in points])

def geolocus(droid,points):
extras={'extraDataName':points2locus(points)}
droid.startActivity('android.intent.action.VIEW','menion.points:extraDataName', None,None, extras, False)

droid = android.Android()
sqlc = sqlite3.connect('/sdcard/wiglewifi/wiglewifi.sqlite')
cur=sqlc.cursor()
cur.execute('select * from network where ssid=? limit 10',('eduroam',))
result= cur.fetchall()
sqlc.close()

#geostd(droid,result[0][5],result[0][6])
geolocus([(row[1],row[0],'',row[5],row[6],'') for row in result])

Code: [Select]
 request = json.dumps(data)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 43: unexpected code byte

has anyone an idea how to create und submit such datastructure in python?
« Last Edit: January 01, 1970, 01:00:00 by Guest »
 

Offline marlar

  • More than Newbie
  • *
  • Posts: 82
    • View Profile
Re: [DEVELOPING] - showing points on app
« Reply #1 on: April 14, 2011, 16:34:36 »
Lamer, a bit offtopic but it is possible to program Android in Python?
« Last Edit: January 01, 1970, 01:00:00 by Guest »
 

Offline lamer

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: [DEVELOPING] - showing points on app
« Reply #2 on: April 14, 2011, 18:37:32 »
Yes it is. There is the Scripting Layer for Android (SL4A) http://code.google.com/p/android-scripting/
It might be not suitable for real apps, meant to be handed out to someone.
« Last Edit: January 01, 1970, 01:00:00 by Guest »
 

Offline menion

  • Administrator
  • Professor of Locus
  • *****
  • Posts: 10878
  • Thanked: 194 times
    • View Profile
    • http://www.asamm.com
  • Device: SGS7
Re: [DEVELOPING] - showing points on app
« Reply #3 on: April 14, 2011, 18:47:14 »
lamer, I do not understand python language so I cannot help you directly, but if you want some update in calling to locus, let me know ...
« Last Edit: January 01, 1970, 01:00:00 by Guest »
Ideas, wishes, problems
Advanced topics, public discussion, sharing of knowledges, testing beta versions: you're here!
 

Offline lamer

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: [DEVELOPING] - showing points on app
« Reply #4 on: April 18, 2011, 11:43:43 »
Hi menion,
to me it seems that this problem is not python specific. But rather a design flaw in the AndroidFacadeAPI. All the script  calls are encoded using JSON, which is meant to handle unicode data. Therefore there is no way in python to create 'invalid' utf8 to transport raw 8-bit data. To only solution I can imagine is reimplement the the whole AndroidFaceAPI call  in order to bypass the default python JSON encoding for the locus specific data structure.
« Last Edit: January 01, 1970, 01:00:00 by Guest »