This commit is contained in:
kh99 2017-12-29 07:53:01 +00:00 committed by GitHub
commit 7f26ff1887
6 changed files with 40 additions and 22 deletions

View File

@ -1,5 +1,6 @@
from mixpanel import Mixpanel
class Analytics:
# Setup analytics.
# dnt - do not track. Disables tracking if True
@ -7,17 +8,19 @@ class Analytics:
def __init__(self, dnt, token):
self.dnt = dnt
self.tracker = Mixpanel(token)
if(self.dnt == True):
print "[+] Analytics disabled"
if(self.dnt is True):
print("[+] Analytics disabled")
# Track an event
# event - string containing the event name
# data - data related to the event, defaults to {}
def track(self, event, data = {}):
if(self.dnt == False):
def track(self, event, data={}):
if(self.dnt is False):
# All events are tracked anonymously
self.tracker.track("anonymous", event, data)
# Track a visit to a URL
# The url maybe an HN submission or
# The url maybe an HN submission or
# some meta-url pertaining to hackertray
def visit(self, url):
self.track('visit', {"link":url})
self.track('visit', {"link": url})

View File

@ -1,4 +1,4 @@
#=========================
# =========================
#
# AppIndicator for GTK
# drop-in replacement
@ -6,7 +6,7 @@
# Copyright 2010
# Nathan Osman
#
#=========================
# =========================
# We require PyGTK
import gtk
@ -29,7 +29,9 @@ STATUS_ATTENTION = 1
def get_icon_filename(icon_name):
# Determine where the icon is
return os.path.abspath(resource_filename('hackertray.data', 'hacker-tray.png'))
return os.path.abspath(
resource_filename('hackertray.data', 'hacker-tray.png')
)
# The main class

View File

@ -4,8 +4,10 @@ import shutil
import os
import sys
class Chrome:
HISTORY_TMP_LOCATION = '/tmp/hackertray.chrome'
@staticmethod
def search(urls, config_folder_path):
Chrome.setup(config_folder_path)
@ -13,17 +15,19 @@ class Chrome:
db = conn.cursor()
result = []
for url in urls:
db_result = db.execute('SELECT url from urls WHERE url=:url',{"url":url})
if(db.fetchone() == None):
# db_result = db.execute(
# 'SELECT url from urls WHERE url=:url',{"url":url})
if db.fetchone() is None:
result.append(False)
else:
result.append(True)
os.remove(Chrome.HISTORY_TMP_LOCATION)
return result
@staticmethod
def setup(config_folder_path):
file_name = os.path.abspath(config_folder_path+'/History')
file_name = os.path.abspath(config_folder_path + '/History')
if not os.path.isfile(file_name):
print("ERROR: ", "Could not find Chrome history file", file=sys.stderr)
print("ERROR: ", "Could not find Chrome history file",file=sys.stderr)
sys.exit(1)
shutil.copyfile(file_name, Chrome.HISTORY_TMP_LOCATION)

View File

@ -4,9 +4,11 @@ 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)
@ -14,17 +16,20 @@ class Firefox:
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):
# db_result = db.execute(
# 'SELECT url from moz_places WHERE url=:url',{"url":url})
if db.fetchone() is 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)
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)
shutil.copyfile(file_name, Firefox.HISTORY_TMP_LOCATION)

View File

@ -15,4 +15,4 @@ class HackerNews:
try:
return r.json()
except ValueError:
continue
continue

View File

@ -1,8 +1,10 @@
import requests
import pkg_resources
class Version:
PYPI_URL = "https://pypi.python.org/pypi/hackertray/json"
@staticmethod
def latest():
res = requests.get(Version.PYPI_URL).json()
@ -14,14 +16,16 @@ class Version:
@staticmethod
def new_available():
latest = Version.latest()
latest = Version.latest()
current = Version.current()
try:
if pkg_resources.parse_version(latest) > pkg_resources.parse_version(current):
print "[+] New version " + latest + " is available"
print("[+] New version " + latest + " is available")
return True
else:
return False
except requests.exceptions.RequestException as e:
print "[+] There was an error in trying to fetch updates"
return False
print("[+] There was an error in trying to fetch updates")
return False