Задать вопрос

Тел: +7 965 3737 888

618

Просмотров

6

Ответов

Flickr Sync

<p>This code provides a Django model for photos based on Flickr, as well as a script to perform a one-way sync between Flickr and a Django installation.
<em>Please note that the snipped contains code for two files, update.py and a Django model.</em>
<em>The two chunks are separated by:</em></p>
"""
END OF FLICKRUPDATE
"""

"""
START DJANGO PHOTO MODEL
Requires django-tagging (http://code.google.com/p/django-tagging/)
"""

<p>My model implements tagging in the form of the wonderful django-tagging app by Jonathan Buchanan, so be sure to install it before trying to use my model.</p>
<p>The flickrupdate.py code uses a modified version of flickerlib.py (http://code.google.com/p/flickrlib/).  Flickr returns invalid XML occasionally, which Python won't stand for.  I got around this by wrapping the return XML in &lt;flickr_root&gt; tags.</p>
<p>To modify flickrlib to work with my code, simply change the this line:</p>
return self.parseData(getattr(self._serverProxy, '.'.join(n))(kwargs))

<p>to:</p>
return self.parseData('&lt;flickr_root&gt;' + getattr(self._serverProxy, '.'.join(n))(kwargs) + '&lt;/flickr_root&gt;')

<p>I hate this workaround, but I can't control what Flickr returns.</p>
<p>flickrupdate will hadle the addition and deletion of photos, sets and tags.  It will also keep track of photos' pools, although, right now, it doesn't delete unused pools.  This is mostly because I don't care about unused pools hanging around.  It's a simple enough addition, so I'll probably add it when I have a need.</p>
<p>Be sure to set the appropriate information on these lines:</p>
api_key = "YOUR API KEY"
api_secret = "YOUR FLICKR SECRET"
flickr_uid = 'YOUR FLICKR USER ID'

<p>I hadn't seen a Django model and syncing script, so I threw these together.  I hope they will be useful to those wanting start syncing their photos.</p>

Вопрос полезен? Да0/Нет0
file_5113.py(18.7Кб)
None

Ответы (6):

Ответstranger1:07.03.2008
Ответ полезен? Да0/Нет0

Hi thank you for the great piece of code. i am new to django and I have installed this app. I am able to see the photo model in admin panel. but is there a way to sync the flickr automatically like cron job. I think the flickrupdate.py is one such but how to run that file. I tried $python flickrupdate.py but it gives me errors like Traceback (most recent call last): File "apps/photos/flickrupdate.py", line 8, in [HTML_REMOVED] from apps.photos.models import Photo ImportError: No module named apps.photos.models

After setting PYTHONPATH and DJANGO settings alos I get this ould not import settings 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings

Ответkbpeterson:26.02.2008
Ответ полезен? Да0/Нет0

Sorry my last comment left out the error: xmlrpclib.Fault: Fault 1: 'User not found'

Am I missing some kind of configuration?

Ответkbpeterson:26.02.2008
Ответ полезен? Да0/Нет0

Is there a typo in your version of flickrlib.py on line 109? I'm having a tough time getting this to work. I keep getting a fault in xmlrpclib: [HTML_REMOVED]. Any help would be greatly appreciated.

Ответbretwalker:03.11.2007
Ответ полезен? Да0/Нет0

I changed int to largeint, so it should work fine with MySQL now.

I also modified the first page load via the search api, rather than the recenltyupdated api.

I also updated the tag code. Thanks for the catch.

Unfortunately, if you delete a photo, there's no way to be notified via the API, so you have to do a full comparison between the Django database and Flickr.

Ответreid:07.10.2007
Ответ полезен? Да0/Нет0

importing tags seems to be broken (maybe flickr fixed their XML...)

return_data['tags'] = ",".join(["%s" % (d['text']) for d in photo_info['tags'][0]['tag'][0]])

should be

return_data['tags'] = ",".join(["%s" % (d['text']) for d in photo_info['tags'][0]['tag']])

Ответreid:07.10.2007
Ответ полезен? Да0/Нет0

I've been working to get this up and running on my site and I've noticed a few things that might be useful to others.