Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	main.py
  • Loading branch information
tgorgdotcom committed Sep 16, 2020
2 parents 13bd420 + 8d080f7 commit 8c48346
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 155 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## 0.6.0 (unreleased)
- Switch to Python 3 (Thanks @ratherDashing!)
- Scripts are now fully linted (Thanks @deathbybandaid!)
- Added all the market codes/FCC names so we don't have to add them when Locast enables them (Thanks @deathbybandaid!)

## 0.5.3
- Scripts are now fully linted (Thanks @deathbybandaid!)
- Updated Readme for spelling/clarity/credits (Thanks @tri-ler and @gogorichie!)
- Added ability to place config in /app/config folder for Kubernetes users (Thanks @dcd!)
- Added Detroit DMA support (Thanks @precision!)
Expand Down
146 changes: 75 additions & 71 deletions LocastService.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SSDPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,4 @@ def do_byebye(self, usn):
except (AttributeError, socket.error) as msg:
logger.error("failure sending out byebye notification: %r" % msg)
except KeyError as msg:
logger.error("error building byebye notification: %r" % msg)
logger.error("error building byebye notification: %r" % msg)
27 changes: 16 additions & 11 deletions fcc_facility/get_facilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import urllib, zipfile, os, sys, datetime, json
import urllib
import zipfile
import os
import sys
import datetime
import json

os.chdir(os.path.dirname(sys.argv[0]))

Expand Down Expand Up @@ -32,17 +37,17 @@

if fac_line_split[12] != '':
fac_status_date_split = fac_line_split[12].split('/')

if fac_line_split[15] != '':
fac_lic_expiration_date_split = fac_line_split[15].split('/')
fac_lic_expiration_date_datetime = datetime.datetime(int(fac_lic_expiration_date_split[2]),
int(fac_lic_expiration_date_split[0]),
int(fac_lic_expiration_date_split[1]),
fac_lic_expiration_date_datetime = datetime.datetime(int(fac_lic_expiration_date_split[2]),
int(fac_lic_expiration_date_split[0]),
int(fac_lic_expiration_date_split[1]),
23, 59, 59, 999999)

if fac_line_split[21] != '':
fac_callsign_eff_date_split = fac_line_split[21].split('/')

if fac_line_split[29] != '':
fac_last_change_date_split = fac_line_split[29].split('/')

Expand Down Expand Up @@ -79,9 +84,9 @@
"last_change_date": fac_line_split[29]
}

if ((fac_obj['fac_status'] == 'LICEN')
and (fac_lic_expiration_date_datetime != None)
and (fac_lic_expiration_date_datetime > current_date)
if ((fac_obj['fac_status'] == 'LICEN')
and (fac_lic_expiration_date_datetime is not None)
and (fac_lic_expiration_date_datetime > current_date)
and (fac_obj['fac_service'] in ('DT', 'TX', 'TV', 'TB', 'LD', 'DC'))):
sys.stdout.write(fac_obj['fac_callsign'] + '.')
sys.stdout.flush()
Expand All @@ -105,4 +110,4 @@
tv_dma_file.write("%s\n" % dma_list_item)

print('Complete!')
print('Found ' + str(fac_found_count) + ' items.')
print('Found ' + str(fac_found_count) + ' items.')
12 changes: 6 additions & 6 deletions m3u8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

try:
from urllib.request import urlopen, Request
from urllib.error import HTTPError
from urllib.parse import urlparse, urljoin
except ImportError: # Python 2.x
from urllib2 import urlopen, Request, HTTPError
from urllib2 import urlopen, Request
from urlparse import urlparse, urljoin

from m3u8.model import (M3U8, Segment, SegmentList, PartialSegment,
Expand All @@ -26,10 +25,11 @@
PYTHON_MAJOR_VERSION = sys.version_info

__all__ = ('M3U8', 'Segment', 'SegmentList', 'PartialSegment',
'PartialSegmentList', 'Key', 'Playlist', 'IFramePlaylist',
'Media', 'MediaList', 'PlaylistList', 'Start', 'RenditionReport',
'RenditionReportList', 'ServerControl', 'Skip', 'PartInformation',
'loads', 'load', 'parse', 'ParseError')
'PartialSegmentList', 'Key', 'Playlist', 'IFramePlaylist',
'Media', 'MediaList', 'PlaylistList', 'Start', 'RenditionReport',
'RenditionReportList', 'ServerControl', 'Skip', 'PartInformation',
'loads', 'load', 'parse', 'ParseError')


def loads(content, uri=None, custom_tags_parser=None):
'''
Expand Down
1 change: 1 addition & 0 deletions m3u8/iso8601/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# pylama:ignore=W0401,W0611
from .iso8601 import *
14 changes: 9 additions & 5 deletions m3u8/iso8601/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
__all__ = ["parse_date", "ParseError", "UTC",
"FixedOffset"]

if sys.version_info >= (3, 0, 0):
_basestring = str
else:
_basestring = basestring
if sys.version_info.major >= 3:
basestring = str


# Adapted from http://delete.me.uk/2005/03/iso8601.html
Expand Down Expand Up @@ -67,11 +65,14 @@
re.VERBOSE
)


class ParseError(Exception):
"""Raised when there is a problem parsing a date string"""


if sys.version_info >= (3, 2, 0):
UTC = datetime.timezone.utc

def FixedOffset(offset_hours, offset_minutes, name):
return datetime.timezone(
datetime.timedelta(
Expand All @@ -80,6 +81,7 @@ def FixedOffset(offset_hours, offset_minutes, name):
else:
# Yoinked from python docs
ZERO = datetime.timedelta(0)

class Utc(datetime.tzinfo):
"""UTC Timezone
Expand Down Expand Up @@ -150,6 +152,7 @@ def to_int(d, key, default_to_zero=False, default=None, required=True):
else:
return int(value)


def parse_timezone(matches, default_timezone=UTC):
"""Parses ISO 8601 time zone specs into tzinfo offsets
Expand All @@ -171,6 +174,7 @@ def parse_timezone(matches, default_timezone=UTC):
minutes = -minutes
return FixedOffset(hours, minutes, description)


def parse_date(datestring, default_timezone=UTC):
"""Parses ISO 8601 dates into datetime objects
Expand All @@ -188,7 +192,7 @@ def parse_date(datestring, default_timezone=UTC):
constructing the datetime instance.
"""
if not isinstance(datestring, _basestring):
if not isinstance(datestring, basestring):
raise ParseError("Expecting a string %r" % datestring)
m = ISO8601_REGEX.match(datestring)
if not m:
Expand Down
6 changes: 6 additions & 0 deletions m3u8/iso8601/test_iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@

from iso8601 import iso8601


def test_iso8601_regex():
assert iso8601.ISO8601_REGEX.match("2006-10-11T00:14:33Z")


def test_fixedoffset_eq():
# See https://bitbucket.org/micktwomey/pyiso8601/issues/19
datetime.tzinfo() == iso8601.FixedOffset(2, 0, '+2:00')


def test_parse_no_timezone_different_default():
tz = iso8601.FixedOffset(2, 0, "test offset")
d = iso8601.parse_date("2007-01-01T08:00:00", default_timezone=tz)
assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, tz)
assert d.tzinfo == tz


def test_parse_utc_different_default():
"""Z should mean 'UTC', not 'default'.
Expand All @@ -30,6 +34,7 @@ def test_parse_utc_different_default():
d = iso8601.parse_date("2007-01-01T08:00:00Z", default_timezone=tz)
assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, iso8601.UTC)


@pytest.mark.parametrize("invalid_date, error_string", [
("2013-10-", "Unable to parse date string"),
("2013-", "Unable to parse date string"),
Expand All @@ -52,6 +57,7 @@ def test_parse_invalid_date(invalid_date, error_string):
assert exc.errisinstance(iso8601.ParseError)
assert str(exc.value).startswith(error_string)


@pytest.mark.parametrize("valid_date,expected_datetime,isoformat", [
("2007-06-23 06:40:34.00Z", datetime.datetime(2007, 6, 23, 6, 40, 34, 0, iso8601.UTC), "2007-06-23T06:40:34+00:00"), # Handle a separator other than T
("1997-07-16T19:20+01:00", datetime.datetime(1997, 7, 16, 19, 20, 0, 0, iso8601.FixedOffset(1, 0, "+01:00")), "1997-07-16T19:20:00+01:00"), # Parse with no seconds
Expand Down
1 change: 0 additions & 1 deletion m3u8/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import os
from m3u8.parser import is_url

Expand Down
Loading

0 comments on commit 8c48346

Please sign in to comment.