Posts Tagged python
rola_songbird.py
Based on the script published by gnuget rola-banshee.py this is a little hack to work with songbird 1.1.1 using the dbus add-on, with 1.1.2 don’t work because the add-on didn’t work with the new version
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#Author: Isaac I. Torres
#Correo: istodi[arroba]gmail[punto]com
#Based on rola-banshee.py http://gnuget.underlife.org/blog/view/203/rola-banshee-py
version = "1.0"
__module_name__ = "rola_songbird.py"
__module_version__ = version
import dbus
import xchat
class RolaSongbird:
def __init__(self):
self.songbird = dbus.SessionBus()
self.songbird = self.songbird.get_object("org.mozilla.songbird","/org/mozilla/songbird")
xchat.prnt("rola-songbird.py Version %s loaded!" % (version))
xchat.prnt("/rola")
def rola(self, word, word_eol, userdata):
song = self.songbird.getTitle()
artist = self.songbird.getArtist()
xchat.command("me esta escuchando: %s - %s" % (artist, song))
return xchat.EAT_XCHAT
control = RolaSongbird()
xchat.hook_command("rola", control.rola)
May 1, 2009
download links with python
Lately (about 3 days ago) I’ve started learning python, and this is a little script I made for download all the links of a page, you give it the html file (it have to be a local html, it can’t use an url, so save the page and use it) and the extension of the files you want to download, it use wget, so I know there are hundreds of script or software that can do this an maybe so much better but I want to do it just for didactic purpose, so here it is:
#!/usr/bin/env python
import sys
import os
#get two args:
# file name to search in
# extension of link to download
#use ./filename file.html extension_to_search
file = open(sys.argv[1], 'r')
ext = str(sys.argv[2])
extLength = len(ext)
lineas = file.readlines()
for line in lineas:
if line.find('href="') != -1:
hrefpos = line.find('href="')
#+6 to add the length of href="
if line[hrefpos+6:].find(ext) != -1:
lastpos = line[hrefpos+6:].find(ext)
#extLength added so the string contains the extension
dfile = line[hrefpos+6:][:lastpos+extLength]
os.system("wget -c " + dfile)
Cheers
5 comments April 9, 2009