Get everything nice for heroku

This commit is contained in:
Bradlee Speice 2016-07-18 21:37:14 -04:00
parent 2cdf45cd01
commit e4599c2866
15 changed files with 70 additions and 68 deletions

1
Procfile Normal file
View File

@ -0,0 +1 @@
web: python elektricity/server.py

View File

@ -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/

20
default_conf.yaml Normal file
View File

@ -0,0 +1,20 @@
# Format (all args are passed to __init__ as kwargs:
#
# <mountpoint>:
# class: <feed_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

BIN
elektricity/.server.py.swp Normal file

Binary file not shown.

30
elektricity/conf_parser.py Executable file
View File

@ -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

View File

@ -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())

View File

@ -1,15 +0,0 @@
# Format (all args are passed to __init__ as kwargs:
#
# <mountpoint>:
# class: <feed_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

View File

@ -1,3 +1,4 @@
python>=3.5.0
pyramid>=1.6.1
feedgen>=0.3.2
PyYAML>=3.11

1
runtime.txt Normal file
View File

@ -0,0 +1 @@
python-3.5.2

View File

@ -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