Kivy is written in Python, so you can use any mysql libraries in python.
I suggest you to take a look at sqlalchemy (http://www.sqlalchemy.org/)
for an high level access to database, or if you prefer to write sql
request by hand, you can use directly
http://mysql-python.sourceforge.net/MySQLdb.html.
But both libraries are not standard, and so, not shipped with Kivy.
I can also suggest another way of working with kivy. Use json !
If you create webpage that output json, or data, you can use it in a
simpler manner.
Check: http://kivy.org/docs/api-kivy.network.urlrequest.html
You have 2 examples that demonstrate how to make a request and get the
content. If you output json with good Content-Type, the result will be a
python object. So you can use it directly for creating the list.
Example of web output
URL: /api/get_medias
[
{
'title': 'Image number 1',
'type': 'image',
'url': 'http://yourhost/uploads/image1.jpg' }
{
'title': 'Video number 1',
'type': 'video',
'url': 'http://yourhost/uploads/video.mkv'
}
]
And how you can use it in Kivy (not tested, must be improved, but just
for the logic.):
from kivy.network.urlrequest import UrlRequest
from kivy.uix.image import Image
from kivy.uix.video import Video
from random import random
class MyApp(App):
def create_objects(self, req, result):
for item in result:
if item['type'] == 'image':
# create image
widget = Image(source=result['url'])
elif item['type'] == 'video':
# create video
widget = Video(source=result['url'])
else:
print 'unknown type for', result
continue
widget.pos = random() * 500, random() * 500
self.root.add_widget(widget)
def build(self):
root = FloatLayout()
req = UrlRequest('http://yourhost/api/get_medias',
self.create_objects)
return root
if __name__ == '__main__':
MyApp().run()
Hope that will give you some tips !
Regards,
Mathieu
The result object is not a dict, but in fact a list of dicts. result[0]['trends'] should give you what you want.
Print out the result object to see the structure.
Thanks very much for your reply,Im experimenting with the urlrequest classspecially the twitter example. I found out that the url for twitter trends have just changed to a new one: https://api.twitter.com/1/trends/1.jsonbut also.. I get an error when trying to run:trends = result['trends']TypeError: list indices must be integers, not strIm new to json and python, so I dont know whats wrong with the array.Also I have a question...My app is supose to filter media by categories, so Im planning on using json to get categories from DB and generate a Tree interface menu or something, then also use json to get all media from selected Category.So I guess I will need to create a site that outputs json for all categories but also a site that generates json for a specific category...because getting ALL media from all categories when you only need few? i think it could generate a very large json file, and probably not the must efficient way to make a sql selection. I Found this : http://craftyman.net/mysql-to-json/so much Thanks in advance.