コード例 #1
0
ファイル: preprocess.py プロジェクト: ahmadia/site
def main():
    '''
    Main driver for regenerating _config.yml for web site.
    This program also creates _includes/recent_blog_posts.html.
    '''

    # Get the standard stuff.
    options, args = parse_args()
    config = load_info(os.curdir, STANDARD_YML)
    config['badges'] = load_info(os.curdir, BADGES_YML)
    config['airports'] = load_info(os.curdir, AIRPORTS_YML)
    config.update({
        'month_names'     : MONTHS,
        'months'          : sorted(MONTHS.keys()),
        'site'            : options.site,
        'timestamp'       : time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
        'today'           : options.today
    })

    # Cache the window size.
    recent_length = config['recent_length']

    # Get information from blog entries.
    config['blog'] = harvest_blog(config)

    # Sanity checks on blog posts.
    check_blog_sanity(config['blog'])

    # Select those that'll be displayed on the home page, the index page, etc.
    config['blog_recent'] = config['blog'][-recent_length:]
    config['blog_recent'].reverse()

    # Create _includes/recent_blog_posts.html for inclusion in blog index page.
    # This is done programmatically because we want snippets to be rendered properly.
    for post in config['blog_recent']:
        post['excerpt'] = get_blog_excerpt(post['path'])
    write_recent_blog_posts(config['blog_recent'])

    # Organize all posts by year and month.
    blog_lookup, blog_count = organize_blog_entries(config['blog'])
    config['blog_lookup'] = blog_lookup
    config['blog_count'] = blog_count
    config['blog_years'] = sorted(blog_lookup.keys())
    config['blog_years'].reverse()

    # Get information from legacy boot camps.
    config['bootcamps'] = harvest_bootcamps()

    # Select those that'll be displayed on the home page.
    upcoming = [bc for bc in config['bootcamps'] if bc['startdate'] >= config['today']]
    config['bootcamps_upcoming'] = upcoming[:recent_length]

    # Save.
    with open(CONFIG_YML, 'w') as writer:
        yaml.dump(config, writer)
コード例 #2
0
def load_cached_info(folder, filename, message):
    '''Load cached info if available, fail if not.'''
    path = os.path.join(folder, filename)
    if not os.path.isfile(path):
        print >> sys.stderr, '{0} file "{1}" does not exist.'.format(message, path)
        print >> sys.stderr, 'Please use "make cache" before building site,'
        sys.exit(1)
    return load_info(folder, filename)
コード例 #3
0
ファイル: preprocess.py プロジェクト: Harshit094/site
def load_cached_info(folder, filename, message):
    '''Load cached info if available, fail if not.'''
    path = os.path.join(folder, filename)
    if not os.path.isfile(path):
        print >> sys.stderr, '{0} file "{1}" does not exist.'.format(message, path)
        print >> sys.stderr, 'Please use "make cache" before building site,'
        sys.exit(1)
    return load_info(folder, filename)
コード例 #4
0
ファイル: preprocess.py プロジェクト: abought/swc-site
def load_cached_workshop_info(folder, filename):
    '''Load cached workshop info if available, fail if not.'''
    path = os.path.join(folder, filename)
    if not os.path.isfile(path):
        print >> sys.stderr, 'Workshop information cache "{0}" does not exist.'.format(path)
        print >> sys.stderr, 'Please use "make cache" before building site,'
        print >> sys.stderr, 'Or run "bin/get_workshop_info" to regenerate it.'
        sys.exit(1)
    return load_info(folder, filename)
コード例 #5
0
ファイル: make_calendar.py プロジェクト: psteinb/site
def main():
    '''Main driver for calendar regeneration.'''

    options, args = parse_args()
    config = load_info(os.curdir)
    config['site'] = options.site
    calendar_file = os.path.join(options.output, 'workshops.ics')

    icw = ICalendarWriter()
    icw(calendar_file, config)
コード例 #6
0
ファイル: make-calendar.py プロジェクト: arokem/site
def main():
    '''Main driver for calendar regeneration.'''

    options, args = parse_args()
    config = load_info(os.curdir)
    config['site'] = options.site
    calendar_file = os.path.join(options.output, 'workshops.ics')

    icw = ICalendarWriter()
    icw(calendar_file, config)
コード例 #7
0
def main():
    '''Main driver for workshop feed regeneration.'''

    options, args = parse_args()
    config = load_info(os.curdir)
    config['site'] = options.site

    workshops = get_future_workshops(config['workshops'])
    build_workshop_rss(config, os.path.join(options.output,
                                            'workshop-feed.xml'), workshops)
コード例 #8
0
def load_cached_workshop_info(folder, filename):
    '''Load cached workshop info if available, fail if not.'''
    path = os.path.join(folder, filename)
    if not os.path.isfile(path):
        print >> sys.stderr, 'Workshop information cache "{0}" does not exist.'.format(
            path)
        print >> sys.stderr, 'Please use "make cache" before building site,'
        print >> sys.stderr, 'Or run "bin/get_workshop_info" to regenerate it.'
        sys.exit(1)
    return load_info(folder, filename)
コード例 #9
0
ファイル: make_bootcamp_rss_feed.py プロジェクト: dmj111/site
def main():
    '''Main driver for boot camp feed regeneration.'''

    options, args = parse_args()
    config = load_info(os.curdir)
    config['site'] = options.site

    bootcamps = get_future_boot_camps(config['bootcamps'])
    build_bootcamp_rss(config,
                       os.path.join(options.output, 'bootcamp-feed.xml'),
                       bootcamps)
コード例 #10
0
def main():
    '''Main driver for workshop feed regeneration.'''

    options, args = parse_args()
    config = load_info(os.curdir)
    config['site'] = options.site

    workshops = get_future_workshops(config['workshops'])
    build_workshop_rss(config,
                       os.path.join(options.output, 'workshop-feed.xml'),
                       workshops)
コード例 #11
0
def main():
    '''Main driver for feed regeneration.'''

    options, args = parse_args()
    config = load_info(os.curdir)
    config['site'] = options.site
    config['output'] = options.output

    selection = config['blog'][-config['recent_length']:]
    selection.reverse()
    build_blog_rss(config, os.path.join(options.output, 'feed.xml'), selection)
コード例 #12
0
ファイル: make-rss-feed.py プロジェクト: Harshit094/site
def main():
    '''Main driver for feed regeneration.'''

    options, args = parse_args()
    config = load_info(os.curdir)
    config['site'] = options.site
    config['output'] = options.output

    selection = config['blog'][-config['recent_length']:]
    selection.reverse()
    build_blog_rss(config,
                   os.path.join(options.output, 'feed.xml'),
                   selection)
コード例 #13
0
ファイル: preprocess.py プロジェクト: greisault/site
def main():
    '''
    Main driver for regenerating _config.yml for web site.
    This program also creates _includes/recent_blog_posts.html.
    '''

    # Get the standard stuff.
    options, args = parse_args()
    config = load_info(os.curdir, STANDARD_YML)
    config['badges'] = load_info(os.curdir, BADGES_YML)
    config['airports'] = load_info(os.curdir, AIRPORTS_YML)
    config.update({
        'month_names':
        MONTHS,
        'months':
        sorted(MONTHS.keys()),
        'site':
        options.site,
        'timestamp':
        time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
        'today':
        options.today
    })

    # Cache the window size.
    recent_length = config['recent_length']

    # Get information from blog entries.
    config['blog'] = harvest_blog(config)

    # Sanity checks on blog posts.
    check_blog_sanity(config['blog'])

    # Select those that'll be displayed on the home page, the index page, etc.
    config['blog_recent'] = config['blog'][-recent_length:]
    config['blog_recent'].reverse()

    # Create _includes/recent_blog_posts.html for inclusion in blog index page.
    # This is done programmatically because we want snippets to be rendered properly.
    for post in config['blog_recent']:
        post['excerpt'] = get_blog_excerpt(post['path'])
    write_recent_blog_posts(config['blog_recent'])

    # Organize all posts by year and month.
    blog_lookup, blog_count = organize_blog_entries(config['blog'])
    config['blog_lookup'] = blog_lookup
    config['blog_count'] = blog_count
    config['blog_years'] = sorted(blog_lookup.keys())
    config['blog_years'].reverse()

    # Construct list of favorite blog posts.
    config['blog_favorites'] = [p for p in config['blog'] if p['favorite']]
    config['blog_favorites'].reverse()

    # Get information from legacy boot camps.
    config['bootcamps'] = harvest_bootcamps()

    # Select those that'll be displayed on the home page.
    upcoming = [
        bc for bc in config['bootcamps'] if bc['startdate'] >= config['today']
    ]
    config['bootcamps_upcoming'] = upcoming[:recent_length]

    # Save.
    with open(CONFIG_YML, 'w') as writer:
        yaml.dump(config, writer)
コード例 #14
0
ファイル: preprocess.py プロジェクト: abought/swc-site
def main():
    '''
    Main driver for regenerating _config.yml for web site.
    This program also creates _includes/recent_blog_posts.html.
    '''

    # Get the standard stuff.
    options, args = parse_args()

    # Check that a cached workshop information file is available, and
    # report an error if it's not.  Do this early to avoid wasting
    # time; store in local variable until other workshop info is
    # loaded and available for merging.
    cached_workshop_info = load_cached_workshop_info(os.curdir, WORKSHOP_CACHE)

    # Load other information.
    config = load_info(options.config_dir, STANDARD_YML)
    config['badges'] = load_info(options.config_dir, BADGES_YML)
    config['airports'] = load_info(options.config_dir, AIRPORTS_YML)
    config.update({
        'month_names'     : MONTHS,
        'months'          : sorted(MONTHS.keys()),
        'site'            : options.site,
        'timestamp'       : time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
        'today'           : options.today
    })

    # People and projects.
    config['people'] = map(lambda x: os.path.relpath(x, '_includes'), 
                           sorted(glob.glob('_includes/people/*.html')))
    config['projects'] = map(lambda x: os.path.relpath(x, '_includes'), 
                             sorted(glob.glob('_includes/projects/*.html')))

    # Cache the window size.
    recent_length = config['recent_length']
    upcoming_length = config['upcoming_length']

    # Get information from blog entries.
    config['blog'] = harvest_blog(config)

    # Sanity checks on blog posts.
    check_blog_sanity(config['blog'])

    # Select those that'll be displayed on the home page, the index page, etc.
    config['blog_recent'] = config['blog'][-recent_length:]
    config['blog_recent'].reverse()

    # Create _includes/recent_blog_posts.html for inclusion in blog index page.
    # This is done programmatically because we want snippets to be rendered properly.
    for post in config['blog_recent']:
        post['excerpt'] = get_blog_excerpt(post['path'])
    write_recent_blog_posts(config['blog_recent'])

    # Organize all posts by year and month.
    blog_lookup, blog_count = organize_blog_entries(config['blog'])
    config['blog_lookup'] = blog_lookup
    config['blog_count'] = blog_count
    config['blog_years'] = sorted(blog_lookup.keys())
    config['blog_years'].reverse()

    # Construct list of favorite blog posts.
    config['blog_favorites'] = [p for p in config['blog'] if p['favorite']]
    config['blog_favorites'].reverse()

    # Ensure that information about workshops is in the right order.
    cached_workshop_info.sort(lambda x, y: cmp(x['slug'], y['slug']))
    config['workshops'] = cached_workshop_info

    # Select those that'll be displayed on the home page.  Use a loop instead of
    # a list comprehension to get better error reporting.
    upcoming = []
    for bc in config['workshops']:
        try:
            if bc['startdate'] >= config['today']:
                upcoming.append(bc)
        except TypeError, e:
            print >> sys.stderr, 'Unable to process start date "{0}"'.format(bc['startdate'])
コード例 #15
0
ファイル: 8.1.py プロジェクト: xietx1995/pdb_intro
def my_func1(path):
    info = util.load_info(path)
    my_func2(info)
コード例 #16
0
ファイル: preprocess.py プロジェクト: PBarmby/site
def main():
    '''
    Main driver for regenerating _config.yml for web site.
    This program also creates _includes/recent_blog_posts.html.
    '''

    # Get the standard stuff.
    options, args = parse_args()

    # Load other information.
    config = load_info(options.config_dir, STANDARD_YML)

    # Insert standing values into configuration.
    config.update({
        'month_names'     : MONTHS,
        'months'          : sorted(MONTHS.keys()),
        'site'            : options.site,
        'timestamp'       : time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
        'today'           : options.today
    })

    # Load cached dashboard info.  Do this early to avoid wasting time
    # on everything else if it's not available.
    config['dashboard'] = load_cached_info(os.curdir, DASHBOARD_CACHE, 'dashboard cache')

    # Fetch information from AMY.
    config['badges'] = fetch_info(options.amy_url, BADGES_URL)
    config['airports'] = fetch_info(options.amy_url, AIRPORTS_URL)
    config['workshops'] = fetch_info(options.amy_url, WORKSHOPS_URL)

    # Lower-case and coalesce national flags.
    for a in config['airports']:
        a['country'] = a['country'].lower()
    for w in config['workshops']:
        w['country'] = w['country'].lower()
    config['flags'] = {
        'workshops': sorted({w['country'] for w in config['workshops'] if w['country']}),
        'airports': sorted({a['country'] for a in config['airports'] if a['country']})
    }

    # Select workshops that will be displayed on the home page (soonest first).
    workshops_upcoming = [w for w in config['workshops'] if w['start'] >= config['today']]
    workshops_upcoming.reverse()
    config['workshops_upcoming'] = workshops_upcoming
    config['workshops_upcoming_short'] = workshops_upcoming[ :config['upcoming_length'] ]

    # Load people and projects.
    config['people'] = list(map(lambda x: os.path.relpath(x, '_includes'),
                                sorted(glob.glob('_includes/people/*.html'))))
    config['projects'] = list(map(lambda x: os.path.relpath(x, '_includes'),
                                  sorted(glob.glob('_includes/projects/*.html'))))

    # Get information from blog entries.
    config['blog'] = harvest_blog(config)

    # Sanity checks on blog posts.
    check_blog_sanity(config['blog'])

    # Select those that'll be displayed on the home page, the index page, etc.
    config['blog_recent'] = config['blog'][ -config['recent_length']: ]
    config['blog_recent'].reverse()

    # Create _includes/recent_blog_posts.html for inclusion in blog index page.
    # This is done programmatically because we want snippets to be rendered properly.
    for post in config['blog_recent']:
        post['excerpt'] = get_blog_excerpt(post['path'])
    write_recent_blog_posts(config['blog_recent'])

    # Organize all posts by year and month.
    blog_lookup, blog_count = organize_blog_entries(config['blog'])
    config['blog_lookup'] = blog_lookup
    config['blog_count'] = blog_count
    config['blog_years'] = sorted(blog_lookup.keys())
    config['blog_years'].reverse()

    # Construct list of favorite blog posts.
    config['blog_favorites'] = [p for p in config['blog'] if p['favorite']]
    config['blog_favorites'].reverse()

    # Save.
    with open(CONFIG_YML, 'w') as writer:
        yaml.dump(config, writer, encoding='utf-8', allow_unicode=True)
コード例 #17
0
ファイル: preprocess.py プロジェクト: beroe/site
def main():
    '''
    Main driver for regenerating _config.yml for web site.
    This program also creates _includes/recent_blog_posts.html.
    '''

    # Get the standard stuff.
    options, args = parse_args()

    # Check that a cached bootcamp information file is available, and
    # report an error if it's not.  Do this early to avoid wasting
    # time; store in local variable until other bootcamp info is
    # loaded and available for merging.
    cached_bootcamp_info = load_cached_bootcamp_info(os.curdir, BOOTCAMP_CACHE)

    # Load other information.
    config = load_info(options.config_dir, STANDARD_YML)
    config['badges'] = load_info(options.config_dir, BADGES_YML)
    config['airports'] = load_info(options.config_dir, AIRPORTS_YML)
    config.update({
        'month_names'     : MONTHS,
        'months'          : sorted(MONTHS.keys()),
        'site'            : options.site,
        'timestamp'       : time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
        'today'           : options.today
    })

    # Cache the window size.
    recent_length = config['recent_length']

    # Get information from blog entries.
    config['blog'] = harvest_blog(config)

    # Sanity checks on blog posts.
    check_blog_sanity(config['blog'])

    # Select those that'll be displayed on the home page, the index page, etc.
    config['blog_recent'] = config['blog'][-recent_length:]
    config['blog_recent'].reverse()

    # Create _includes/recent_blog_posts.html for inclusion in blog index page.
    # This is done programmatically because we want snippets to be rendered properly.
    for post in config['blog_recent']:
        post['excerpt'] = get_blog_excerpt(post['path'])
    write_recent_blog_posts(config['blog_recent'])

    # Organize all posts by year and month.
    blog_lookup, blog_count = organize_blog_entries(config['blog'])
    config['blog_lookup'] = blog_lookup
    config['blog_count'] = blog_count
    config['blog_years'] = sorted(blog_lookup.keys())
    config['blog_years'].reverse()

    # Construct list of favorite blog posts.
    config['blog_favorites'] = [p for p in config['blog'] if p['favorite']]
    config['blog_favorites'].reverse()

    # Get information from legacy boot camp pages and merge with cached info.
    config['bootcamps'] = harvest_bootcamps(cached_bootcamp_info)

    # Select those that'll be displayed on the home page.
    upcoming = [bc for bc in config['bootcamps'] if bc['startdate'] >= config['today']]
    config['bootcamps_upcoming'] = upcoming[:recent_length]
    config['bootcamps_num_upcoming'] = len(upcoming)

    # Save.
    with open(CONFIG_YML, 'w') as writer:
        yaml.dump(config, writer)
コード例 #18
0
def main():
    '''
    Main driver for regenerating _config.yml for web site.
    This program also creates _includes/recent_blog_posts.html.
    '''

    # Get the standard stuff.
    options, args = parse_args()

    # Check that a cached workshop information file is available, and
    # report an error if it's not.  Do this early to avoid wasting
    # time; store in local variable until other workshop info is
    # loaded and available for merging.
    cached_workshop_info = load_cached_workshop_info(os.curdir, WORKSHOP_CACHE)

    # Load other information.
    config = load_info(options.config_dir, STANDARD_YML)
    config['badges'] = load_info(options.config_dir, BADGES_YML)
    config['airports'] = load_info(options.config_dir, AIRPORTS_YML)
    config.update({
        'month_names':
        MONTHS,
        'months':
        sorted(MONTHS.keys()),
        'site':
        options.site,
        'timestamp':
        time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
        'today':
        options.today
    })

    config['people'] = map(lambda x: os.path.relpath(x, '_includes'),
                           sorted(glob.glob('_includes/people/*.html')))

    # Cache the window size.
    recent_length = config['recent_length']
    upcoming_length = config['upcoming_length']

    # Get information from blog entries.
    config['blog'] = harvest_blog(config)

    # Sanity checks on blog posts.
    check_blog_sanity(config['blog'])

    # Select those that'll be displayed on the home page, the index page, etc.
    config['blog_recent'] = config['blog'][-recent_length:]
    config['blog_recent'].reverse()

    # Create _includes/recent_blog_posts.html for inclusion in blog index page.
    # This is done programmatically because we want snippets to be rendered properly.
    for post in config['blog_recent']:
        post['excerpt'] = get_blog_excerpt(post['path'])
    write_recent_blog_posts(config['blog_recent'])

    # Organize all posts by year and month.
    blog_lookup, blog_count = organize_blog_entries(config['blog'])
    config['blog_lookup'] = blog_lookup
    config['blog_count'] = blog_count
    config['blog_years'] = sorted(blog_lookup.keys())
    config['blog_years'].reverse()

    # Construct list of favorite blog posts.
    config['blog_favorites'] = [p for p in config['blog'] if p['favorite']]
    config['blog_favorites'].reverse()

    # Ensure that information about workshops is in the right order.
    cached_workshop_info.sort(lambda x, y: cmp(x['slug'], y['slug']))
    config['workshops'] = cached_workshop_info

    # Select those that'll be displayed on the home page.  Use a loop instead of
    # a list comprehension to get better error reporting.
    upcoming = []
    for bc in config['workshops']:
        try:
            if bc['startdate'] >= config['today']:
                upcoming.append(bc)
        except TypeError, e:
            print >> sys.stderr, 'Unable to process start date "{0}"'.format(
                bc['startdate'])
コード例 #19
0
def main():
    '''
    Main driver for regenerating _config.yml for web site.
    This program also creates _includes/recent_blog_posts.html.
    '''

    # Get the standard stuff.
    options, args = parse_args()

    # Load other information.
    config = load_info(options.config_dir, STANDARD_YML)

    # Insert standing values into configuration.
    config.update({
        'month_names':
        MONTHS,
        'months':
        sorted(MONTHS.keys()),
        'site':
        options.site,
        'timestamp':
        time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
        'today':
        options.today
    })

    # Load cached dashboard info.  Do this early to avoid wasting time
    # on everything else if it's not available.
    config['dashboard'] = load_cached_info(os.curdir, DASHBOARD_CACHE,
                                           'dashboard cache')

    # Fetch information from AMY.
    config['badges'] = fetch_info(options.amy_url, BADGES_URL)
    config['airports'] = fetch_info(options.amy_url, AIRPORTS_URL)
    config['workshops'] = fetch_info(options.amy_url, WORKSHOPS_URL)

    # Lower-case and coalesce national flags.
    for a in config['airports']:
        a['country'] = a['country'].lower()
    for w in config['workshops']:
        w['country'] = w['country'].lower()
    config['flags'] = {
        'workshops':
        sorted({w['country']
                for w in config['workshops'] if w['country']}),
        'airports':
        sorted({a['country']
                for a in config['airports'] if a['country']})
    }

    # Select workshops that will be displayed on the home page (soonest first).
    workshops_upcoming = [
        w for w in config['workshops'] if w['start'] >= config['today']
    ]
    workshops_upcoming.reverse()
    config['workshops_upcoming'] = workshops_upcoming
    config['workshops_upcoming_short'] = workshops_upcoming[:config[
        'upcoming_length']]

    # Load people and projects.
    config['people'] = list(
        map(lambda x: os.path.relpath(x, '_includes'),
            sorted(glob.glob('_includes/people/*.html'))))
    config['projects'] = list(
        map(lambda x: os.path.relpath(x, '_includes'),
            sorted(glob.glob('_includes/projects/*.html'))))

    # Get information from blog entries.
    config['blog'] = harvest_blog(config)

    # Sanity checks on blog posts.
    check_blog_sanity(config['blog'])

    # Select those that'll be displayed on the home page, the index page, etc.
    config['blog_recent'] = config['blog'][-config['recent_length']:]
    config['blog_recent'].reverse()

    # Create _includes/recent_blog_posts.html for inclusion in blog index page.
    # This is done programmatically because we want snippets to be rendered properly.
    for post in config['blog_recent']:
        post['excerpt'] = get_blog_excerpt(post['path'])
    write_recent_blog_posts(config['blog_recent'])

    # Organize all posts by year and month.
    blog_lookup, blog_count = organize_blog_entries(config['blog'])
    config['blog_lookup'] = blog_lookup
    config['blog_count'] = blog_count
    config['blog_years'] = sorted(blog_lookup.keys())
    config['blog_years'].reverse()

    # Construct list of favorite blog posts.
    config['blog_favorites'] = [p for p in config['blog'] if p['favorite']]
    config['blog_favorites'].reverse()

    # Save.
    with open(CONFIG_YML, 'w') as writer:
        yaml.dump(config, writer, encoding='utf-8', allow_unicode=True)