source: trunk/utilities/scam-export.py @ 1980

Revision 1980, 4.5 KB checked in by pjotr, 12 years ago (diff)

References #1512, added functionality to translate the subject_area into the codes used by the portal

Line 
1#!/usr/bin/env python
2# Generates CSV file for SCAM export
3
4import os, sys
5import codecs
6
7from Products.CMFCore.utils import getToolByName
8from Products.LeMill.config import MATERIAL_TYPES
9
10""" This script will generate a CSV file out of LeMill instance publiched object types that should be searchable from the Calibrate portal. Later it will be imported into SCAM. SCAM repository will be serving these objects to Calibrate portal thus allowing portal users to search for materials created in LeMill.
11
12Structure of the CSV file (mandatory fields are marked with *)
13
14Identifier catalog *
15Identifier entry *
16Metadata language *
17Title
18Description
19LO language *
20LRE keyword
21Keyword
22URL
23Learning resource type
24Age range
25Description of rights *
26Author
27
28FOLLOWING WILL BE LEFT EMPTY
29Language of translation
30Translated title
31Translated description
32Translated keywords
33"""
34
35
36# The script is run line this:
37# Go to the Zope instance folder and write bin/zopectl run Products/LeMill/utilities/scam-export.py [name of your portal] [link to your instance plus /content] and write to the file of your choice
38# The actual example is something like this:
39# bin/zopectl run Products/LeMill/utilities/scam-export.py  lemill http://dev.htk.tlu.ee:7778/lemill >lre.csv
40
41# LeMill identifier (Used for: Identifier catalog)
42identifier_catalog = 'lemill'
43
44# A link to a licence used by the portal (Used for: Description of rights)
45license_link = 'http://creativecommons.org/licenses/by-sa/2.5/'
46
47# Learning resource types
48lre_types = {'PILOTMaterial':'exploration','PresentationMaterial':'presentation','MultimediaMaterial':'web resource'}
49
50# Codes for Subject areas we use
51subj_area_types = {'Natural sciences':'875','Geography':'544','Chemistry':'195','Physics':'978','Biology':'144','Environmental education':'431','Language and literature':'758','Foreign languages':'508','Mathematics':'790','Informatics or ICT':'1034','Art':'91','Music':'856','History':'590','Religion':'1085','Philosophy':'968','Ethics':'441','Psychology':'1040','Social sciences':'1204','Culture':'303','Citizenship':'209','Politics':'1001','Economics':'383','Media education':'798','Physical education':'974','School-community relationship':'1139','Educational administration':'761','Cross-curricular education':'292'}
52
53def generateCSVfile(lemill_id,portal_url):
54    lemill = getattr(app,lemill_id)
55
56    pc = getToolByName(lemill, 'portal_catalog')
57    query = {'meta_type':MATERIAL_TYPES,
58        'review_state':'public'}
59    results = pc.searchResults(query)
60
61    for result in results:
62        fields = []
63        # Add Identifier catalog *
64        fields.append('lemill')
65
66        # Add Identifier entry *
67        fields.append(result.UID)
68        # Add Metadata language
69        fields.append(result.Language)
70        # Add Title
71        fields.append(result.Title)
72        # Add Description
73        # XXX XXX This one might be tricky and might even require us to deal with objects themselves
74        # ... BLA BLA BLA
75        # XXX TEMPORARY REPLACEMENT
76        fields.append('Description')
77        # Add LO language
78        fields.append(result.Language)
79        # LRE keyword
80        subj_res = result.getSubject_area
81        mod_subj_res = []
82        for subj in subj_res:
83            mod_subj_res.append(subj_area_types[subj])
84        subjs = ','.join(mod_subj_res)
85        fields.append(subjs)
86        # Add Keyword
87        # Tags list needs to be transformed into a string
88        tags_res = result.getTags
89        tags = ','.join(tags_res)
90        fields.append(tags)
91        # Add URL
92        # This will only work with objects from Content section
93        res_url = portal_url+'/content/'+result.getId
94        fields.append(res_url)
95        # Add learning resource type
96        fields.append(lre_types[result.meta_type])
97        # Add Age range
98        # XXX XXX This one will require a transformation
99        # XXX TEMPORARY REPLACEMENT
100        fields.append('6-18')
101        # ... BLA BLA BLA
102        # Add Description of rights
103        fields.append(license_link)
104        # Add Author
105        # We might need to get the nice Full names for the authors
106        authors_res = result.listCreators
107        authors = ','.join(authors_res)
108        fields.append(authors)
109
110        # All the rest will just be left empty
111        # Add Language of translation
112        fields.append('')
113        # Add Translated title
114        fields.append('')
115        # Add Translated description
116        fields.append('')
117        # Add Translated keywords
118        fields.append('')
119        # Print out some stuff
120        print '\t'.join(fields)
121    # This function ends
122
123generateCSVfile(sys.argv[1],sys.argv[2])
Note: See TracBrowser for help on using the repository browser.