Skip to content

Instantly share code, notes, and snippets.

@jachin
Last active December 10, 2015 13:28
Show Gist options
  • Save jachin/4440831 to your computer and use it in GitHub Desktop.
Save jachin/4440831 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import uuid
con = lite.connect('bom.db')
with con:
cur = con.cursor()
cur.execute( "SELECT id FROM upc WHERE uuid IS NULL")
for row in cur.fetchall():
id = row[0]
cur.execute( "UPDATE upc SET uuid = ? WHERE id = ?", (str(uuid.uuid4()), id) )
#con.commit()
print(row)
con.close()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
import sqlite3 as lite
import httplib
import socket
import uuid
con = lite.connect('bom.db')
with con:
cur = con.cursor()
cur.execute(
"""
CREATE TABLE IF NOT EXISTS upc(
id INTEGER PRIMARY KEY AUTOINCREMENT,
`upc` TEXT,
`location` TEXT,
`uuid` TEXT,
`timestamp` timestamp DEFAULT CURRENT_TIMESTAMP
)
"""
)
con.commit()
con.close()
while True:
barcode = raw_input("scann bar code: ")
if barcode == '':
continue
print(datetime.now())
print(barcode)
con = lite.connect('bom.db')
with con:
cur = con.cursor()
cur.execute(
"INSERT INTO upc (upc, location, uuid) VALUES( ?, ?, ? )",
( barcode, socket.gethostname(), str(uuid.uuid4()) )
)
con.commit()
con.close()
# Small time out for repeated scans.
try:
conn = httplib.HTTPConnection("beverages.cw", timeout=1)
conn.request("GET", "/ping/?upc={0}".format(barcode))
response = conn.getresponse()
conn.close()
print("Ping status {0}".format(response.status))
except (httplib.HTTPException, socket.error):
print("Unable to ping, no big deal.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment