Adds firefox module that checks urls
This commit is contained in:
parent
d9e6e51722
commit
c7cea3d278
|
@ -25,6 +25,7 @@ import signal
|
||||||
|
|
||||||
from hackernews import HackerNews
|
from hackernews import HackerNews
|
||||||
from chrome import Chrome
|
from chrome import Chrome
|
||||||
|
from firefox import Firefox
|
||||||
from version import Version
|
from version import Version
|
||||||
|
|
||||||
class HackerNewsApp:
|
class HackerNewsApp:
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
from __future__ import print_function
|
||||||
|
import sqlite3
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
class Firefox:
|
||||||
|
HISTORY_TMP_LOCATION = '/tmp/hackertray.firefox'
|
||||||
|
HISTORY_FILE_NAME = '/places.sqlite'
|
||||||
|
@staticmethod
|
||||||
|
def search(urls, config_folder_path):
|
||||||
|
Firefox.setup(config_folder_path)
|
||||||
|
conn = sqlite3.connect(Firefox.HISTORY_TMP_LOCATION)
|
||||||
|
db = conn.cursor()
|
||||||
|
result = []
|
||||||
|
for url in urls:
|
||||||
|
db_result = db.execute('SELECT url from moz_places WHERE url=:url',{"url":url})
|
||||||
|
if(db.fetchone() == None):
|
||||||
|
result.append(False)
|
||||||
|
else:
|
||||||
|
result.append(True)
|
||||||
|
os.remove(Firefox.HISTORY_TMP_LOCATION)
|
||||||
|
return result
|
||||||
|
@staticmethod
|
||||||
|
def setup(config_folder_path):
|
||||||
|
file_name = os.path.abspath(config_folder_path+Firefox.HISTORY_FILE_NAME)
|
||||||
|
if not os.path.isfile(file_name):
|
||||||
|
print("ERROR: ", "Could not find Firefox history file", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
shutil.copyfile(file_name, Firefox.HISTORY_TMP_LOCATION)
|
|
@ -0,0 +1,15 @@
|
||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
|
from hackertray import Firefox
|
||||||
|
|
||||||
|
class ChromeTest(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
config_folder_path = os.getcwd()+'/test/'
|
||||||
|
data = Firefox.search([
|
||||||
|
"http://www.hckrnews.com/",
|
||||||
|
"http://www.google.com/",
|
||||||
|
"http://wiki.ubuntu.com/",
|
||||||
|
"http://invalid_url/"],
|
||||||
|
config_folder_path)
|
||||||
|
self.assertTrue(data == [True,True,True,False])
|
Binary file not shown.
Loading…
Reference in New Issue