{ "info": { "author": "Shawn Averkamp", "author_email": "shawnaverkamp@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# Pycdm\r\n\r\nPycdm is a simple library for working with your CONTENTdm item and collection metadata as Python objects. Retrieve all metadata for an item and its pages with just a collection alias and item ID. \r\n\r\n cookbook = pycdm.item('cookbooks', '2775')\r\n\r\nPycdm interfaces with the CONTENTdm 6 dmwebservices API to fetch metadata. You can also make direct calls to the API through the Api class:\r\n\r\n #returns a decoded json response for a dmGetItemInfo call\r\n call = Api()\r\n iteminfo = call.dmGetItemInfo('cookbooks', '2775')\r\n\r\n# Installation\r\n\r\nPycdm works with Python 2.7x only (solely to make use of the collections.OrderedDict subclass, which preserves Node and Page object sequence within dictionaries).\r\n\r\nInstall with pip: \r\n\r\n $ pip install pycdm\r\n\r\n(or easy_install):\r\n\r\n $ easy_install pycdm\r\n\r\nOpen the pycdm.py file and replace the base and port variables with the base url and port of your CONTENTdm respository.\r\n\r\n base = 'http://yourbaseurl.edu'\r\n port = ':81'\r\n\r\n# Examples\r\n\r\n### Working with items and pages\r\n#### Items\r\nCONTENTdm items are one of three types: single page, compound object--document (a series of pages), or compound object--monograph (a series of pages organized into nodes, like a book divided into chapters). Calling the item() function creates an item object with attributes related to its descriptive and structural metadata. This includes: \r\n\r\n* descriptive metadata record (item.info, Python dict where key=field nickname)\r\n* the Dublin Core metadata record (item.dcinfo, Python dict where key= DC field nickname)\r\n* CONTENTdm identifier (item.id)\r\n* the Collection object the item is part of (item.collection)\r\n* the reference URL for the item (item.refurl)\r\n* the page structure of theitem object (item.structure) \r\n* list of the item's constituent page objects (item.pages)\r\n\r\nFor single page items, you'll also get: \r\n\r\n* URL for the stored file for the page (item.fileurl)\r\n* URL for the default scaled/cropped JPEG image of a page image. Use the GetImage() method to set the URL with different parameters (item.imageurl) \r\n* URL for the page thumbnail (item.thumburl)\r\n\r\nTo create an item object, use the item() call with collection alias and CONTENTdm item number:\r\n\r\n >>>letter = pycdm.item('leighhunt', '1566')\r\n\r\nThis is a document type compound object:\r\n\r\n >>>letter\r\n \r\n\r\nShow the title of the item:\r\n\r\n >>>letter.info['title']\r\n u'Colburn Mayne letter to Leigh Hunt, September 30, 1850s'\r\n\r\nShow the reference URL for the item: \r\n\r\n >>> letter.refurl\r\n 'http://digital.lib.uiowa.edu/cdm/ref/collection/leighhunt/id/1566'\r\n\r\n####Pages\r\nCreating an item object in pycdm also creates page objects for each page of the item. This includes some basic metadata for each page: \r\n\r\n* CONTENTdm identifier (.id)\r\n* the page label (.label)\r\n* the page's parent (item) identifier (.parentId)\r\n* the pages parent node title (.parentnodetitle, defaults to parent item title if no parent node)\r\n* the reference URL for the item (item.refurl)\r\n* URL for the stored file for the page (item.fileurl)\r\n* URL for the default scaled/cropped JPEG image of a page image. Use the GetImage() method to set the URL with different parameters (item.imageurl) \r\n* URL for the page thumbnail (item.thumburl)\r\n\r\nIncluding the \"pageinfo='on'\" attribute in the item() call will retrieve all of its pages' record and Dublin Core metadata as well. (The default is \"pageinfo='off'\" to reduce unneccessary calls to the API): \r\n\r\n >>>letter = pycdm.item('leighhunt', '1566', pageinfo='on')\r\n\r\nShow the page labels for each page of the letter:\r\n\r\n >>> for p in letter.pages:\r\n p.label\r\n u'Page1'\r\n u'Page2'\r\n u'Page3'\r\n u'Page4'\r\n\r\nPrint the page transcriptions for each page of the letter:\r\n\r\n >>> for p in letter.pages:\r\n print p.label + ': ' + p.info['transc']\r\n \r\n Page1: September 30th \r\n\r\n Dear Sir \r\n\r\n Your kind letter followed me to the Co Wicklow, & reached, this morning, the Vicarage, where I am passing Michaelmas with my Brother in law a Church of England clergyman, attending church & was regularly as though I held all the Church of England doctrines; it was therefore the more refreshing to receive your few lines & learn from them that you were not displeased with my letter; In\r\n \r\n Page2: the strangers land the language we are familiar with sounds the sweetest, & I own that orthodoxy, however moderate, (as it is here) seems to cramp & restrain my feelings; I long to breathe a freer air, or to get into a Corner with a \"Book for a Corner\" that may send my thoughts abroad in sympathy with human nature in all its varying phases. I grieve to learn that you have been unwell, yet, as long as the mind preserves its [ ? ], & the spirits their freshness, bodily weakness may be borne cheerfully, as it is, I am certain by you. I am glad you will read my novel; you will see how carelessly it has been\r\n \r\n Page3: sent through the press, the truth is the publisher had no one to correct the proofs, & the thing was so new to me that my corrections but little improved them. this & other faults of the letter I trust you will not condemn, rather not condemn the books on their account, but look only to the Spirit in which there is I think something to please you. You will notice too that the feelings which prompted me to seek an interview with you at Hammersmith are of no recent date or hasty growth, & I trust the last chapter will not Cause you to dislike my hero & heroine for their taste in literature.\r\n \r\n Page4: I must not trespass longer on\r\n Your time and remain \r\n Dear Sir \r\n Yours very faithfully \r\n Colburne Mayne \r\n\r\n### Working with collections and metadata fields\r\n#### Collections\r\nCreating an item instance also creates a corresponding collection object. A collection object's attributes include: \r\n\r\n* the collection alias (.alias)\r\n* the collection name (.name)\r\n* the URL for the digital collection (.url)\r\n* the collection's metadata fields (.fields, a Python dict of field objects, where key=field nickname)\r\n* the collection field mappings to Dublin Core (.dcmap, a Python dict, where key=field nickname)\r\n\r\nShow an item's full collection name: \r\n\r\n >>>leighhunt = letter.collection #first put the item's collection attribute into a variable\r\n >>>leighhunt.name #then call the name attribute on the collection object \r\n u'Leigh Hunt Letters'\r\n\r\n >>>letter.collection.name #this works too\r\n u'Leigh Hunt Letters'\r\n\r\nYou can also create a collection object directly:\r\n\r\n >>>leighhunt = pycdm.Collection('leighhunt')\r\n\r\nCalling the getItems() method on the collection will retrieve a list of all items identifiers in the collection and put it in the .item attribute:\r\n\r\n >>>leighhunt.getItems()\r\n >>>leighhunt.items\r\n ['51', '58', '63', '71', '76', '84', '89', '94', '99', '105', '110', '115', '125 ', '128', '141', '152', '156', '161', '166', '169', '173', '177', '183', '185', '194', '196', '199', '203', '206', '211', '214', '218', '223', '228', '262', '267', '272', '274', '277', '279', '283', '288', '294', '298', '303', '308', '311', '316', '321', '325', '330', '335', '339', '340', '344', '350', '355', '359', '362', '367', '370', '374', '379', '383', '388', '394', '399', '404', '409', '413'...]\r\n\r\nNow you can iterate through every item in your collection (beware, this is A LOT of API calls):\r\n\r\n >>>for i in leighhunt.items:\r\n item = pycdm.item('leighhunt', i)\r\n\r\nBut maybe you just wanted to generate a list of all reference urls in the collection:\r\n\r\n >>>for i in leighhunt.items:\r\n print \"http://digital.lib.uiowa.edu/cdm/ref/collection/leighhunt/id/\" + i\r\n\r\n\r\n####Fields\r\nWhen a collection object is created, field objects are created for each of its metadata fields. Fields have full names and nicknames. When working with the API, nicknames are required for requesting field information in calls, but these nicknames can be hard to find within the admin interface. You can list all of the nicknames of field objects in a collection with Collection.fields, but that's not very readable:\r\n\r\n >>> leighhunt.fields\r\n {u'fullrs': , u'relati': , u'contac': , u'cited': , u'number': , u'dmrecord': , u'transd': , u'archiv': , u'oclc': , u'file': , u'topica': , u'topicb': , u'transa': , u'numbea': , u'transc': , u'creato': , u'subjec': , u'rights': , u'dmoclcno': , u'title': , u'publis': , u'find': , u'note': , u'source': , u'transb': , u'typa': , u'contri': , u'typb': , u'type': , u'descri': , u'promo': , u'object': , u'locati': , u'colleb': , u'collea': , u'date': , u'data': , u'dmmodified': , u'dmcreated': , u'catalo': , u'chrono': , u'corpor': , u'digitx': , u'upload': , u'place': , u'digiti': , u'width': }\r\n\r\nListing just the nicknames by using .keys() makes this a little more readable:\r\n\r\n >>>leighhunt.fields.keys()\r\n [u'fullrs', u'relati', u'contac', u'cited', u'number', u'dmrecord', u'transd', u'archiv', u'oclc', u'file', u'topica', u'topicb', u'transa', u'numbea', u'transc', u'creato', u'subjec', u'rights', u'dmoclcno', u'title', u'publis', u'find', u'note', u'source', u'transb', u'typa', u'contri', u'typb', u'type', u'descri', u'promo', u'object', u'locati', u'colleb', u'collea', u'date', u'data', u'dmmodified', u'dmcreated', u'catalo', u'chrono', u'corpor', u'digitx', u'upload', u'place', u'digiti', u'width']\r\n\r\nBut this still doesn't show us the corresponding full names of each field. \r\n\r\nBy looking into the field objects, we can learn more about a collection's fields. Attributes of fields include: \r\n\r\n* the alias of the collection (.alias)\r\n* the CDM nickname of the field (.nick)\r\n* the Dublin Core mapping of the field (.dc)\r\n* obligation of the field, where required=1 (.req)\r\n* if the field is hidden, hidden=1 (.hide)\r\n* if the field is indexed, search=1 (.search)\r\n* if the field has controlled vocabulary, vocab=1 (.vocab)\r\n* a list of the field's controlled vocabulary terms (.vocabterms)\r\n\r\nShow the nickname and full name of each field (we'll sort them, too) for :\r\n\r\n >>> for k, v in sorted(leighhunt.fields.items()):\r\n print k + \": \" + v.name\r\n \r\n archiv: Archival Collection\r\n catalo: Cataloged by\r\n chrono: Chronological Subject\r\n cited: Letter Published In\r\n collea: Collection Guide\r\n colleb: Collection Identifier\r\n contac: Contact Information\r\n contri: Contributing Institution\r\n corpor: Corporate Name Subject\r\n creato: Creator\r\n data: Date Digital\r\n date: Date Original\r\n descri: Description\r\n digiti: Digitization Specifications\r\n digitx: Digital Collection\r\n dmcreated: Date created\r\n dmmodified: Date modified\r\n dmoclcno: OCLC number\r\n dmrecord: CONTENTdm number\r\n ...\r\n\r\nWe can also find the full name of a field from the collection object. List the full name of the 'date' field:\r\n\r\n >>> leighhunt.fields['date'].name\r\n u'Date Original'\r\n\r\nOr the DC mapping. Get the Dublin Core mapping of the 'Topical Subject (LCSH)' ('topica') field:\r\n\r\n >>> leighhunt.dcmap['topica']\r\n u'subjec'\r\n\r\n###CSV\r\nWorking with Unicode in Python is such a pain, isn't it? And much of the work you'll do with this library might involve dumping metadata into a CSV file in perfect UTF-8. The CSV object makes this a little easier by putting the work of creating a Unicode CSV writer in the library, so you dont have to.\r\n\r\nCreate a new CSV file to write to. Include a name for your file and a header row (optional):\r\n\r\n >>>f = pycdm.CSV('myfile.csv', header=['foo', 'bar', 'one', 'two'])\r\n\r\nThen do your stuff. To write a row of data to the csv file (where row = [your, list, of, values]:\r\n\r\n >>>f.writerow(row)\r\n\r\nDon't forget to close your file when you're finished:\r\n\r\n >>>f.close()\r\n\r\n###A word of caution!\r\nIf you haven't ever worked with the API or you don't manage your CONTENTdm server, please have a heart-to-heart with your sysadmin before you begin. Once you start working with many items or collections at once, it's very easy to generate many API calls, possibly enough to help crash your server. Your sysadmin can help you hack responsibly or give you the keys to a test instance. \r\n\r\n# License\r\n\r\nCopyright \u00a9 2012 Shawn Averkamp \r\n\r\nThis program is free software: you can redistribute it and/or modify\r\nit under the terms of the GNU General Public License as published by\r\nthe Free Software Foundation, either version 3 of the License, or\r\n(at your option) any later version.\r\n\r\nThis program is distributed in the hope that it will be useful,\r\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\r\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\nGNU General Public License for more details.\r\n\r\nYou should have received a copy of the GNU General Public License\r\nalong with this program. If not, see .\r\n\r\n# Contributors\r\n\r\nThanks to Chad Nelson (bibliotechy) for help with dmGetCollections() and dmQuery().", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/pycdm", "keywords": null, "license": "GNU General Public License, version 3.0", "maintainer": null, "maintainer_email": null, "name": "Pycdm", "package_url": "https://pypi.org/project/Pycdm/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/Pycdm/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/pycdm" }, "release_url": "https://pypi.org/project/Pycdm/0.2/", "requires_dist": null, "requires_python": null, "summary": "UNKNOWN", "version": "0.2" }, "last_serial": 1016131, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "cf9543a41de2b1c4b7be2603bd88f5b2", "sha256": "50cfc28d34f1a5771c75dcbaf279ce0f8102a226bb4f43e8bfd3888ded40ca48" }, "downloads": -1, "filename": "Pycdm-0.1.zip", "has_sig": false, "md5_digest": "cf9543a41de2b1c4b7be2603bd88f5b2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8004, "upload_time": "2012-11-01T20:23:28", "url": "https://files.pythonhosted.org/packages/7d/80/d7ecd948211981ac96de8218504126fe9792b42431da3212e8124eaff12a/Pycdm-0.1.zip" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "c8a2acea0c365c5558d7cad7f4d790c7", "sha256": "ae9a4163e6d5a8d1e668826086f2ead571a571a630fe0e0c079c0d73871664de" }, "downloads": -1, "filename": "Pycdm-0.1.1.zip", "has_sig": false, "md5_digest": "c8a2acea0c365c5558d7cad7f4d790c7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8012, "upload_time": "2012-12-12T16:15:38", "url": "https://files.pythonhosted.org/packages/80/58/987765a16a895422cea4091131aa83a0e00b2cffca63cec0cd9018e2647b/Pycdm-0.1.1.zip" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "fa39c34e24be70e198cabe359d0bce1f", "sha256": "279de2ddfcd859d3da26d46cebbd66f76f9b9f1314d4c230db5619c2bcd0d3ae" }, "downloads": -1, "filename": "Pycdm-0.1.2.zip", "has_sig": false, "md5_digest": "fa39c34e24be70e198cabe359d0bce1f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8027, "upload_time": "2013-01-31T18:45:11", "url": "https://files.pythonhosted.org/packages/62/a8/228cca37c13dc6a30e529de13eb475bf33d567d031ec253fe821cc8d235b/Pycdm-0.1.2.zip" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "8f71ccc71f0645989010ab3f5a73bbfd", "sha256": "16b936047f8374e2941422bbc03bddad648f6dcf280e01582fc9c72291682965" }, "downloads": -1, "filename": "Pycdm-0.1.3.zip", "has_sig": false, "md5_digest": "8f71ccc71f0645989010ab3f5a73bbfd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8803, "upload_time": "2013-02-07T16:08:22", "url": "https://files.pythonhosted.org/packages/3a/56/ee5ade8a937929101554b9edcd1be47fb8c4d56398ed19cf6211ed24bc63/Pycdm-0.1.3.zip" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "163f785972946e66c4392c25eeed1eef", "sha256": "24d219b379bbea9c1769c10a47b0743bcce7dd4b8e09f0cd06a6c3aee3ffe5f2" }, "downloads": -1, "filename": "Pycdm-0.1.4.zip", "has_sig": false, "md5_digest": "163f785972946e66c4392c25eeed1eef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8954, "upload_time": "2013-06-24T22:05:03", "url": "https://files.pythonhosted.org/packages/d0/7c/daf0b750015dc420b7404a6be263ffaca876c05a8c048787ddf3a72f20e8/Pycdm-0.1.4.zip" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "640205c3dedf41e4f25430e60c87af0f", "sha256": "cdccc041380a2cc773b8230a4cd9306f4e456430295e03ff2ff45aee8a32425a" }, "downloads": -1, "filename": "Pycdm-0.2.tar.gz", "has_sig": false, "md5_digest": "640205c3dedf41e4f25430e60c87af0f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15764, "upload_time": "2014-03-02T04:10:40", "url": "https://files.pythonhosted.org/packages/23/b0/7f5f74a943f939c20318f1f9fc8e8449a0ae305f8241f35962e37c73d3a8/Pycdm-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "640205c3dedf41e4f25430e60c87af0f", "sha256": "cdccc041380a2cc773b8230a4cd9306f4e456430295e03ff2ff45aee8a32425a" }, "downloads": -1, "filename": "Pycdm-0.2.tar.gz", "has_sig": false, "md5_digest": "640205c3dedf41e4f25430e60c87af0f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15764, "upload_time": "2014-03-02T04:10:40", "url": "https://files.pythonhosted.org/packages/23/b0/7f5f74a943f939c20318f1f9fc8e8449a0ae305f8241f35962e37c73d3a8/Pycdm-0.2.tar.gz" } ] }