Archive for the 'Python' Category
A simple Django life stream
Published Thu Jul 2008 inAfter reading Ryan Bergs' "The basics of creating a tumblelog with Django" (part1) and (part2), I realized that I wanted a similar tumblog/life stream but I didn't want to have to go through all the work of saving those objects to the database. After all, isn't all that data already stored in their respective systems. And since I am using FriendFeed, which is again duplicating all that data, I don't want to be duplicating it yet another time.
That's when the light bulb went off. Using the FriendFeed API and a bit of caching I can pull in my lifestream from FriendFeed using only a custom tag. So I came up with what I call lifefeed Just add "lifefeed" to your installed apps and you can now do this from any template
{% load lifefeed %}{% load cache %}
{% cache 900 friendfeed %}
{% lifefeed "YOUR FRIEND FEED USERNAME" %}
{% endcache %}
- Consolidate duplicate twitter/pownce/brightkite posts
- Display FriendFeed comments
Intense Debate Import Hack
Published Thu Jun 2008 in
Recently I wanted to try out the Intense Debate commenting system on this blog. I didn't want to lose all the comments that I had already and Intense Debate only supports importing comments from Blogger, etc but not custom blog software. Since I wrote this blog using the Django framework using django.contrib.comments I needed to come up with my own solution.
It only took one Tamper Data request to see how an anonymous comment was posted into the Intense Debate system. A few minutes later I had a script to import my old comments into Intense Debate.
import intenseDebate
intenseDebate.postComment(blogpostid="", acctid="", anonName="", anonEmail="", \
anonURL="", comment="")
- blogpostid is the unique Intense Debate postId. You can find this easily on any Intense Debate powered page using the firebug dom tab. The key to look for is "IDCommentScript".
- acctid is your Intense Debate accountId. This can also be found using the firebug dom tab. The key to look for is "IDWUserWidget.acctid"
- anonName is the name of the commenter
- anonEmail is the commenters email address
- anonURL is the commenters web address
- comment is the text of the comment
This method of importing comments does have it's problems.
- Manual process to get the blogpostid.
- No way of getting the Date/Time into Intense Debate.
Footnote: I don't have a problem with Django comments, especially when paired with django-comment-utils, I just wanted to give Intense Debate a try.
Django server side file selector
Published Wed Sep 2005 inNote: This is no longer valid. You can now use the meta.FilePathField that is built into Django like this
fieldName = meta.FilePathField(path='/path/to/files', match='re_string', recursive=True)
videoUrl = meta.ServerFileField('/home/user/video')
from django.core import meta
import os
videoDir = '/home/jay/video'
files = os.listdir(videoDir)
theList = []
for f in files:
if os.path.isfile(os.path.join(videoDir,f)):
theList.append(tuple([os.path.join(videoDir,f), f]))
videoChoices = tuple(theList)
class Message(meta.Model):
def __repr__(self):
return self.name
title = meta.CharField(maxlength=200)
video = meta.CharField(maxlength=200, help_text='Select the video', choices=videoChoices ,blank=True)
...
Django and Xinha
Published Fri Jul 2005 inAfter I posted about Django and TinyMce someone on IRC mentioned Xinha. I had not heard of or used Xinha before, so I thought I would give it a shot. Xinha has some really nice features that are not found in TinyMce, however I was a little bit disappointed at the extra configuration that Xinha required. TinyMce also just seemed a bit more polished.
Note that in order to get this to work I had to specify to Xinha the id's of the textarea's that I wanted to be wysiwyg editors. TinyMce was much more flexible in that it can convert every textarea on the page to a wysiwyg editro_editor_url = "/media/js/xinha/"; _editor_lang = "en";
xinha_editors = null;
xinha_init = null;
xinha_config = null;
xinha_plugins = null;
// This contains the names of textareas we will make into Xinha editors
xinha_init = xinha_init ? xinha_init : function()
{
xinha_plugins = xinha_plugins ? xinha_plugins :
[
'CharacterMap',
'ContextMenu',
'FullScreen',
'ListType',
'SpellChecker',
'Stylist',
'SuperClean',
'TableOperations'
];
// THIS BIT OF JAVASCRIPT LOADS THE PLUGINS, NO TOUCHING :)
if(!HTMLArea.loadPlugins(xinha_plugins, xinha_init)) return;
xinha_editors = xinha_editors ? xinha_editors :
[
'id_description'
];
xinha_config = xinha_config ? xinha_config() : new HTMLArea.Config();
xinha_editors = HTMLArea.makeEditors(xinha_editors, xinha_config, xinha_plugins);
HTMLArea.startEditors(xinha_editors);
}
window.onload = xinha_init;
js = ('/media/js/xinha/init.js','/media/js/xinha/htmlarea.js','/media/js/xinha/description.js'),
meta.TextField('description'),
To change a field of a different id, modify the xinha_editors in the description.js and probably change that files name.
Django on Dreamhost
Published Wed Jul 2005 inAfter lots of googleing and some late night IRC chats I have Django installed and fully working on Dreamhost. The full how to is posted on the Dreamhost Wiki
Django and TinyMce
Published Wed Jul 2005 inI have been experimenting with the Django web framework for the past few days and it is great. It is easy to learn, and what it produces from the amount of code you input is staggaring.
One thing I did find lacking was lack of a wysisyg input field. meta.TextField works great but sometimes users need a little more. At first I wanted to create a meta.HtmlField but after some more thought you can achieve the same results with a meta.TextField and the admin.js param. Before I get into the code here is a screenshot of what we will achieve.
Here's how:
First you will need to download the TinyMce code from http://tinymce.moxiecode.com/download.php
Extract that to somewhere on your system. I used /Users/jay/Sites/javascript
Next you will need to link the TinyMce code into the Django media directory
ln -s /Users/jay/javascript/tinymce/jscripts/tiny_mce /Users/jay/python/django/trunk/django/conf/admin_media/js/tiny_mce
djang-admin.py runserver --settings=myproject.settings.admin
tinyMCE.init({
mode : "textareas",
theme : "default"
});fields = (
meta.CharField('title','title',maxlength=200),
meta.TextField('description','description'),
meta.CharField('location','location',maxlength=200)
)
admin = meta.Admin(
fields = (
(None, {'fields': ('title','description','location')}),
),
js = ('/media/js/tiny_mce/tiny_mce.js','/media/js/tiny_mce/textareas.js'),
)
Upcoming.org Python Module
Published Sun May 2005 inI have just released a Python module for the Upcoming.org API. You can find it here. If you use it, please send all bugs, suggestions, patches to jay@socialistsoftware.com
Upcoming.org Modules
Published Sun May 2005 in
Python
Download 0.1
Example
import Upcoming
u = Upcoming.Upcoming('username', 'password', 'key')
events = u.searchForEvents('Shins')
for e in events:
print e.id + ' : ' + e.name
Output
14138 : The Shins
17314 : The Shins
17002 : The Shins
Upcoming.py Pydoc
ApiFilters.py Pydoc
Java
Download 0.3.
Example
import java.util.ArrayList;
import com.socialistsoftware.upcoming.*;
public class UpTest {
public static void main(String[] args) {
Upcoming up = new Upcoming("username", "password", "key");
ArrayList lists = up.getWatchlist();
for (int i = 0; i < lists.size(); i++){
Watchlist w = (Watchlist)lists.get(i);
String id = w.getEventId();
Event e = (Event)up.getEventInfo(id).get(0);
System.out.println(w.getEventId() + " : " + e.getName());
}
}
}
Output
12447 : The Decemberists, Okkervill River
14135 : Q and not U
15001 : Fiery Furnaces, Dios Malos
14138 : The Shins
15517 : Electric Six and VHS or Beta
15516 : Built to Spill
15515 : Built to Spill
15737 : The Mars Volta
17074 : ... And you Will Know Us by the Trail of the Dead w/ International Noise Conspiracy and We Are Wolves
17078 : Spoon w/ The Clientele
18294 : Maroon 5
18543 : Nuggets vs Spurs
19323 : testEventName
19449 : WeedenFete
The javadoc is here.
Latest
Xbox Live Gamercard
-
@alexgraves you will do that, yet I have to kill the bugs for you at home@betterelevation this vista is making me thirsty.I will be later to @refreshdenver than @kristoferbaxter
