# Path: search/data/category_mappings.py
# def mit_to_merlot_category(cat, subcat=None, spec=None):
#     # print cat, subcat, spec
#     if cat and subcat and spec:
#         cat = cat[0]
#         subcat = subcat[0]
#         spec = spec[0]
#         return MIT_MAPPING[cat][subcat][spec]['_cat']
# 
#     if cat and subcat:
#         cat = cat[0]
#         subcat = subcat[0]
#         return MIT_MAPPING[cat][subcat]['_cat']
# 
#     if cat:
#         cat = cat[0]
#         return MIT_MAPPING[cat]['_cat']


import xlwt
import datetime
import requests
import requests_cache
import xml.etree.ElementTree as ET
import lxml.html
from lxml import etree
from lxml.cssselect import CSSSelector
from optparse import make_option
from collections import OrderedDict
from urlparse import urlsplit, parse_qs
from django.core.management.base import BaseCommand
from django.conf import settings
from ...category_mappings import mit_to_merlot_category
from data.models import Source, Course, MerlotCategory, MerlotLanguage, SearchQuery
    def _update_metadata(self, material):
        url = material.find('URL').text
        try:
            photo_url = material.find('photoURL').text
        except AttributeError:
            photo_url = ''

        course_data = {
            'linkurl': url,
            'title': material.find('title').text,
            'merlot_id': material.find('materialid').text,
            'description': material.find('description').text,
            'author': material.find('authorName').text or '',
            'author_organization': material.find('authorOrg').text or '',
            'image_url': photo_url,
            'merlot_xml': ET.tostring(material, encoding='utf-8'),
            'merlot_synced_date': datetime.datetime.now(),
            'merlot_synced': True,
        }

        course_data['creative_commons_commercial'] = 'Unsure'
        creativecommons = material.find('creativecommons').text
        if 'cc-' in creativecommons:
            course_data['creative_commons'] = 'Yes'

            if 'nc' in creativecommons:
                course_data['creative_commons_commercial'] = 'No'

            if 'sa' in creativecommons:
                course_data['creative_commons_derivatives'] = 'Sa'

# Path: search/data/category_mappings.py
# def mit_to_merlot_category(cat, subcat=None, spec=None):
#     # print cat, subcat, spec
#     if cat and subcat and spec:
#         cat = cat[0]
#         subcat = subcat[0]
#         spec = spec[0]
#         return MIT_MAPPING[cat][subcat][spec]['_cat']
# 
#     if cat and subcat:
#         cat = cat[0]
#         subcat = subcat[0]
#         return MIT_MAPPING[cat][subcat]['_cat']
# 
#     if cat:
#         cat = cat[0]
#         return MIT_MAPPING[cat]['_cat']


# Path: search/data/management/commands/merlot.py
import xlwt
import datetime
import requests
import requests_cache
import xml.etree.ElementTree as ET
import lxml.html
from lxml import etree
from lxml.cssselect import CSSSelector
from optparse import make_option
from collections import OrderedDict
from urlparse import urlsplit, parse_qs
from django.core.management.base import BaseCommand
from django.conf import settings
from ...category_mappings import mit_to_merlot_category
from data.models import Source, Course, MerlotCategory, MerlotLanguage, SearchQuery

    def _update_metadata(self, material):
        url = material.find('URL').text
        try:
            photo_url = material.find('photoURL').text
        except AttributeError:
            photo_url = ''

        course_data = {
            'linkurl': url,
            'title': material.find('title').text,
            'merlot_id': material.find('materialid').text,
            'description': material.find('description').text,
            'author': material.find('authorName').text or '',
            'author_organization': material.find('authorOrg').text or '',
            'image_url': photo_url,
            'merlot_xml': ET.tostring(material, encoding='utf-8'),
            'merlot_synced_date': datetime.datetime.now(),
            'merlot_synced': True,
        }

        course_data['creative_commons_commercial'] = 'Unsure'
        creativecommons = material.find('creativecommons').text
        if 'cc-' in creativecommons:
            course_data['creative_commons'] = 'Yes'

            if 'nc' in creativecommons:
                course_data['creative_commons_commercial'] = 'No'

            if 'sa' in creativecommons:
                course_data['creative_commons_derivatives'] = 'Sa'

            elif 'nd' in creativecommons: