Use sqlite3 with NAO (Pepper)

When I wanted to save data with NAO, it was surprisingly easy.

environment

OS X El Capitan 10.11.3 Choregraphe 2.1.3.3 SQLite version 3.8.10.2

Python Script You can leave the box at the default.

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        #put initialization code here
        pass

    def onUnload(self):
        #put clean-up code here
        pass

    def onInput_onStart(self):
        import sqlite3
        
        appId = self.packageUid()
        qi.path.setWritablePath("/Users/{User name}/Desktop/dev/nao/data_files") #Specify any location

        dbpath = qi.path.userWritableDataPath(appId, "sample.db")
        self.logger.info(dbpath)

        conn = sqlite3.connect(dbpath)
        c = conn.cursor()
        c.execute('''CREATE TABLE shop (id INTEGER PRIMARY KEY, name TEXT , price INTEGER)''')
        c.execute("INSERT INTO shop (name, price) VALUES ('hogehoge',100)")
        conn.commit()
        conn.close()
                    
        self.onStopped()
        
    def onInput_onStop(self):
        self.onUnload() #it is recommended to reuse the clean-up as the box is stopped

Verification

$ pwd
/Users/{User name}/Desktop/dev/nao/data_files/data/.lastUploadedChoregrapheBehavior

$ sqlite3 sample.db
SQLite version 3.8.10.2 2015-05-20 18:17:19
Enter ".help" for usage hints.
sqlite> .table
shop
sqlite> select * from shop;
1|hogehoge|100

I was able to register.

Other

It seems that CSV package, JSON package, ElementTree package can also be used.

Recommended Posts

Use sqlite3 with NAO (Pepper)
Use sqlite load_extensions with Pyramid
Use mecab-ipadic-neologd with igo-python
Use ansible with cygwin
Use pipdeptree with virtualenv
[Python] Use JSON with Python
Use Mock with pytest
Use indicator with pd.merge
Use Gentelella with django
Use mecab with Python3
Use tensorboard with Chainer
Use DynamoDB with Python
Use pip with MSYS2
Use Python 3.8 with Anaconda
Use pyright with Spacemacs
Use python with docker
Use TypeScript with django-compressor
Point Cloud with Pepper
Use LESS with Django
Easy to use SQLite3
Use MySQL with Django
Use Enums with SQLAlchemy
Use tensorboard with NNabla
Use GPS with Edison
Use nim with Jupyter
Use Cursur that closes automatically with sqlite3 in Python
Use Trello API with python
Use shared memory with shared libraries
Use custom tags with PyYAML
Use directional graphs with networkx
Use TensorFlow with Intellij IDEA
Use Twitter API with Python
Use pip with Jupyter Notebook
Use DATE_FORMAT with SQLAlchemy filter
Use TUN / TAP with Python
Use Windows 10 fonts with WSL
Use chainer with Jetson TK1
Use SSL with Celery + Redis
Use Cython with Jupyter Notebook
Debug with PEPPER python interpreter
Use Maxout + CNN with Pylearn2
Use WDC-433SU2M2 with Manjaro Linux
Use OpenBLAS with numpy, scipy
[Python] [SQLite3] Operate SQLite with Python (Basic)
Use subsonic API with python3
Use Sonicwall NetExtener with Systemd
Use prefetch_related conveniently with Django
Use AWS interpreter with Pycharm
Use Bokeh with IPython Notebook
Use Python-like range with Rust
Use MLflow with Databricks ④ --Call model -
When coverage fails with _sqlite3 error
Use pyright with CentOS7, emacs lsp-mode
Python: How to use async with
Use Azure SQL Database with SQLAlchemy
Use PointGrey camera with Python (PyCapture2)
Use PX-S1UD / PX-Q1UD with Jetson nano
Use the preview feature with aws-cli
Easily handle lists with python + sqlite3
How to use SQLite in Python
How to use virtualenv with PowerShell