Skip to content

Instantly share code, notes, and snippets.

@wadewegner
Last active August 29, 2015 14:00
Show Gist options
  • Save wadewegner/6aa1c8a8e864cdcb4cf7 to your computer and use it in GitHub Desktop.
Save wadewegner/6aa1c8a8e864cdcb4cf7 to your computer and use it in GitHub Desktop.
import os
import psycopg2
import urlparse
urlparse.uses_netloc.append("postgres")
url = urlparse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
cur = conn.cursor()
cur.execute('INSERT INTO iot_monitortemps.readings__c (celsius__c, fahrenheit__c, readingdatetime__c) ' +
'VALUES (%s, %s, %s)',
(25.2225819147,83.261394157,'2014-05-02 21:39:12.795193+00:00'))
cur.execute('select * from iot_monitortemps.readings__c')
rows = cur.fetchall()
print "\nShow me the records:\n"
for row in rows:
print " ", row[1]
conn.commit()
cur.close()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment