2019-02-02 10:18:57 +00:00
|
|
|
import os
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
from proxy import fetch_proxies
|
|
|
|
|
2019-02-02 15:06:57 +00:00
|
|
|
def get_cache(directory, name):
|
|
|
|
cache_file = os.path.join(directory, "{}.sqlite".format(name))
|
2019-02-02 10:18:57 +00:00
|
|
|
if(not os.path.exists(cache_file)):
|
|
|
|
with open(cache_file, "w") as fin:
|
|
|
|
pass
|
|
|
|
db = sqlite3.connect(cache_file)
|
|
|
|
|
|
|
|
cursor = db.cursor()
|
|
|
|
|
|
|
|
cursor.execute("CREATE TABLE proxies(proxy TEXT, lasttime_could_not_be_used DECIMAL)")
|
|
|
|
cursor.execute("CREATE TABLE links(source TEXT, destination TEXT)")
|
2019-02-02 15:06:57 +00:00
|
|
|
cursor.execute("CREATE TABLE dijkstra_helper(name TEXT UNIQUE, value INT)")
|
|
|
|
cursor.execute("CREATE TABLE failed_to_fetch(title TEXT, depth INT)")
|
2019-02-02 10:18:57 +00:00
|
|
|
|
|
|
|
db.commit()
|
|
|
|
db = sqlite3.connect(cache_file)
|
|
|
|
fetch_proxies(db)
|
|
|
|
return db
|
|
|
|
|
|
|
|
def clear_cache_data(connection):
|
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute("DELETE FROM links")
|
|
|
|
cursor.execute("DELETE FROM dijkstra_helper")
|
|
|
|
connection.commit()
|