This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| Hack to look for user agent strings in typical Apache style log and | |
| count up the number of requests by bots vs non-bots. The list of bot | |
| user agents comes from http://www.user-agents.org/ but has had some | |
| agents added to it, since the user-agents.org list is pretty out of date, e.g. | |
| no Bing?! | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| Script to go through all the OAI-PMH records in the PubMedCentral database and | |
| print out a tab delimited list of record identifiers and a license url (if one | |
| is included). | |
| You'll need lxml installed to run this. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def words(filename): | |
| for line in open(filename): | |
| words = line.split(' ') | |
| for word in words: | |
| yield word | |
| for word in words('file.txt'): | |
| print word |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from tastypie import fields | |
| from tastypie.resources import ModelResource | |
| from tastypie.authorization import DjangoAuthorization | |
| from tastypie.authentication import ApiKeyAuthentication | |
| from tasty.pie.models import Book, Author | |
| class BookResource(ModelResource): | |
| authors = fields.ToManyField('tasty.pie.api.resources.AuthorResource', 'authors', full=True) | |
| class Meta: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import models | |
| class Book(models.Model): | |
| title = models.CharField(max_length=15) | |
| class Author(models.Model): | |
| name = models.CharField(max_length=255) | |
| book = models.ForeignKey('Book', related_name='authors') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EssayAdmin(VersionAdmin, ManyToManyAdmin): | |
| form = EssayForm | |
| # helper to put LCCNs mentioned in an essay into the list display | |
| def lccns(obj): | |
| links = [] | |
| for title in obj.subjects.all(): | |
| a = '<a href="http://chroniclingamerica.loc.gov/lccn/%s>%s</a>' % (title.lccn, title.lccn) | |
| links.append(a) | |
| return mark_safe(', '.join(links)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CampaignResource(ModelResource): | |
| work = fields.ForeignKey(WorkResource, 'work') | |
| class Meta: | |
| queryset = models.Campaign.objects.all() | |
| resource_name = 'campaign' | |
| excludes = ['amazon_receiver', 'paypal_receiver'] | |
| def override_urls(self): | |
| return [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> import microdata | |
| >>> import urllib | |
| >>> html = urllib.urlopen('http://lx6.loc.gov').read() | |
| >>> items = microdata.get_items(html) | |
| >>> print len(items) | |
| 30 | |
| >>> print items[0].tweet_time | |
| 2011-02-15 06:00 | |
| >>> print items[0].json() | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'bagit' | |
| bag = BagIt::Bag.new 'test-data' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ed@curry:~/Projects/bagit-ruby$ rake spec | |
| (in /home/ed/Projects/bagit-ruby) | |
| /usr/bin/ruby1.8 -S bundle exec rspec -fs --color spec/tag_info_spec.rb spec/manifest_spec.rb spec/validation_spec.rb spec/bagit_spec.rb spec/fetch_spec.rb | |
| Tag Info Files | |
| bagit.txt | |