From e4599c28663b94940942b7cee278ad113f0522a1 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 18 Jul 2016 21:37:14 -0400 Subject: [PATCH] Get everything nice for heroku --- Procfile | 1 + README.md | 10 +++-- default_conf.yaml | 20 ++++++++++ elektricity/.server.py.swp | Bin 0 -> 12288 bytes {src => elektricity}/__init__.py | 0 elektricity/conf_parser.py | 30 ++++++++++++++ {src => elektricity}/podcasters/__init__.py | 0 {src => elektricity}/podcasters/base.py | 0 {src => elektricity}/podcasters/bassdrive.py | 0 {src => elektricity}/server.py | 20 +++++----- {src => elektricity}/tests/__init__.py | 0 example_conf.yaml | 15 ------- requirements.txt | 1 + runtime.txt | 1 + src/conf_parser.py | 40 ------------------- 15 files changed, 70 insertions(+), 68 deletions(-) create mode 100644 Procfile create mode 100644 default_conf.yaml create mode 100644 elektricity/.server.py.swp rename {src => elektricity}/__init__.py (100%) create mode 100755 elektricity/conf_parser.py rename {src => elektricity}/podcasters/__init__.py (100%) rename {src => elektricity}/podcasters/base.py (100%) rename {src => elektricity}/podcasters/bassdrive.py (100%) rename {src => elektricity}/server.py (74%) rename {src => elektricity}/tests/__init__.py (100%) delete mode 100644 example_conf.yaml create mode 100644 runtime.txt delete mode 100644 src/conf_parser.py diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..3d9e57b --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python elektricity/server.py diff --git a/README.md b/README.md index 0fe2030..6bcc1c1 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ -# Repod +# Elektricity A server designed to make it easy to re-broadcast existing content -as a podcast. +as a podcast. Named after [London Elektricity][1] who, among other +things, hosts the [Hospital Podcast][2]. --- -The purpose of Repod is to take content that exists on the web already, +The purpose of Elektricity is to take content that exists on the web already, and turn it into a podcast to consume whenever you want. Specifically, I'm a huge Drum & Bass head that wanted an easy way to access [the Bassdrive archives](http://archives.bassdrivearchive.com/) since @@ -19,3 +20,6 @@ Future ideas: Turn your mixcloud feed into a podcast? Repod is currently very bare-bones, but the Requirements file should be enough to get up and running. + +[1]: https://www.youtube.com/watch?v=6IRiuLy0IW4 +[2]: https://www.hospitalrecords.com/podcast/ diff --git a/default_conf.yaml b/default_conf.yaml new file mode 100644 index 0000000..bcf7512 --- /dev/null +++ b/default_conf.yaml @@ -0,0 +1,20 @@ +# Format (all args are passed to __init__ as kwargs: +# +# : +# class: +# args: +# key: value + +subfactory-show: + package: bassdrive + class: BassdriveFeed + args: + url: http://archives.bassdrivearchive.com/1%20-%20Monday/Subfactory%20Show%20-%20DJ%20Spim/ + logo: http://www.bassdrive.com/img/radio_schedule_entries/image/original/subfactory-web-add-56.jpg + +electronic-warfare: + package: bassdrive + class: BassdriveFeed + args: + url: http://archives.bassdrivearchive.com/6%20-%20Saturday/Electronic%20Warfare%20-%20The%20Overfiend/ + logo: http://bassdrive.com/img/radio_schedule_entries/image/original/front-page-intro-box-200x200-115.jpg diff --git a/elektricity/.server.py.swp b/elektricity/.server.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..ce33a28115883ff6196bf9b425c107278feeacd1 GIT binary patch literal 12288 zcmeHNO>Z1E71{R1^?YmF1oB?oKl^9z5PO ztE%MyT&Otp$`!$h0}}iKI3e}Qk$X>^;Q){Ancdltw1E>v_Uege?04Re=Y8$jXx&?W z@6r{z8oo);UL@qtPri6Re&WH&uU;plR~90PgqeA0tK>Q#o?Go~yt{JoDB(Mm;L?WJ z6R9jRk?SRqie0UeDAD7Y>r$vap~7N(lr}%^8So4on}Lz;cg~$AD{q`#HqR`~&(T+2 z-Z}Q;UeGh(8So5v20R0v0ndPEz%$?(c>EdA#R>8;!Z=xlvQqUY4)oQn?>qyZ0ndPE zz%$?(@Cn}tAzwaC$fwW1dHnug|NsBn8A5&qz6Qp?KClhE z11tdZz#Q<$3xs?J+yy=dc7e;lJTM151w08nI8Dg+zztv>I0f8)o{)RM7H|f*{~RHo z0q21(@EY(EaQ|6CegN(P9{~ek6?hf+`0CxcnYy!U{mY;!d0Tb6xi0?8j|JKtg#?~aFNap=yFj8D6GH*ofEY9!byq5~9 zB`vrr1)UM6{UjA3y;Ra$w<)K4JWXQy!IjH){H=Ln;sKeW(DZ`FX~y12i?@}MYL>tM zKydvej}MJ)Lkb(6*iTA58`36%-;#P$j`H|GRHf!hGj~?Aw>?Qk@cv3Ph6 zDoL=i4`Fv_ z%-CX#cDpoSEaOSeSg_{m*fA5@j^PD?Gup;&>$jVO&l%qp^>VjMk(!i%n4)kInnB39 z2ker&=GO3atH?+noVH25?hHW>rl&#Xs+ZNTst3RiS0)ZYkkvfw{0z9HMnAG U)4G~Sr3zmM+?&51sLPc61s(O<8UO$Q literal 0 HcmV?d00001 diff --git a/src/__init__.py b/elektricity/__init__.py similarity index 100% rename from src/__init__.py rename to elektricity/__init__.py diff --git a/elektricity/conf_parser.py b/elektricity/conf_parser.py new file mode 100755 index 0000000..37d6e20 --- /dev/null +++ b/elektricity/conf_parser.py @@ -0,0 +1,30 @@ +""" +Given a configuration file, set up everything needed to kick +off the server. +""" +from importlib import import_module +import yaml +from pyramid.config import Configurator +from os.path import expanduser, join + +# Needed for import_module call +# noinspection PyUnresolvedReferences +import podcasters + + +def build_configuration(conf=None) -> Configurator: + if conf is None: + conf = join(expanduser('~'), '.repodrc') + + server_conf = Configurator() + with open(conf) as conf_file: + conf_dict = yaml.load(conf_file) + for mountpoint, feed in conf_dict.items(): + feed_package = import_module('podcasters.' + feed['package']) + feed_class = getattr(feed_package, feed['class']) + feed_instance = feed_class(**feed['args']) + + server_conf.add_route(mountpoint, '/' + mountpoint + '/') + server_conf.add_view(feed_instance.view, route_name=mountpoint) + + return server_conf diff --git a/src/podcasters/__init__.py b/elektricity/podcasters/__init__.py similarity index 100% rename from src/podcasters/__init__.py rename to elektricity/podcasters/__init__.py diff --git a/src/podcasters/base.py b/elektricity/podcasters/base.py similarity index 100% rename from src/podcasters/base.py rename to elektricity/podcasters/base.py diff --git a/src/podcasters/bassdrive.py b/elektricity/podcasters/bassdrive.py similarity index 100% rename from src/podcasters/bassdrive.py rename to elektricity/podcasters/bassdrive.py diff --git a/src/server.py b/elektricity/server.py similarity index 74% rename from src/server.py rename to elektricity/server.py index 94f44ac..6f38e7e 100644 --- a/src/server.py +++ b/elektricity/server.py @@ -1,6 +1,6 @@ import argparse import traceback -from os.path import expanduser, join +from os.path import expanduser, join, dirname, realpath from wsgiref.simple_server import make_server from pyramid.config import Configurator @@ -12,14 +12,15 @@ from conf_parser import build_configuration def start_server(server_conf: dict, configurator: Configurator) -> None: app = configurator.make_wsgi_app() - port = server_conf['port'] if 'port' in server_conf else cmd_args.port - host = server_conf['host'] if 'host' in server_conf else cmd_args.host + port = server_conf['port'] + host = server_conf['host'] server = make_server(host, port, app) server.serve_forever() if __name__ == '__main__': - default_rc = join(expanduser('~'), '.repodrc') + # default_rc = join(expanduser('~'), '.repodrc') + default_rc = join(dirname(realpath(__file__)), '../default_conf.yaml') parser = argparse.ArgumentParser() parser.add_argument('--verbose', action='store_true', help='Run server in verbose mode') @@ -32,7 +33,11 @@ if __name__ == '__main__': cmd_args = parser.parse_args() try: - server_conf, configurator = build_configuration(cmd_args.configuration) + configurator = build_configuration(cmd_args.configuration) + server_conf = { + 'host': cmd_args.host, + 'port': cmd_args.port + } start_server(server_conf, configurator) except FileNotFoundError: print("Unable to find configuration file. Does {} exist?" @@ -44,8 +49,3 @@ if __name__ == '__main__': .format(cmd_args.configuration)) if cmd_args.verbose: print(traceback.format_exc()) - except KeyError: - print('Unable to parse configuration file. Is there a `podcasts` ' - 'section?') - if cmd_args.verbose: - print(traceback.format_exc()) diff --git a/src/tests/__init__.py b/elektricity/tests/__init__.py similarity index 100% rename from src/tests/__init__.py rename to elektricity/tests/__init__.py diff --git a/example_conf.yaml b/example_conf.yaml deleted file mode 100644 index b520c75..0000000 --- a/example_conf.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# Format (all args are passed to __init__ as kwargs: -# -# : -# class: -# args: -# key: value -server: - port: 10000 - -podcasts: - subfactory-show: - class: podcasters.BassdriveFeed - args: - url: http://archives.bassdrivearchive.com/1%20-%20Monday/Subfactory%20Show%20-%20DJ%20Spim/ - logo: http://www.bassdrive.com/img/radio_schedule_entries/image/original/subfactory-web-add-56.jpg diff --git a/requirements.txt b/requirements.txt index 5477442..2b2e8d2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +python>=3.5.0 pyramid>=1.6.1 feedgen>=0.3.2 PyYAML>=3.11 diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..c0354ee --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.5.2 diff --git a/src/conf_parser.py b/src/conf_parser.py deleted file mode 100644 index 9233940..0000000 --- a/src/conf_parser.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -Given a configuration file, set up everything needed to kick -off the server. -""" -from importlib import import_module - -import yaml -from pyramid.config import Configurator - - -def build_configurator(podcasts: dict) -> Configurator: - server_conf = Configurator() - for mountpoint, feed in podcasts.items(): - package, class_name = feed['class'].rsplit('.', 1) - feed_package = import_module(package) - feed_class = getattr(feed_package, class_name) - feed_instance = feed_class(**feed) - - server_conf.add_route(mountpoint, '/' + mountpoint + '/') - server_conf.add_view(feed_instance.view, route_name=mountpoint) - - return server_conf - - -def build_configuration_text(file_str: str) -> (dict, Configurator): - conf_dict = yaml.load(file_str) - - server_opts = conf_dict.get('server', None) - podcasts = build_configurator(conf_dict['podcasts']) - return server_opts, podcasts - - -def build_configuration(file_name) -> (dict, Configurator): - try: - with open(file_name) as conf_file: - return build_configuration_text(conf_file.read()) - except FileNotFoundError: - print("Could not locate configuration file " + - "(does {} exist?)".format(file_name)) - raise