pep8 changes

This commit is contained in:
Nemo 2017-12-24 18:55:20 +05:30
parent e34d767ef0
commit 3afba6f3eb
7 changed files with 43 additions and 28 deletions

View File

@ -31,11 +31,13 @@ from .firefox import Firefox
from .version import Version from .version import Version
from .analytics import Analytics from .analytics import Analytics
class HackerNewsApp: class HackerNewsApp:
HN_URL_PREFIX = "https://news.ycombinator.com/item?id=" HN_URL_PREFIX = "https://news.ycombinator.com/item?id="
UPDATE_URL = "https://github.com/captn3m0/hackertray#upgrade" UPDATE_URL = "https://github.com/captn3m0/hackertray#upgrade"
ABOUT_URL = "https://github.com/captn3m0/hackertray" ABOUT_URL = "https://github.com/captn3m0/hackertray"
MIXPANEL_TOKEN = "51a04e37dad59393c7371407e84a8050" MIXPANEL_TOKEN = "51a04e37dad59393c7371407e84a8050"
def __init__(self, args): def __init__(self, args):
# Load the database # Load the database
home = expanduser("~") home = expanduser("~")
@ -122,7 +124,6 @@ class HackerNewsApp:
self.menu.remove(widget) self.menu.remove(widget)
self.tracker.visit(HackerNewsApp.UPDATE_URL) self.tracker.visit(HackerNewsApp.UPDATE_URL)
def showAbout(self, widget): def showAbout(self, widget):
"""Handle the about btn""" """Handle the about btn"""
webbrowser.open(HackerNewsApp.ABOUT_URL) webbrowser.open(HackerNewsApp.ABOUT_URL)
@ -184,7 +185,6 @@ class HackerNewsApp:
i.show() i.show()
def refresh(self, widget=None, no_timer=False, chrome_data_directory=None, firefox_data_directory=None): def refresh(self, widget=None, no_timer=False, chrome_data_directory=None, firefox_data_directory=None):
"""Refreshes the menu """ """Refreshes the menu """
try: try:
# Create an array of 20 false to denote matches in History # Create an array of 20 false to denote matches in History
@ -223,6 +223,7 @@ class HackerNewsApp:
original[index] = original[index] or patch[index] original[index] = original[index] or patch[index]
return original return original
def main(): def main():
parser = argparse.ArgumentParser(description='Hacker News in your System Tray') parser = argparse.ArgumentParser(description='Hacker News in your System Tray')
parser.add_argument('-v', '--version', action='version', version=Version.current()) parser.add_argument('-v', '--version', action='version', version=Version.current())

View File

@ -1,9 +1,11 @@
from mixpanel import Mixpanel from mixpanel import Mixpanel
class Analytics: class Analytics:
# Setup analytics. # Setup analytics.
# dnt - do not track. Disables tracking if True # dnt - do not track. Disables tracking if True
# token - The mixpanel token # token - The mixpanel token
def __init__(self, dnt, token): def __init__(self, dnt, token):
self.dnt = dnt self.dnt = dnt
self.tracker = Mixpanel(token) self.tracker = Mixpanel(token)
@ -12,6 +14,7 @@ class Analytics:
# Track an event # Track an event
# event - string containing the event name # event - string containing the event name
# data - data related to the event, defaults to {} # data - data related to the event, defaults to {}
def track(self, event, data={}): def track(self, event, data={}):
if(self.dnt == False): if(self.dnt == False):
# All events are tracked anonymously # All events are tracked anonymously
@ -19,5 +22,6 @@ class Analytics:
# Track a visit to a URL # 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 # some meta-url pertaining to hackertray
def visit(self, url): def visit(self, url):
self.track('visit', {"link": url}) self.track('visit', {"link": url})

View File

@ -35,6 +35,7 @@ def get_icon_filename(icon_name):
# The main class # The main class
class Indicator: class Indicator:
# Constructor # Constructor
def __init__(self, unknown, icon, category): def __init__(self, unknown, icon, category):
# Store the settings # Store the settings
self.inactive_icon = get_icon_filename(icon) self.inactive_icon = get_icon_filename(icon)

View File

@ -4,8 +4,10 @@ import shutil
import os import os
import sys import sys
class Chrome: class Chrome:
HISTORY_TMP_LOCATION = '/tmp/hackertray.chrome' HISTORY_TMP_LOCATION = '/tmp/hackertray.chrome'
@staticmethod @staticmethod
def search(urls, config_folder_path): def search(urls, config_folder_path):
Chrome.setup(config_folder_path) Chrome.setup(config_folder_path)
@ -20,6 +22,7 @@ class Chrome:
result.append(True) result.append(True)
os.remove(Chrome.HISTORY_TMP_LOCATION) os.remove(Chrome.HISTORY_TMP_LOCATION)
return result return result
@staticmethod @staticmethod
def setup(config_folder_path): def setup(config_folder_path):
file_name = os.path.abspath(config_folder_path+'/History') file_name = os.path.abspath(config_folder_path+'/History')

View File

@ -4,9 +4,11 @@ import shutil
import os import os
import sys import sys
class Firefox: class Firefox:
HISTORY_TMP_LOCATION = '/tmp/hackertray.firefox' HISTORY_TMP_LOCATION = '/tmp/hackertray.firefox'
HISTORY_FILE_NAME = '/places.sqlite' HISTORY_FILE_NAME = '/places.sqlite'
@staticmethod @staticmethod
def search(urls, config_folder_path): def search(urls, config_folder_path):
Firefox.setup(config_folder_path) Firefox.setup(config_folder_path)
@ -21,6 +23,7 @@ class Firefox:
result.append(True) result.append(True)
os.remove(Firefox.HISTORY_TMP_LOCATION) os.remove(Firefox.HISTORY_TMP_LOCATION)
return result return result
@staticmethod @staticmethod
def setup(config_folder_path): 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)

View File

@ -7,6 +7,7 @@ urls = [
class HackerNews: class HackerNews:
@staticmethod @staticmethod
def getHomePage(): def getHomePage():
random.shuffle(urls) random.shuffle(urls)

View File

@ -1,8 +1,10 @@
import requests import requests
import pkg_resources import pkg_resources
class Version: class Version:
PYPI_URL = "https://pypi.python.org/pypi/hackertray/json" PYPI_URL = "https://pypi.python.org/pypi/hackertray/json"
@staticmethod @staticmethod
def latest(): def latest():
res = requests.get(Version.PYPI_URL).json() res = requests.get(Version.PYPI_URL).json()