Amara recipe index
This page provides pointers to useful examples of Amara 2.x usage, some on this wiki and some elsewhere on the Web. Please add any you find or post yourself. Don't forget these useful resources:
Amara/Tutorial - The tutorial
Amara/Whatsnew - Differences between Amara 1.x and 2.x
Amara/QuickRef - Quick reference
Use Google's feed history feature as a universal feed tool (besides maintaining history it converts feeds to Atom)
Amara1/Recipes/Google_Web_feed_atomizer
Scrape the topics out of New York Times and emit them as SKOS.
Based on http://inkdroid.org/journal/2009/08/18/new-york-times-topics-as-skos/
Note: the site changes a lot, so the recipe may need tweaking when it does. Screen scraping's treacherous like that
Update an XML file with parameters drawn from a separate text file
Subclassing/specializing Amara nodes. See: "Creating custom binding class for renaming nodes"
Snippets
This section has tiny (generally 5 lines or so) recipes designed to illustrate how simple some common tasks can be in Amara. Some even have "tweetable" variations of under 140 characters (on one line). Twitter is poor technology but everyone is doing it.
Generate a set of all the unique categories in an Atom document, using scheme as a namespace, in James Clark notation:
import sys
from amara import bindery
doc = bindery.parse(U)
print set([ u"{%s}%s"%(unicode(c.scheme), unicode(c.term)) for e in doc.feed.entry for c in e.category ])
Sample usage (if saved as atom_cats.py):
curl http://diveintopython3.org/examples/feed.xml | python atom_cats.py
Generate an abbreviated version of an XML file, with text nodes truncated in order to focus on element/attribute structure.
import sys, amara
doc = amara.parse(sys.stdin)
for t in doc.xml_select("//text()"):
t.xml_value = t.xml_value[:10]
doc.xml_write()
Sample usage (if saved as abbreviator.py):
curl "http://clinicaltrials.gov/show/NCT00684658?displayxml=true" | python abbreviator.py
Tweetable equivalent:
import sys, amara; doc = amara.parse(sys.stdin); for t in doc.xml_select("//text()"): t.xml_value = t.xml_value[:10]; doc.xml_write()
Dispatch XML docs to handler functions based on their root elements:
FWIW in Amara Bindery you can do something like:
from amara import bindery
doc = bindery.parse(the_data)
top_elem = doc.xml_elements.next()
deleg = getattr(self, 'elem_' + str(top_elem.xml_qname))
deleg(doc)
Recipe requests
If you have ideas for others to build into demos and recipes, put them here: Akara/Ideas
