Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lepinkainen committed Nov 4, 2016
1 parent 9ccc688 commit 51d18a9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pyfibot/modules/module_urltitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import urlparse
import logging
import re
import math
from datetime import datetime, timedelta
from types import TupleType
from dateutil.tz import tzutc
from dateutil.parser import parse as parse_datetime
import math

from types import TupleType

from repoze.lru import ExpiringLRUCache

Expand All @@ -36,6 +35,8 @@


def init(botref):
"""Initialize the urltitle module"""

global config
global bot
global handlers
Expand All @@ -58,12 +59,12 @@ def __get_bs(url):

duration = (end - start).seconds
if duration > TITLE_LAG_MAXIMUM:
log.error("Fetching title took %d seconds, not displaying title" % duration)
log.error("Fetching title took %d seconds, not displaying title", duration)
return None

content_type = r.headers['content-type'].split(';')[0]
if content_type not in ['text/html', 'text/xml', 'application/xhtml+xml']:
log.debug("Content-type %s not parseable" % content_type)
log.debug("Content-type %s not parseable", content_type)
return None

if r.content:
Expand All @@ -87,6 +88,8 @@ def __get_title_tag(url):


def __get_length_str(secs):
"""Convert seconds to human readable string"""

lengthstr = []
hours, minutes, seconds = secs // 3600, secs // 60 % 60, secs % 60
if hours > 0:
Expand All @@ -101,6 +104,8 @@ def __get_length_str(secs):


def __get_age_str(published, use_fresh=True):
"""Convert delta time to human readable format"""

now = datetime.now(tz=published.tzinfo)

# Check if the publish date is in the future (upcoming episode)
Expand Down Expand Up @@ -141,6 +146,8 @@ def __get_age_str(published, use_fresh=True):


def __get_views(views):
"""Convert viewcount to human readable format"""

if int(views) == 0:
return '0'
millnames = ['', 'k', 'M', 'Billion', 'Trillion']
Expand Down

0 comments on commit 51d18a9

Please sign in to comment.