Tuesday, September 30, 2008

Foto's downloaden van mijnalbum.nl

[edit 21-10-2008: album-id meegeven vanaf command line]

Update 12-09-2015: Dit scriptje is overbodig geworden omdat mijnalbum.nl nu een knop heeft waarmee je het hele album kunt downloaden. Klik op "Foto's opslaan",  dan op "Album downloaden".

Mijnalbum.nl is een site waar je foto's kan neerzetten. Het enige nadeel is dat deze foto's alleen te bekijken zijn via de site, dat is wat onhandig bladeren. Het zou dan ook fijner zijn alle foto's in een keer te downloaden, zodat je er op je gemak doorheen kunt bladeren. Gelukkig hebben ze dat niet al te moeilijk gemaakt: leve python en de lxml-module!
#!/usr/bin/python

import sys
from lxml import etree
from lxml import objectify
from urllib import urlopen

# pass the album id as a command line argument
album_id = sys.argv[1]
thumbs_url = 'http://www.mijnalbum.nl/index.php?m=albumview&a=2&key='
thumbs_url += album_id

parser = etree.HTMLParser()
page = urlopen(thumbs_url)
html = page.read()

htmltree  = etree.HTML(html)

for element in htmltree.xpath("body/table/tr/td[@class='thumbfoto']"):
    id = element.get('id')
    to_be_stripped = 'thumbcont-'
    foto_id = id.replace(to_be_stripped,'',1)
    foto_url = 'http://www.mijnalbum.nl/GroteFoto-'+foto_id+'.jpg'
    print foto_url

# Just pass the output to wget using "| xargs wget".

Dit maakte het downloaden van alle foto's van de Ronde van Winsum een stuk makkelijker. Hieronder is een sleutelmoment in deze legendarisch ronde te zien.

Sunday, September 28, 2008

Stand Eredivisie

Een mooi plaatje om te bewaren:

Friday, September 26, 2008

Using base_class tag instead of drawing lines in UML

When you're extending one class many time, and all the lines are cluttering up your UML model, you can use the tag base_class on the extending classes instead of a line.

Thursday, September 25, 2008

i18ndude says "No entries for domain" when you pass filenames

If you pass a new version i18ndude a filename or filetype, it will say "No entries for domain".

See
http://plone.org/products/i18ndude/i18ndudetracker/20

Define a RecordsField through UML (Archgenxml 2.1)

In Archgenxml 1.5, a field called "record" or "records" would be converted to a RecordsField. Somewhere between 1.5 and 2.1, this functionality was broken. In current agx, you may define a RecordsField as a stub in a separate stub package "fields" like so:

Set import_from=Products.ATExtensions.field.records, and make sure to add the "dependency" lines. You will probably also want the accompanying widget, see the model below. Import the widget from Products.ATExtensions.widget
There is a difference between a RecordField/RecordWidget and a RecordsField/RecordsWidget, to use a RecordField import it from Products.ATExtensions.field.records

After having done this, you may define a field of type Record(s)field, and set a tagged value widget=RecordsWidget (or RecordWidget).

Wednesday, September 24, 2008

Extracting information from CVS

CVS history:
cvs history -acf path/to/file | sort

By default, CVS will not show it for all users (a) and also not on all modifications (commits, c). The results are not always in chronological order, so sort them.

CVS log prints the information that was entered to describe the update:
cvs log path/to/file


To compare to another revision:
cvs diff -r 1.44 -r 1.45 path/to/file

Saturday, September 20, 2008

Goldmund, Wyldebeast & Wunderfahrrad

Sommigen hebben een auto van de zaak, bij Goldmund, Wyldebeast & Wunderliebe doen we niet mee aan die gekkigheid. CO2-neutraal en bevorderlijk voor des werknemers welbevinden worden er bedrijfsfietsen uitgedeeld.

Uitslag Ronde van Winsum 13 september 2008

Heren
1. Wilfred van Holst
2. Peter Wolters
3. Henk Bakker
4. Arend Mulder
5. Kees Hink
6. Sybren Mulder
7. Jaap
8. Paul Boon
de rest DNF

Dames
1. Chantal
2. Marieke Falkmann
3. Frenke Bolt

Dit zijn de uitslagen van de etappe, er was ook nog een proloog, maar voor de heren is de klassering ongewijzigd.

Zie verder de hyve.

Thursday, September 18, 2008

Setting a field value by its fieldname (Archetypes)

Suppose you have a long list of fieldnames that you want to change on an Archetypes content type. You might want to do obj.setField1(), obj.setField2() etc. for all these fields, but it would be nicer to pass in a list of fieldnames. This is possible on Archetypes content types as follows:

# the fields to be set are in a dictionary adres_dict
for fieldname in adres_dict.keys():
# value to be set on the field
value = adres_dict[fieldname]
# get the field from the schema
field = obj.Schema().getField(fieldname)
# get the mutator name
mutator = field.mutator
# get the mutator function
func = getattr(obj, mutator)
# set the value using the mutator function
func(value)
print " Inserted value %s into field %s" % (value,fieldname,)

Tuesday, September 2, 2008

archgenxml + i18ndude + Plone 2.5: AttributeError: 'GlobalAdapterRegistry' object has no attribute '_null'

A small addition to the last post, intended for use with Plone 2.5:

When i run archgenxml on a Plone 2.5 project (i set PYTHONPATH to my Zope 2.9.9's lib/python),
i got this error: AttributeError: 'GlobalAdapterRegistry' object has no attribute '_null'
(see http://paste.plone.org/23497)

I am running archgenxml + i18ndude from a virtualenv, to prevent corrupting my Zope libraries
with i18ndude's eggs. Before easy_installing i18ndude, it worked fine. For Zope 2.10.6, it still
works fine.

Removing from my virtualenv the extra eggs that i18ndude pulled in (zope.testing-3.6.0-py2.4.egg,
zope.interface-3.4.1-py2.4-linux-x86_64.egg, zope.tal-3.5.0-py2.4.egg) made it work.

(googling yields http://zope3.pov.lt/irclogs/%23zope3-dev.2006-09-22.log.html, not sure if it's
related)