<commit_before>#!/usr/bin/env python
# encoding: utf-8
import sys
from modularodm.exceptions import ModularOdmException
from website.project.views.email import Conference
from website.app import init_app

def main():
    init_app(set_backends=True, routes=False)
    populate_conferences()

MEETING_DATA = {
    'spsp2014': {
        'name': 'SPSP 2014',
        'info_url': None,
        'logo_url': None,
        'active': False,
        'admins': None,
        'public_projects': True,
    },
    'asb2014': {
        'name': 'ASB 2014',
        'info_url': 'http://www.sebiologists.org/meetings/talks_posters.html',
        'logo_url': None,
        'active': False,
        'admins': None,
        'public_projects': True,
    },
    'aps2014': {
        'name': 'APS 2014',
        'info_url': 'http://centerforopenscience.org/aps/',
        'logo_url': '/static/img/2014_Convention_banner-with-APS_700px.jpg',
        'active': False,
        'admins': None,
        'public_projects': True,
    },
    'annopeer2014': {
        'name': '#annopeer',
        'info_url': None,
        'logo_url': None,
        'active': False,
        'admins': None,
        'public_projects': True,
    },
    'cpa2014': {
        'name': 'CPA 2014',
        'info_url': None,
        'logo_url': None,
        'active': False,
        'admins': None,
        'public_projects': True,
    },
    'filaments2014': {
        'name': 'Filaments 2014',
        'info_url': None,
        'logo_url': 'https://science.nrao.edu/science/meetings/2014/'
                    'filamentary-structure/images/filaments2014_660x178.png',
        'active': True,
        'admins': [
            '<EMAIL>',
            '<EMAIL>',
        ],
        'public_projects': True,
    },
    # TODO: Uncomment on 2015/02/01
    # 'spsp2015': {
    #     'name': 'SPSP 2015',
    #     'info_url': None,
    #     'logo_url': None,
    #     'active': False,
    # },
}

def populate_conferences():
    for key, val in MEETING_DATA.iteritems():
        try:
            conf = Conference(
                endpoint=key, **val
            )
            conf.save()
        except ModularOdmException:
            print('{0} Conference already exists. Skipping...'.format(key))<commit_msg>Fix populate_conferences script<commit_after>#!/usr/bin/env python
# encoding: utf-8
import sys

from modularodm import Q
from modularodm.exceptions import ModularOdmException

from framework.auth.core import User
from website.project.views.email import Conference
from website.app import init_app

def main():
    init_app(set_backends=True, routes=False)
    populate_conferences()

MEETING_DATA = {
    'spsp2014': {
        'name': 'SPSP 2014',
        'info_url': None,
        'logo_url': None,
        'active': False,
        'admins': [],
        'public_projects': True,
    },
    'asb2014': {
        'name': 'ASB 2014',
        'info_url': 'http://www.sebiologists.org/meetings/talks_posters.html',
        'logo_url': None,
        'active': False,
        'admins': [],
        'public_projects': True,
    },
    'aps2014': {
        'name': 'APS 2014',
        'info_url': 'http://centerforopenscience.org/aps/',
        'logo_url': '/static/img/2014_Convention_banner-with-APS_700px.jpg',
        'active': False,
        'admins': [],
        'public_projects': True,
    },
    'annopeer2014': {
        'name': '#annopeer',
        'info_url': None,
        'logo_url': None,
        'active': False,
        'admins': [],
        'public_projects': True,
    },
    'cpa2014': {
        'name': 'CPA 2014',
        'info_url': None,
        'logo_url': None,
        'active': False,
        'admins': [],
        'public_projects': True,
    },
    'filaments2014': {
        'name': 'Filaments 2014',
        'info_url': None,
        'logo_url': 'https://science.nrao.edu/science/meetings/2014/'
                    'filamentary-structure/images/filaments2014_660x178.png',
        'active': True,
        'admins': [
            '<EMAIL>',
            '<EMAIL>',
        ],
        'public_projects': True,
    },
    # TODO: Uncomment on 2015/02/01
    # 'spsp2015': {
    #     'name': 'SPSP 2015',
    #     'info_url': None,
    #     'logo_url': None,
    #     'active': False,
    # },
}

def populate_conferences():
    for meeting, attrs in MEETING_DATA.iteritems():
        admin_emails = attrs.pop('admins')
        admin_objs = []
        for email in admin_emails:
            try:
                user = User.find_one(Q('username', 'iexact', email))
                admin_objs.append(user)
            except ModularOdmException:
                raise RuntimeError('Username {0!r} is not registered.'.format(email))
        try:
            conf = Conference(
                endpoint=meeting, admins=admin_objs, **attrs
            )
            conf.save()
        except ModularOdmException:
            print('{0} Conference already exists. Skipping...'.format(meeting))
{'fraction_non_alphanumeric': 0.14898328971209987, 'fraction_numerical': 0.03362190457016308, 'mean_word_length': 2.040391676866585, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5263320', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1600, 'n_words': 312}