"""Fetches the blogs configured on the website to local files.

The local files dumped to are 'BLOGNAME.incoming.yml' in the
assets/blogs directory.

Should be run as a regular cron-job.  Must be run from within the
website virtual environment.

---

Copyright (c) 2013, University Radio York.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
import pyramid
import feedparser
import pickle

import lass.common.config


if __name__ == '__main__':
    blog_config = lass.common.config.from_yaml('sitewide/blogs')

    for name, config in blog_config.items():
        asset = 'assets:blogs/{}.incoming'.format(name)
        full_path = pyramid.path.AssetResolver().resolve(asset).abspath()

        feed = feedparser.parse(config['feed'])

        with open(full_path, 'wb+') as stream:
            pickle.dump(feed, stream)

Move the Python end of blog-fetch to LASS.
Move the Python end of blog-fetch to LASS.
