Created
December 15, 2015 11:35
-
-
Save toboqus/8e92a5f7ee9e20eb7784 to your computer and use it in GitHub Desktop.
This file contains 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
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