Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
script:python:new:xtra [2014/05/19 15:52] alfred [PyMongo] |
script:python:new:xtra [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 170: | Línea 170: | ||
| client = MongoClient('localhost', 27017) | client = MongoClient('localhost', 27017) | ||
| client = MongoClient('mongodb://localhost:27017/') | client = MongoClient('mongodb://localhost:27017/') | ||
| + | </code> | ||
| + | |||
| + | Getting a db: | ||
| + | <code python> | ||
| + | db = client.test_database | ||
| + | db = client['test-database'] | ||
| </code> | </code> | ||
| Línea 181: | Línea 187: | ||
| <code python> | <code python> | ||
| import datetime | import datetime | ||
| - | post = { "author": "Mike", "text": "My first blog post!", "tags": ["mongodb", "python", "pymongo"], "date": datetime.datetime.utcnow() } | + | post = { |
| + | "author": "Mike", | ||
| + | "text": "My first blog post!", | ||
| + | "tags": ["mongodb", "python", "pymongo"], | ||
| + | "date": datetime.datetime.utcnow() | ||
| + | } | ||
| posts = db.posts | posts = db.posts | ||
| post_id = posts.insert(post) | post_id = posts.insert(post) | ||
| Línea 188: | Línea 199: | ||
| Querying: | Querying: | ||
| <code python> | <code python> | ||
| + | posts.find() | ||
| posts.find_one({"author": "Mike"}) | posts.find_one({"author": "Mike"}) | ||
| posts.find_one({"_id": post_id}) | posts.find_one({"_id": post_id}) | ||
| Línea 197: | Línea 209: | ||
| posts.count() | posts.count() | ||
| posts.find({"author": "Mike"}).count() | posts.find({"author": "Mike"}).count() | ||
| + | </code> | ||
| + | |||
| + | ==== Message Pack ==== | ||
| + | <code python> | ||
| + | import msgpack | ||
| + | import array | ||
| + | import json | ||
| + | |||
| + | data = raw_input('Insert data > ') | ||
| + | data = json.loads(data) | ||
| + | packed_data = msgpack.packb(data) | ||
| + | bin_data = array.array('B', packed_data).tolist() | ||
| + | unpacked_data = msgpack.unpackb(array.array('B', bin_data).tostring()) | ||
| + | |||
| + | print 'data:', data | ||
| + | print 'binary data:', bin_data | ||
| + | print 'unpacked_data:', unpacked_data | ||
| </code> | </code> | ||
| ==== Otras ==== | ==== Otras ==== | ||
| * [[http://code.google.com/p/psutil/|psutil]], para controlar el rendimiento de la máquina. | * [[http://code.google.com/p/psutil/|psutil]], para controlar el rendimiento de la máquina. | ||
| + | * [[https://pypi.python.org/pypi/PyHamcrest|PyHamcrest]], para hacer comprobaciones entre instancias en los tests. | ||
| + | * [[https://pypi.python.org/pypi/termcolor|termcolor]], para mostrar colores por consola. | ||
| + | * [[https://dataset.readthedocs.org/en/latest/|dataset]], ORM para emular una NoSQL con SQLite. | ||
| + | * [[https://pypi.python.org/pypi/tabulate|tabulate]], para mostrar datos en tablas por consola. | ||
| + | |||
| + | === No utilizadas === | ||
| + | * [[https://github.com/kennethreitz/envoy|envoy]], para ejecutar programas más fácilmente. | ||
| + | * [[https://github.com/ansible/ansible|Ansible]], configuration-management, application deployment, task-execution, and multinode orchestration engine. | ||
| + | * [[https://github.com/jakubroztocil/httpie|httpie]], a cURL, easy-to-use, alternative. | ||
| + | * [[https://github.com/kennethreitz/requests|requests]], a library to manage HTTP requests. | ||
| + | * [[https://github.com/saltstack/salt|Salt]], is an infrastructure management. Easy enough to get running in minutes, scalable enough to manage tens of thousands of servers, and fast enough to communicate with them in seconds. | ||
| + | * [[https://github.com/getpelican/pelican|pelican]], static site generator. | ||
| ===== Utilidades ===== | ===== Utilidades ===== | ||
| Línea 284: | Línea 325: | ||
| === virtualenvwrapper === | === virtualenvwrapper === | ||
| * [[http://virtualenvwrapper.readthedocs.org/en/latest/]] | * [[http://virtualenvwrapper.readthedocs.org/en/latest/]] | ||
| - | Es una herramienta para hacer más cómodo el uso de ''virtualenv''. | + | Es una herramienta para hacer más cómodo el uso de ''virtualenv''. Para instalarla haz: |
| + | <code> | ||
| + | $ pip install virtualenvwrapper | ||
| + | </code> | ||
| + | Y añade al .bashrc: | ||
| + | <code> | ||
| + | export WORKON_HOME=$HOME/.virtualenvs | ||
| + | export PROJECT_HOME=$HOME/Devel | ||
| + | source /usr/local/bin/virtualenvwrapper.sh | ||
| + | </code> | ||
| * ''$ workon'' lista los virtualenv creados. | * ''$ workon'' lista los virtualenv creados. | ||
| * ''$ mkvirtualenv <nombre>'' crea un virtualenv. | * ''$ mkvirtualenv <nombre>'' crea un virtualenv. | ||