def METHOD_NAME():
    try:
        release_date = datetime.now().strftime("%Y-%m-%d")
        try:
            for line in sys.stdin:
                rec = simplejson.loads(line)
                rec = rec.get('record', rec)
                rec["portal_release_date"] = release_date
                if not rec.get('date_published'):
                    rec['date_published'] = release_date
                rec["ready_to_publish"] = "true"
                rec["imso_approval"] = "true"
                if "catalog_type" in rec:
                    del rec["catalog_type"]
                rec["type"] = "dataset"
                if "subject" in rec:
                    if rec["subject"] in subject_replacements:
                        rec["subject"] = subject_replacements[rec["subject"]]
                    else:
                        print >> sys.stderr, 'Invalid subject "{0}" for {1}'.format(rec["subject"], rec["id"])
                        continue
                rec['author_email'] = 'statcan.infostats-infostats.statcan@canada.ca'
                rec['maintainer_email'] = 'statcan.infostats-infostats.statcan@canada.ca'
                url_en, url_fr = rec.pop('url', None), rec.pop('url_fra', None)
                rec['program_url'] = {'en':url_en, 'fr':url_fr}
                notes_en = rec.pop('notes','')
                notes_fr = rec.pop('notes_fra','')
                rec['notes_translated'] = {'en':notes_en, 'fr':notes_fr}
                data_series_name_en = rec.pop('data_series_name', '')
                data_series_name_fr = rec.pop('data_series_name_fra', '')
                rec['data_series_name'] = {'en':data_series_name_en, 'fr':data_series_name_en}
                title_en = rec.get('title', '')
                title_fr = rec.pop('title_fra', '')
                rec['title_translated']={'en':title_en, 'fr':title_fr}
                data_series_issue_identification = rec.pop("data_series_issue_identification", "")
                data_series_issue_identification_fra = rec.pop("data_series_issue_identification_fra", "")
                rec["data_series_issue_identification"]={
                        'en':data_series_issue_identification,
                        'fr':data_series_issue_identification_fra
                }
                freq = rec.pop('maintenance_and_update_frequency', '')
                if freq:
                    rec['frequency'] = freq_dict.get(freq, 'as_needed')
                keywords = rec.pop('keywords','')
                keywords_fr = rec.pop('keywords_fra','')
                rec['keywords'] = {'en':[keywords], 'fr':[keywords_fr]}
                rec['collection'] = 'primary'
                rec['jurisdiction'] = 'federal'
                rec['geographic_region']= []
                rec['restrictions'] = 'unrestricted'
                for res in rec['resources']:
                    name = res.pop('name','')
                    name_fr = res.pop('name_fra','')
                    res['name_translated'] = {'en':name, 'fr':name_fr}
                    lang = res.pop('language', '')
                    res['language'] = lang_dict.get(lang, [])
                    rformat = res.get('format', '')
                    if rformat =='HTML':
                        res['resource_type']='guide'
                    else:
                        res['resource_type']='dataset'
                print simplejson.dumps(rec)
        except IOError:
            print >> sys.stderr, 'Error while reading line.'
    except KeyError:
        if 'warehouse' in sys.argv:
            sys.exit(85)
        else:
            raise