Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Publicaciones sobre programming (publicaciones antiguas, página 12)

Python-v4l: neat!

Think­ing about Cher­ryTV and ways to turn it in­to a re­al ap­pli­ca­tion, I thought the worse piece of it was the re­liance on v4lctl, and how re­al­ly you just don't know if it works or not, and how you can't fine­tune, and what­ev­er, and run in­to Python-v4l.

It has re­mained ap­par­ent­ly un­touched by two years, but I man­aged to build it with one ed­it and to make it work by switch­ing a line to an al­ter­nate ver­sion (they are both there), and it's nice.

Here's the ex­am­ple TV view­ing ap­pli­ca­tion us­ing it:

#!/usr/bin/env python
# Sample TV viewing application for pyv4l >= 0.3 - by Michael Dove
# Note: this does the imaging in grab mode. Performance is limited.
# I average 35 fps @ 320x240. Disabling the writes to the tk window yeilds 90+ fps.

import v4l
import Image
import ImageChops
WIDTH = 320
HEIGHT = 240
vid ='/dev/video')
cap = vid.getCapabilities()
print "Device Name: %s" % cap[0]
print "Type: %d" % cap[1]
print "Channels: %d" % cap[2]
print "Audios: %d" % cap[3]
print "Maximum Width: %d" % cap[4]
print "Maximum Height: %d" % cap[5]
print "Minimum Width: %d" % cap[6]
print "Minimum Height: %d" % cap[7]
print vid.getChannel(0) # TV
vid.setChannel(0) # set to TV

import Tkinter
import ImageTk
photo = ImageTk.PhotoImage("RGB",(WIDTH,HEIGHT))
label= Tkinter.Label(tk,text="mini TV",image=photo,width=WIDTH,height=HEIGHT)

nextFrame = 0;

    while 1:
        output = vid.getImage(nextFrame)
        im = Image.fromstring("RGB", (WIDTH, HEIGHT), output)
        # update Tk label
        nextFrame = vid.queueFrame()

except Tkinter.TclError:
    print "something"

If you have seen the equiv­a­lent C ap­p... well... nice job here!

Flickr Banners

If you are one of the three per­sons who ac­tu­al­ly see this blog on its site in­stead of read­ing it through some sort of ag­gre­ga­tor, you may have no­ticed I have a ban­ner.

This is what it looks like:


Nice, ah?

It's not very orig­i­nal (look for "spell with flick­r" to see where I stole the idea), but I wrote a script to do it. So here it is, feel free to steal it too, it's your turn.

You will need this, Im­ageMag­ick, and a Flickr API key.

To use it sim­ply call it like this:

python something

And you will have a some­thing.jpg with some­thing in it.

#!/usr/bin/env python

import flickr,sys,random
from urllib import urlopen
import os


urls = []
for l in sys.argv[1]:
  if l=="a":
  if l=="i":
  photos = g.getPhotos(tags=[l], per_page=50)
              size='Square', urlType='source'))

for i in range(0,len(urls)):

os.system ("montage -tile %dx1 -geometry +0+0 %s %s"%(
            len(urls),' '.join([ '%d.jpg'%x for x in range(0,
            len(urls)) ]), sys.argv[1]+'.jpg'))

Using runit is even simpler

I have post­ed in the past about runit.

One of the prob­lems peo­ple mi­grat­ing to runit have is that all your ser­vices are SysV script­s.

The runit au­thor has a col­lec­tion of scripts you can use, but usu­al­ly they re­quire some ad­just­ment to work on a spe­cif­ic ver­sion of Lin­ux.

So, I wrote a lame python script that takes the SysV scripts you are cur­rent­ly us­ing and turns them in­to runit ser­vices, in­clud­ing de­pen­den­cies.

Sup­pose you usu­al­ly start on run­lev­el 3. Then you save this script and run it like this:

mkdir services
python 3

And you should end with a bunch of runit ser­vices in­side ser­vices/

Those ser­vices will start in rough­ly the same or­der as if you were us­ing SysV init. That's prob­a­bly way too much de­pen­den­cies.

The main dif­fer­ence is that kdm will start ear­li­er and the ttys will start way ear­li­er than you are used to.

I have found that my note­book boots faster us­ing this, but I can't pro­vide a bootchart be­cause it sim­ply does­n't seem to work in my com­put­er.

If any­one is will­ing and able to run the tests and quan­ti­fy the dif­fer­ence, I am all ears.

For some rea­son kudzu, ipt­a­bles and arpt­a­bles_jf don't work with this ap­proach, so just stick them at the bot­tom of /etc/runit/1

Al­so, please un­der­stand that these are not cor­rect runit ser­vices. They are not man­aged, so if your ser­vice crash­es it stays crashed.

So, you should still even­tu­al­ly mi­grate to cor­rect script­s. This is just a way to make that sim­pler.

If you see a russian, it's my doing

In this rus­sian site, you can see how they got my post about the San­ta Fe python even­t. And ap­par­ent­ly what im­pressed them is the thing about the fish and the beer.

См. вас там!

I Jornada Python en Santa Fe, Argentina

Bilin­gual en­try here:

Yo nací en San­ta Fe. Me gus­ta Python. Hay un even­to de Python en San­ta Fe.

Pien­so asi­s­tir so­la­mente co­mo es­pec­ta­dor, quedarme calla­do y es­cuchar cosas in­tere­santes que di­gan los de­mas.

Sin em­bar­go, si quieren ex­per­i­men­tar un lu­gar donde se pueden com­er 30 platos de pesca­do por 20 pe­sos (y te podes com­er los 30, aunque yo conoz­co so­la­mente una per­sona con la su­fi­ciente for­t­aleza es­tom­acal), mas to­da la cerveza que puedas tomar... bueno, nos ve­mos en San­ta Fe el 3 de ju­nio.

Mas in­for­ma­cion aca

I come from San­ta Fe. I like Python. There is a Python event on San­ta Fe.

I in­tend to at­tend in a strict­ly spec­ta­tor fash­ion. I will lis­ten to oth­er guys telling in­ter­est­ing stuff, and keep qui­et.

How­ev­er, if you want to ex­pe­ri­ence a place where you can eat 30 dif­fer­ent fish dish­es for about 7 dol­lars (and I mean you can eat all 30, al­though I know on­ly one per­son of such su­per­hu­man for­ti­tude), plus all the beer you can drink... well, I will be in San­ta Fe on June 3rd.

More in­for­ma­tion here

Contents © 2000-2024 Roberto Alsina