Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tweaks to the setup

- Use the open context manager
- Docstrings are good
- make your functions generators and yield results so that it's not view +
controller type functionality
- Add a basic setup.py so you can python setup.py develop or better yet,
    python setup.py register && python setup.py sdist upload
- Adds a command omcnotes once package is installed
- Should add in some README, etc. but hey, I should be in bed.
  • Loading branch information...
commit 8dc975de7fde712f6259adcfdfcddc203370b9d8 1 parent 93a7e87
@mitechie mitechie authored
View
38 setup.py
@@ -0,0 +1,38 @@
+from setuptools import setup, find_packages
+import sys, os
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+version = '0.1'
+install_requires = ['BeautifulSoup']
+
+if sys.version_info < (2,7):
+ install_requires.append('argparse')
+elif sys.version_info >= (3,0) and sys.version_info < (3,2):
+ install_requires.append('argparse')
+
+tests_require = ['nose']
+
+setup(name='omcnotes',
+ version=version,
+ description="Build the show notes for OMC",
+ long_description="",
+ classifiers=[
+ # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ ],
+ keywords='podcast shownotes',
+ author='Craig Maloney',
+ author_email='something',
+ url='http://openmetalcast.com/',
+ license='BSD',
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},include_package_data=True,
+ zip_safe=False,
+ install_requires=install_requires,
+ tests_require=tests_require,
+ entry_points={
+ 'console_scripts':
+ ['omcnotes=shownotes:main']
+ }
+)
+
View
82 shownotes.py
@@ -1,82 +0,0 @@
-#!/usr/bin/env python
-import json
-import argparse
-import datetime
-from BeautifulSoup import BeautifulStoneSoup
-
-class ShowNotes(object):
- def __init__(self,filename):
- self.file = open(filename, 'rt')
- self.playlist = json.load(self.file)
- self.file.close
- self.song_template = """<li>({time}) <a href="{url}">{title} by {artist} from {album}</a> ({license})</li>"""
- self.announcements = {
- "first":"That was {title} by {artist} from {album}.",
- "second":"Before that, {title} by {artist} from {album}.",
- "middle":"{title} by {artist} from {album}.",
- "last":"And starting off the show. {title} by {artist} from the album {album}."
- }
- self.aud_timing = {}
-
- def find_timing(self, audacity_file):
- aup_file = open(audacity_file, 'rt')
- bs = BeautifulStoneSoup(aup_file)
- tracks = bs.findAll('wavetrack')
- for track in tracks:
- wavestart = track.findAll('waveclip')
- secs = int(float(wavestart[0]['offset']))
- timestamp = str(datetime.timedelta(seconds=secs))
- self.aud_timing[track['name']] = timestamp
-
- def create_shownotes(self):
- for i in self.playlist:
- tmp_timing = self.aud_timing[i['audacity']]
- hour, minute, second = tmp_timing.split(':')
- if int(hour) > 0:
- i['time'] = '{}:{}:{}'.format(hour, minute, second)
- else:
- i['time'] = '{}:{}'.format(minute, second)
-
- print self.song_template.format(**i)
-
- def create_announcement(self):
- num_tracks = 0
- self.playlist.reverse()
- for i in self.playlist:
- num_tracks = num_tracks + 1
- position = 'middle'
- if num_tracks == 1:
- position = 'first'
- elif num_tracks == 2:
- position = 'second'
- elif num_tracks == len(self.playlist):
- position = 'last'
- print self.announcements[position].format(**i)
- self.playlist.reverse()
-
-def configure():
- parser = argparse.ArgumentParser(description='Shownotes Application')
- parser.add_argument('--audacity', '-a',
- action='store',
- required=True,
- help='audacity file')
- parser.add_argument('--json', '-j',
- action='store',
- required=True,
- help='json playlist file')
-
- args = parser.parse_args()
-
- return args
-
-def main():
- args = configure()
- print args
- show = ShowNotes(args.json)
- show.find_timing(args.audacity)
- show.create_shownotes()
- show.create_announcement()
-
-if __name__ == '__main__':
- main()
-
View
0  src/__init__.py
No changes.
View
92 src/shownotes.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+import argparse
+import datetime
+import json
+from BeautifulSoup import BeautifulStoneSoup
+
+
+class ShowNotes(object):
+ song_template = """<li>({time}) <a href="{url}">{title} by {artist} from {album}</a> ({license})</li>"""
+ announcements = {
+ "first":"That was {title} by {artist} from {album}.",
+ "second":"Before that, {title} by {artist} from {album}.",
+ "middle":"{title} by {artist} from {album}.",
+ "last":"And starting off the show. {title} by {artist} from the album {album}."
+ }
+
+ def __init__(self, filename, audacity_file):
+ """Docstrings!!!!!
+
+ wtf is aud_timing?
+
+ """
+ with open(filename, 'rt') as f:
+ self.playlist = json.load(f)
+ self.aud_timing = {}
+ self.find_timing(audacity_file)
+
+ def find_timing(self, audacity_file):
+ with open(audacity_file, 'rt') as aup_file:
+ bs = BeautifulStoneSoup(aup_file)
+ tracks = bs.findAll('wavetrack')
+ for track in tracks:
+ wavestart = track.findAll('waveclip')
+ secs = int(float(wavestart[0]['offset']))
+ timestamp = str(datetime.timedelta(seconds=secs))
+ self.aud_timing[track['name']] = timestamp
+
+ def create_shownotes(self):
+ for i in self.playlist:
+ tmp_timing = self.aud_timing[i['audacity']]
+ hour, minute, second = tmp_timing.split(':')
+ if int(hour) > 0:
+ i['time'] = '{}:{}:{}'.format(hour, minute, second)
+ else:
+ i['time'] = '{}:{}'.format(minute, second)
+
+ yield self.song_template.format(**i)
+
+ def create_announcement(self):
+ """I wouldn't print from here. What if you want to log, or email
+
+ Generate the data, but then let someone else handle the view
+
+ """
+ num_tracks = 0
+ self.playlist.reverse()
+ for i in self.playlist:
+ num_tracks = num_tracks + 1
+ position = 'middle'
+ if num_tracks == 1:
+ position = 'first'
+ elif num_tracks == 2:
+ position = 'second'
+ elif num_tracks == len(self.playlist):
+ position = 'last'
+ yield self.announcements[position].format(**i)
+ self.playlist.reverse()
+
+
+def configure():
+ parser = argparse.ArgumentParser(description='Shownotes Application')
+ parser.add_argument('--audacity', '-a',
+ action='store',
+ required=True,
+ help='audacity file')
+ parser.add_argument('--json', '-j',
+ action='store',
+ required=True,
+ help='json playlist file')
+ args = parser.parse_args()
+ return args
+
+
+def main():
+ args = configure()
+ print args
+ show = ShowNotes(args.json, args.audacity)
+ print [note for note in show.create_shownotes()]
+ print [ann for ann in show.create_announcement()]
+
+if __name__ == '__main__':
+ main()
Please sign in to comment.
Something went wrong with that request. Please try again.