Skip to content

Instantly share code, notes, and snippets.

@toboqus
Created December 15, 2015 11:35
Show Gist options
  • Save toboqus/8e92a5f7ee9e20eb7784 to your computer and use it in GitHub Desktop.
Save toboqus/8e92a5f7ee9e20eb7784 to your computer and use it in GitHub Desktop.
import sqlite3
import calendar
import time
class Database:
_conn = None
def __init__(self):
self._conn = sqlite3.connect("url.db")
cur = self._conn.cursor()
cur.execute(''' CREATE TABLE IF NOT EXISTS urls (url TEXT PRIMARY KEY UNIQUE , crawlDate TEXT) ''')
def __del__(self):
self._conn.close();
def addURL(self, url):
record = (url, calendar.timegm(time.gmtime()))
cur = self._conn.cursor()
cur.execute(''' INSERT OR REPLACE INTO urls VALUES (?, ?)''', record)
self._conn.commit()
db = Database()
db.addURL("http://google.com")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment