Anyone working on any projects?

Study group dedicated to learning how to code in the Python language.

Moderators: snarkout, Patrick, dann

User avatar
riddlebox
Posts: 86
Joined: Mon Jul 03, 2006 2:09 pm
Contact:

Anyone working on any projects?

Post by riddlebox » Sun Apr 29, 2007 6:22 pm

I just wanted to know if anyone is working on anything, I would love to help. I have found that when I am working on something it is easier to learn different methods. I dont know if that is the best way, but it is what works for me. I am almost finished with a phonebook app that I had created as a menu system, I am converting it to a gui now.

User avatar
CptnObvious999
Posts: 798
Joined: Fri Jun 03, 2005 7:54 pm
Location: Maryland
Contact:

Post by CptnObvious999 » Sun Apr 29, 2007 6:52 pm

Cool, what GUI toolkit are you using? Care to share the code?

I have just started to make Mille Bornes clone in Python, only got a few lines done but hopefully I will have enough motivation to complete it. ;)

User avatar
Ryochan7
Posts: 99
Joined: Wed Dec 15, 2004 10:18 pm
Location: Peoria, IL
Contact:

Post by Ryochan7 » Mon Apr 30, 2007 12:58 am

The program that I have been working on that uses Python is StepMania Unlock Code Generator. The program is a GUI for making an Unlocks.dat file that can be used with the StepMania 3.9 unlock system to lock songs until a certain criteria is fulfilled (such as number of songs completed). For the GUI, I use PyGTK. I currently distribute the program for Linux and Windows and it has gotten a small user base in the StepMania community. You can read my latest blog entry if you want to find out more about the program, although I discuss version 0.2 in the post.

http://bored.homelinux.net/
Linux User #357977
LUGOP is awesome

User avatar
Vogateer
Posts: 700
Joined: Thu Nov 17, 2005 11:18 pm
Location: Norman, Oklahoma
Contact:

Post by Vogateer » Mon Apr 30, 2007 10:54 am

Wow, I feel weak, now. I'm just trying to write a script to handle Wordpress updates on my own server, and I'm already hung up on backing up the database. :oops:

I could probably make it a lot easier, but I wanted the database backup to be automatic, and to enter the password into something like mysqldump when using the command line interface, you have to use pexpect. You can probably do something similar with the mysql module for python, but pexpect looks like it could be helpful for a lot of little system administration scripts, so I'd really like to learn how to use it.
Vim is beautiful

User avatar
Jza
Posts: 466
Joined: Sun Oct 30, 2005 7:01 pm
Location: Mexico
Contact:

Post by Jza » Tue May 01, 2007 1:46 am

I was reading the oreily article on python 2.5 changes, is interesting that it has sqllite native support. This means that your code will depend on less dependencies (MySQLdb is not part of the base modules).

Since your app is small maybe a smaller db might be better and sqllite might be a better choice.

Also sqlite is not a daemon that you need to worry on running everytime you need to use it.

Code: Select all

import sqlite3
Here is the snippet from the article 'what is new in python 2.5':
SQLite Support for Simple SQL Data Storage

The sqlite3 module is an interface to the SQLite library. This library provides SQL access to a single file for data storage, and I find it to be extremely useful for storing small amounts of local data without the need for large external database systems. Here's a sample:

Code: Select all

import sqlite3
conn = sqlite3.connect('data.dat')
c = conn.cursor()
c.execute('''
   create table members(
       id int,
       name varchar,
       login timestamp
   )
''')
c.execute('''
   insert into members
   values (1,'jeff','2006-10-01')
''')
c.execute('''
   insert into members
   values (2,'angie','2006-10-02')
''')
c.execute('''
   insert into members
   values (3,'dylan','2006-10-03')
''')

res = c.execute('select * from members')
for row in res:
   print row
This code connects to a database (which is simply a file, data.dat), then creates a new table in the database using standard SQL CREATE TABLE syntax, then inserts data, again using standard SQL syntax. Then the code finally selects data from the table, again with SQL, and iterates through the selected data.

This module is especially useful for data that isn't big enough to justify a large database system, but is relational in nature and requires more than simple data types.
Basically is pretty simple way to work with the database, also the database is a file which is a good thing for portability. You just impor the module and then execute the sql command with the c.execute and badabim badaboom!!
Alexandro COLORADO

User avatar
Vogateer
Posts: 700
Joined: Thu Nov 17, 2005 11:18 pm
Location: Norman, Oklahoma
Contact:

Post by Vogateer » Tue May 01, 2007 8:17 am

That's brilliant! I like how simple the interface is to sqlite. I might use that some day.

The only thing is that I'm currently trying to backup a wordpress database, which is already running on MySQL. Bash scripting this sort of thing would be pretty easy, but I want to learn the ropes with Python.
Vim is beautiful

User avatar
TankCatNinjaFish
Posts: 110
Joined: Wed Aug 09, 2006 4:29 am

Post by TankCatNinjaFish » Tue May 01, 2007 2:34 pm

Vogateer wrote:That's brilliant! I like how simple the interface is to sqlite. I might use that some day.

The only thing is that I'm currently trying to backup a wordpress database, which is already running on MySQL. Bash scripting this sort of thing would be pretty easy, but I want to learn the ropes with Python.
You should just use shell out to mysqldump using the os.system (or some other similar) method.

<rant>
You'll often run into the situation where you want functionality of an external program and usually there are two basic options:a) read the API and do it directly from code, or b) fork a shell command.

Here's what I've learned:
1) When the command you wish to run has a lot of options, go with option a. For example, if you want to wrap the functionality of ImageMagick into your program, you'll want to use it's API because creating the shell command from hand is laborious, error-prone, and not very powerful.
2) When you need speed, go with option a. Sometimes the overhead of forking off an entire process is too slow. An extreme example of this is Perl CGI scripts vs using mod_perl.
3) If you need high-level communication with the external function, again go with option a. For example, intelligently handling exceptions/errors from forked processes is almost impossible.
4) On the other hand, if the particular method you need doesn't run very often and doesn't have many options, go with option b. A task like backing up a MySQL database is a perfect candidate b/c it'll only run daily/weekly/etc, has only a few (if any) options you need to control, and it's autonomous (you just start it and forget about it).
</rant>

User avatar
Vogateer
Posts: 700
Joined: Thu Nov 17, 2005 11:18 pm
Location: Norman, Oklahoma
Contact:

Post by Vogateer » Tue May 01, 2007 3:32 pm

Good points, TankCatNinjaFish, I'll keep that in mind in the future, too. Though I imagine I'd be lost reading a program's API at the moment, I'd like to see an example of using python to just do it directly from the code of an external program, or am I misunderstanding this, and is "option a" usually done by writing a module in C?

I originally just forked the shell command, but found I needed to enter the password from the prompt, and I decided that, since I'm learning, I should try to make it completely automated, which led me to use pexpect, since mysqldump, like ssh, doesn't take the password from stdin. Now I'm trying to figure out what I need to do to get pexpect to see the prompt...
Vim is beautiful

User avatar
Jza
Posts: 466
Joined: Sun Oct 30, 2005 7:01 pm
Location: Mexico
Contact:

Post by Jza » Tue May 01, 2007 6:09 pm

I think you should just learn the 'description' of the API so u can make a decision if its better to go to the CLI or through pythong. MySQLdb module on pyhton is very extensible:
here are some command lists:
http://mysql-python.sourceforge.net/MyS ... ranslation
and
http://mysql-python.sourceforge.net/MySQLdb-1.2.2/

Both of this documenation will help you decide if the API is developed enough to be able to develop on top of it. MySQLdb personally show the API is pretty complete and I think you will need it for future projects in web-development.
Alexandro COLORADO

User avatar
riddlebox
Posts: 86
Joined: Mon Jul 03, 2006 2:09 pm
Contact:

Post by riddlebox » Tue May 01, 2007 10:41 pm

CptnObvious999 wrote:Cool, what GUI toolkit are you using? Care to share the code?

I have just started to make Mille Bornes clone in Python, only got a few lines done but hopefully I will have enough motivation to complete it. ;)
I am going to use gtk, and glade to build it. Here is a link to my original app as well as some of my other projects over the years that I have done...I think the rc_car.py will no longer work, due to changes in pygame, but it probably wont take much to get it going again. If anyone wants to help me with any of the scripts, let me know. I have a real problem with error detection, I just dont do it!
http://vallista.idyll.org/~james/

User avatar
Vogateer
Posts: 700
Joined: Thu Nov 17, 2005 11:18 pm
Location: Norman, Oklahoma
Contact:

Post by Vogateer » Tue May 01, 2007 11:11 pm

Figured out what I was doing wrong with pexpect! I didn't understand that I had to use another call to the "expect" method after I had sent the password, otherwise I couldn't grab the text from mysqldump. After that I just used "open" to write the file, and all seems to be well!
Vim is beautiful

User avatar
TankCatNinjaFish
Posts: 110
Joined: Wed Aug 09, 2006 4:29 am

Post by TankCatNinjaFish » Wed May 02, 2007 3:57 pm

Just as a side note I think mysqldump takes a --password command line option.

User avatar
riddlebox
Posts: 86
Joined: Mon Jul 03, 2006 2:09 pm
Contact:

Post by riddlebox » Sat May 12, 2007 8:24 am

Is anyone interested in converting a shell script to a python script? I usually use this script to convert the mpg files that mythtv creates to dvds, but in the latest version of ubuntu this script stopped working. I asked a couple questions in #bash and everyone agreed that the original writer did a horrible job writing this script. It was suggested to me by them to rewrite the script. This would be a great starting point for a python script. Most of the important code is already there, the commands to convert the files are there, we just have to clean it up!
If anyone wants to help you can get the file here:
wget http://s91928265.onlinehome.us/hfamily/ ... makedvd.sh

User avatar
Ryochan7
Posts: 99
Joined: Wed Dec 15, 2004 10:18 pm
Location: Peoria, IL
Contact:

Post by Ryochan7 » Sat May 12, 2007 11:50 am

I am a bit busy with my own stuff right now so I wouldn't be able to help out. When I was last messed with MythTv, I was testing out the MythArchive extension for converting my recordings to DVD format and it worked out pretty well.

The small project that I have been working on lately is a Python podcatcher script that will work like BashPodder. There are a few things that I still need to work out but it currently does everything that my modified version of BashPodder does.
Linux User #357977
LUGOP is awesome

User avatar
Vogateer
Posts: 700
Joined: Thu Nov 17, 2005 11:18 pm
Location: Norman, Oklahoma
Contact:

Post by Vogateer » Mon May 14, 2007 6:33 pm

I can try to help, though I'll need some guidance, lest I take a poorly written bash script and turn it into a poorly written python script.
Vim is beautiful

Post Reply