Created
September 24, 2013 23:57
-
-
Save slarson/6693044 to your computer and use it in GitHub Desktop.
Access OpenWorm Semantic Database via Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "Access OpenWorm Semantic Database via Python" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "A simple example of using a [Python MySQL library](https://github.com/PyMySQL/PyMySQL) to access the [OpenWorm Semantic Database](http://www.interintelligence.org/openworm/)." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "!sudo pip install PyMySQL", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "Downloading/unpacking PyMySQL\r\n" | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": " Downloading PyMySQL-0.5.tar.gz\r\n" | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": " Running setup.py egg_info for package PyMySQL\r\n" | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": " \r\nInstalling collected packages: PyMySQL\r\n Running setup.py install for PyMySQL\r\n" | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": " \r\n" | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "Successfully installed PyMySQL\r\nCleaning up...\r\n" | |
} | |
], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "#!/usr/bin/env python\n\nimport pymysql\n\n#conn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock', user='root', passwd=None, db='mysql')\n\nconn = pymysql.connect(host='my01.winhost.com', port=3306, user='openworm', passwd='openworm', db='mysql_31129_celegans')\n \ncur = conn.cursor()\n\ncur.execute(\"SELECT DISTINCT EnID1 FROM tblrelationship LIMIT 5\")\n\n# print cur.description\n\n# r = cur.fetchall()\n# print r\n# ...or...\nfor r in cur.fetchall():\n print(r)\n\ncur.close()\nconn.close()", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "(39L,)\n(48L,)\n(49L,)\n(40L,)\n(41L,)\n" | |
} | |
], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment