Skip to content

Commit

Permalink
code cleanup, add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzy69 committed May 14, 2017
1 parent 3cd08e5 commit e527417
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion application/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0",
"Accept-Language": "en-US,en;q=0.5",
}
}
2 changes: 1 addition & 1 deletion application/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

THREADS = 1
TIMEOUT = 5
DELAY = 1
DELAY = 1
2 changes: 1 addition & 1 deletion application/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def readTextFile(filePath):
return ts.readAll()

def writeTextFile(filePath, fileContents):
pass
pass
49 changes: 44 additions & 5 deletions application/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: UTF-8 -*-
#!/usr/bin/env python

from time import sleep
from urllib.parse import urljoin, urlparse
#from time import sleep
from urllib.parse import urlparse

from lxml import etree
import requests

from .conf import HEADERS
from .defaults import TIMEOUT
from application.conf import HEADERS
from application.defaults import TIMEOUT

def check_alexa(url, timeout=TIMEOUT):
rank = None
Expand All @@ -34,9 +34,48 @@ def check_alexa(url, timeout=TIMEOUT):
return rank, status, msg

def extract_domain(url):
"""
Extracts domain from url
Parameters
----------
url : str
Full url address
Returns
-------
str
Url domain
Examples
--------
>>> extract_domain("https://www.python.org/about/")
'www.python.org'
"""
return urlparse(url).netloc

def split_list(li, n):
"""
Split list into n lists
Parameters
----------
li : list
List to split
n : int
Split count
Returns
-------
list
List of n lists
Examples
--------
>>> split_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)
[[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]
"""
k, m = divmod(len(li), n)

return (li[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n))
return [li[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n)]
2 changes: 1 addition & 1 deletion application/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: UTF-8 -*-
# !/usr/bin/env python

__version__ = "0.5.12.1"
__version__ = "0.5.12.1"
5 changes: 2 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# -*- coding: UTF-8 -*-
# !/usr/bin/env python

import os
import sys

from PyQt5 import uic, QtWidgets
from PyQt5 import QtWidgets

from application.mainwindow import MainWindow
from application.conf import __author__, __title__
Expand All @@ -18,4 +17,4 @@
app.setStyleSheet("QStatusBar::item { border: 0px solid black };")
mainWindow = MainWindow()
mainWindow.show()
app.exec_()
app.exec_()

0 comments on commit e527417

Please sign in to comment.