Browse Source

backend

queue_backend
Kamo Petrosyan 4 years ago
parent
commit
b7ad3ca04f
3 changed files with 90 additions and 1 deletions
  1. +6
    -0
      README.rst
  2. +83
    -0
      pysitemap/backends/sqlite_todo.py
  3. +1
    -1
      version.py

+ 6
- 0
README.rst View File

@ -54,6 +54,12 @@ TODO
changelog changelog
--------- ---------
v. 0.9.2
''''''''
- todo queue and done list backends
- sqlite backend for todo queue and done lists
v. 0.9.1 v. 0.9.1
'''''''' ''''''''


+ 83
- 0
pysitemap/backends/sqlite_todo.py View File

@ -0,0 +1,83 @@
import logging
import sqlite3
class SQLiteTodo(object):
def __init__(self, db_name):
self.connection = sqlite3.connect(db_name)
self.__init_tables()
def __init_tables(self):
cursor = self.connection.cursor()
cursor.execute("DROP TABLE IF EXISTS todo_queue;")
cursor.execute("""
CREATE TABLE todo_queue (
url text(1000) primary key
);
""")
self.connection.commit()
cursor.close()
def add(self, url):
cursor = self.connection.cursor()
try:
cursor.execute("""insert into todo_queue values (?);""", (url,))
except Exception as e:
logging.info(e)
finally:
self.connection.commit()
cursor.close()
def remove(self, url):
cursor = self.connection.cursor()
try:
cursor.execute("""delete from todo_queue where url = ?;""", (url,))
except Exception as e:
logging.info(e)
finally:
self.connection.commit()
cursor.close()
def __contains__(self, item):
cursor = self.connection.cursor()
result = False
try:
cursor.execute("""select 1 from todo_queue where url = ?""", (item, ))
row = cursor.fetchone()
if len(row):
result = True
except Exception as e:
logging.info(e)
finally:
cursor.close()
return result
def __iter__(self):
cursor = self.connection.cursor()
result = []
try:
cursor.execute("""select url from todo_queue""")
rows = cursor.fetchall()
result = [row[0] for row in rows]
except Exception as e:
logging.info(e)
finally:
cursor.close()
return iter(result)
def __next__(self):
for url in self:
yield url
def __len__(self):
cursor = self.connection.cursor()
result = []
try:
cursor.execute("""select count(*) as cnt from todo_queue""")
row = cursor.fetchone()
result = row[0]
except Exception as e:
logging.info(e)
finally:
cursor.close()
return result

+ 1
- 1
version.py View File

@ -1 +1 @@
VERSION = '0.9.1'
VERSION = '0.9.2'

Loading…
Cancel
Save