Skip to content

Instantly share code, notes, and snippets.

@nicholsonjf
Last active June 7, 2016 00:39
Show Gist options
  • Save nicholsonjf/1ac5460200f3ebb5d0e46ab693ea9295 to your computer and use it in GitHub Desktop.
Save nicholsonjf/1ac5460200f3ebb5d0e46ab693ea9295 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'c:\\\\Users\\\\nicholjf\\\\Documents\\\\jupyter\\\\crestcrawl'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"os.getcwd()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"os.chdir('c:\\\\Users\\\\nicholjf\\\\Documents\\\\crawlnet')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import prod.address, prod.sync"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<module 'prod.address' from 'prod\\address.pyc'>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prod.address"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%load_ext autoreload"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"pt = 'c:\\\\Users\\\\nicholjf\\\\Documents\\\\crawlnet\\\\prod\\\\sql'\n",
"fn = 'prod_gsb_crestron_devices.sqlite'\n",
"string = os.path.join(fn, pt)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"'1/1 No changes at 10.75.217.171:41795'\n"
]
}
],
"source": [
"with prod.sync.open_sync(fn, pt) as helper:\n",
" sql = \"\"\"SELECT rowid, ip_address, port_number, hostname,\n",
" serial_number, device_type, mac_address FROM devices\n",
" WHERE is_active = 1 AND ip_address = '10.75.217.171'\n",
" AND port_number = 41795\"\"\"\n",
" helper.sync_db(sql)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from prod.address import AddressBook"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"new_book = AddressBook(db_file_name=fn, db_path=pt)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sql_string = \"\"\"SELECT a.ip_address, a.port_number, a.location, b.display_name, a.variant\n",
" FROM devices AS a LEFT JOIN device_types AS b\n",
" ON a.device_type = b.device_type\n",
" WHERE a.is_active = 1\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"tmp_file = os.path.join(os.getcwd(), 'templates', 'crestron_address_book.xadr')"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"output_file = 'c:\\\\Users\\\\nicholjf\\\\Documents\\\\crawlnet\\\\address_books'"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"new_book.write_book(sql_string, tmp_file, output_file)\n",
"new_book.conn.commit()\n",
"new_book.conn.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"'1/434 No changes at 10.75.217.246:41795'\n",
"'2/434 No changes at 10.75.218.64:41795'\n",
"'3/434 No changes at 10.75.217.220:41795'\n"
]
}
],
"source": [
"with prod.sync.open_sync(fn, pt) as helper:\n",
" sql = \"\"\"SELECT rowid, ip_address, port_number, hostname,\n",
" serial_number, device_type, mac_address FROM devices\n",
" WHERE is_active = 1\"\"\"\n",
" helper.sync_db(sql)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 == True"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0 == False"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment