I created a nice commandline utility a while back for automating the process of creating a Django project template. Since doing so, Django 1.4 arrived which added similar functionality but my script takes project creation a step further.
What is so cool about this script:
- A commandline wizard with pretty colors!
- Bash autocomplete command called mkdjango (like mkdir but for Django)
- Pick from the 4 of the most common server setups which will auto generate the configuration files needed.
- Use your own project template (if mine isn't good enough! :p )
Installation:
Checkout the code here: Django Base
Leave a comment
Django on Mac OS X (10.7) has never been easier.
- Install Xcode which can be found on the Mac App Store. Grab some coffee for it will take a while if you don't already have it installed.
-
Install the database of your choice:
MySQL Server
MySQL can be downloaded here:
http://dev.mysql.com/downloads/
Be prepared to click through layers of links and a registration nag to join their community just to get to a actual download link. Very Lame MySQL!
Also take note that MySQL will be a pain to setup and you should avoid pains at all cost!
First issue: MySQL's installer is so ghetto that it does not SymLink it's own executable to /usr/bin/ for commandline usage. So here is the command to do this manually.
| sudo ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
sudo ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin
|
PostgresSQL Server
You can download postgres here (no link trickery):
http://www.postgresql.org/download/macosx/
Amazingly enough, PostgresSQL comes with an awesome installer and will even install PostGIS for you.
Oh wait, no complaints?!? Yep, it just works. Moving on..
-
Install Python libraries.
Prerequisites for the python imaging library
JPEG Library
| curl -O http://www.ijg.org/files/jpegsrc.v8c.tar.gz
tar -xvzf jpegsrc.v8c.tar.gz
cd jpeg-8c
./confgure
make
sudo make install
|
Free Type Library
| curl -O http://ftp.igh.cnrs.fr/pub/nongnu/freetype/freetype-2.4.5.tar.gz
tar -xvzf freetype-2.4.5.tar.gz
cd freetype-2.4.5
./configure
make
sudo make install
|
Install PIP, a better way of finding and downloading Python packages. Also install VirtualEnv, a nice way to isolate dependencies on a per project basis.
| sudo python easy_install pip VirtualEnv
|
Now lets install Django and PIL (You might want to consider virtualenv at this point).
MYSQL Python Client - You can clearly skip this section since you realized early on your mistake in considering mysql but if you haven't your mistake yet continue on.
Oh wait, before we start, I have to set an Environment variable or this library won't install?!! Ok its time to switch to a real database like PostgreSQL (instructions below).
| export DYLD_LIBRARY_PATH='$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/'
|
In some cases it my be helpful to place the mysql bin directory on your path
| export PATH=/usr/local/bin:/usr/local/mysql/bin/:$PATH
|
Now you can pip install
If you are still having problems installing mysql and you haven't decided to switch to Postgres at this point, you can always install from source. Select a version HERE then follow the steps below:
Download and unpack mysql-python:
| tar -xvzf MySQL-python-x.x.x.tar.gz
cd MySQL-python-x.x.x
|
Make sure to edit and change the mysql_config variable under site.cfg to point to:
| mysql_config = /usr/local/mysql/bin/mysql_config
|
Install mysql-python
Lastly, check that mysql-python did in fact install correctly
| python -c "import MySQLdb"
|
PostgreSQL Python Client - Wait, that's it? Glad you chose to switch?!
And that is it. enjoy!
Leave a comment
Below are a few simple steps for submitting Python packages to the Package Index.
1) Create a setup.py file:
| from setuptools import find_packages, setup
setup(name='python-awesome-package',
install_requires=('required_packages_here',),
author='Me',
author_email='me@example.com',
version='x.x.x',
packages = find_packages(),
license="BSD"
)
|
2) Build the source distribution.
3) Register for an account or login using an existing account.
4) Upload the package.
| python setup.py sdist upload
|
That's it!
Leave a comment
Last week I updated Python-TwiPic to API v2.0. TwitPic announced that they will continue supporting the old version, however, I recommend upgrading to the latest and greatest. Version 2.0 addresses some security concerns and comes with tons more functionality than the previous.
A while back Twitter introduced an extension to oAuth called Echo oAuth. In short, it's a way to provide a Twitter access_token to the media provider (TwitPic) instead of providing a username and password. As you may already know, TwitPic introduced more than photo uploading to their API. Now you can leave comments group and assign photos to events, and tag faces in a photo. I personally am only using TwitPic to upload photos but the extra features could be nice depending on your intentions.
The only request methods that TwitPic currently accepts are GET and POST. In this library, I chose to break up the method request calls into the four main RESTful request groups GET, PUT, POST, DELETE. Each request method belongs to a RESTful request group depending on it's function. Below is an example use case. You must first choose the appropriate method which is either: read, create, update, or remove. Then you pass a method the method call name and a dictionary of parameters (not including a service key). Seems pretty straightforward I hope. Also keep in mind that you are responsible for getting a user's access_token and should be passed as a string which I believe is fairly standard practice.
Usage:
| import twitpic2
twitpic = twitpic2.TwitPicOAuthClient(
consumer_key = CONSUMER_KEY,
consumer_secret = CONSUMER_SECRET,
access_token = ACCESS_TOKEN,
service_key = SERVICE_KEY
)
# methods - read, create, update, remove
response = twitpic.create(METHOD_CALL, PARAMS)
|
If you find any bugs please create a ticket so that I can fix them.
Leave a comment
I have been in need of a video thumbnailer for some time now and so I decided to create a proof of concept django model field that does just that. Note that since this is just a proof of concept project, I don't recommend using this in a production settings. This project is based heavily on the django-thumbs project but for videos instead. In order to create thumbnails for videos we must first extract a frame.
Extracting a frame can be done by using FFMpeg. The main problem is that the python FFMpeg libraries that currently exist are broken and have been for some time now. pyFFMpeg is getting a rewrite but it appears that it won't be ready anytime soon. As a quick hack, I simply pipe out to the command line and extract a group of frames. From there I find which frame has the most color and proceed with thumbnailing that frame. In case you were wondering, some videos contain black frames at the begin of the movie so instead of taking the very first frame, I take a sample of frames and find the frame with the most color.
For obvious reasons, this is NOT the best solution. In the future, if/when I get the time I plan on experimenting with ctypes since its a standard library that ships with python 2.5+. If you have any questions or would like to help please contact me.
Here is the Project Location.
Leave a comment