jsign-commits Mailing List for JSign Client
Brought to you by:
borillo
You can subscribe to this list here.
| 2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
(5) |
Oct
|
Nov
(2) |
Dec
|
|---|
|
From: Ricardo B. D. <bo...@us...> - 2001-11-22 14:08:35
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv663
Modified Files:
AudioGalaxy.py
Log Message:
Nova actualització de Miguel :)
Index: AudioGalaxy.py
===================================================================
RCS file: /cvsroot/jsign/pyweb/AudioGalaxy.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AudioGalaxy.py 2001/11/16 09:39:31 1.1
--- AudioGalaxy.py 2001/11/22 14:08:33 1.2
***************
*** 9,15 ****
self.song = self.URL + "/list/song.php?"
self.chooseversion = self.URL + "/list/chooseVersion.php?"
! #la informacion del usuario debe ser leida de las cookies o
! #pedida al usuario
! self.username, self.password = self.readCookie()
tmp=tempfile.mktemp()
urllib.urlretrieve(self.home,tmp)
--- 9,25 ----
self.song = self.URL + "/list/song.php?"
self.chooseversion = self.URL + "/list/chooseVersion.php?"
!
! #la informacion del usuario es leida de las cookies
!
! self.SID, self.username, self.password = self.readCookie()
!
! if self.SID == "" or self.username == "" or self.password=="":
! self.SID = getSID()
! system.stdout.write("Username:")
! self.username=sys.stdin.readline()[:-1]
! system.stdout.write("Password:")
! self.password=sys.stdin.readline()[:-1]
!
! def getSID(self):
tmp=tempfile.mktemp()
urllib.urlretrieve(self.home,tmp)
***************
*** 18,28 ****
a = re.findall("\<input type=\"hidden\" name=\"SID\" value=\"[0-9a-zA-Z]*\"\>",page)[0]
b = string.split(a,"value=\"")[1]
! self.SID=str(b[:-2])
def readCookie(self):
! lc=os.listdir('c:\windows\cookies')
for i in lc:
if string.find(i,"audiogalaxy") != -1:
! f=open("c:\\windows\\cookies\\"+i)
c=f.read()
f.close()
--- 28,44 ----
a = re.findall("\<input type=\"hidden\" name=\"SID\" value=\"[0-9a-zA-Z]*\"\>",page)[0]
b = string.split(a,"value=\"")[1]
! return str(b[:-2])
!
!
def readCookie(self):
! a=os.environ
! cookie_path=a["WINDIR"]+"\\cookies"
!
!
! lc=os.listdir(cookie_path)
for i in lc:
if string.find(i,"audiogalaxy") != -1:
! f=open(cookie_path+"\\"+i)
c=f.read()
f.close()
***************
*** 30,35 ****
username=re.findall("cookieUsername\n[^\n]+\n",c)[0]
password=re.findall("cookiePassword\n[^\n]+\n",c)[0]
! return string.replace(username,"cookieUsername\n","")[:-1], string.replace(password,"cookiePassword\n","")[:-1]
--- 46,52 ----
username=re.findall("cookieUsername\n[^\n]+\n",c)[0]
password=re.findall("cookiePassword\n[^\n]+\n",c)[0]
+ sid=re.findall("SID\n[^\n]+\n",c)[0]
! return string.replace(sid,"SID\n","")[:-1], string.replace(username,"cookieUsername\n","")[:-1], string.replace(password,"cookiePassword\n","")[:-1]
***************
*** 44,48 ****
--- 61,94 ----
return urllib.urlencode(a)
+
+ def match_bitrate(self,match,bitrate):
+ if string.upper(match) == "ANY":
+ return 1
+
+ if match[0] == ">":
+ if match[1] == "=":
+ b=int(match[2:])
+ return int(bitrate) >= b
+ else:
+ b=int(match[1:])
+ return int(bitrate) > b
+ elif match[0] == "<":
+ if match[1] == "=":
+ b=int(match[2:])
+ return int(bitrate) <= b
+ else:
+ b=int(match[1:])
+ return int(bitrate) < b
+
+ elif match[0] == "=":
+ b=int(match[1:])
+ return b==int(bitrate)
+ else:
+ b=int(match)
+ return b==int(bitrate)
+
+
+
def search(self,cad,maxMatches=None):
off=0
***************
*** 484,488 ****
for i in l.keys():
! if l[i][1] != bitrate:
continue
--- 530,534 ----
for i in l.keys():
! if not self.match_bitrate(bitrate,l[i][1]):
continue
***************
*** 492,495 ****
--- 538,542 ----
ls=string.split(l[i][2],":")
sec=int(ls[0])*60+int(ls[1])
+
if (tsec>=(sec-int(diftime))) and (tsec <= (sec+int(diftime))):
***************
*** 602,606 ****
def getAlbumFromDB(self,artist,album,bitrate):
f=freedb()
! l=f.searchDiscs(album)
l=f.filterDiscs(l,artist,album)
--- 649,653 ----
def getAlbumFromDB(self,artist,album,bitrate):
f=freedb()
! l=f.searchDiscs(artist+" "+album)
l=f.filterDiscs(l,artist,album)
***************
*** 616,636 ****
ldisc=ldisc+[(d,t,nt)]
if ldisc != []:
r=-1
! while (r<0 or r>cnt):
! sys.stdout.write("\nElige un disco (s+num para descripcion): ")
c=sys.stdin.readline()
! if string.upper(c[0]) == "S":
c=string.replace(c,"s","")
c=string.replace(c,"S","")
!
! for i in ldisc[int(c)][0]:
! #print i
! sys.stdout.write(i[0]+" - "+i[1]+" - "+i[2]+"\n")
r=-1
else:
! r=int(c[:-1])
if self.getAlbum(ldisc[r][0],artist,album,bitrate) == 0:
--- 663,711 ----
ldisc=ldisc+[(d,t,nt)]
+ ndiscs = cnt
if ldisc != []:
r=-1
! while (r<0 or r>ndiscs):
! sys.stdout.write("\nElige un disco (i para informacion de opciones): ")
!
c=sys.stdin.readline()
!
! if string.upper(c[0]) == "I":
! sys.stdout.write("\nSelecciona un valor para seleccionar un disco.\n")
! sys.stdout.write("I Muestra esta informacion.\n")
! sys.stdout.write("L Lista los discos hallados.\n")
! sys.stdout.write("S+Num Muestra las canciones del disco seleccionado.\n")
! sys.stdout.write("Q Salir del programa.\n")
! r=-1
! elif string.upper(c[0]) == "Q":
! sys.stdout.write("Good Bye")
! sys.exit(0)
! elif string.upper(c[0]) == "L":
! cnt=0
! for i in l:
! print string.rjust(str(cnt),2),i[2]," Tracks:",string.rjust(str(ldisc[cnt][2]),2)," Total Time:",ldisc[cnt][1]
! cnt=cnt+1
! r=-1
! elif string.upper(c[0]) == "S":
c=string.replace(c,"s","")
c=string.replace(c,"S","")
! try:
! ind=int(c)
! except:
! sys.stderr.write("Valor no valido: "+c)
! r=ind
! if (r>=0 and r<=ndiscs):
! sys.stdout.write("\n")
! for i in ldisc[ind][0]:
! #print i
! sys.stdout.write(i[0]+" - "+i[1]+" - "+i[2]+"\n")
r=-1
else:
! try:
! r=int(c[:-1])
! except:
! sys.stderr.write("Valor no valido: "+c)
if self.getAlbum(ldisc[r][0],artist,album,bitrate) == 0:
***************
*** 773,778 ****
sys.stdout.write("Album: ")
album=sys.stdin.readline()[:-1]
! sys.stdout.write("Bitrate: ")
! bitrate=sys.stdin.readline()[:-1]
ag.getAlbumFromDB(artist,album,bitrate)
--- 848,866 ----
sys.stdout.write("Album: ")
album=sys.stdin.readline()[:-1]
!
! bitrate = ""
! while bitrate == "":
! sys.stdout.write("Bitrate ( =,<,>,<=,>= + bitrate o ANY): ")
! bitrate=sys.stdin.readline()[:-1]
! if string.upper(bitrate) != "ANY":
! b=string.replace(bitrate,"=","")
! b=string.replace(b,"<","")
! b=string.replace(b,">","")
! try:
! b=int(b)
! except:
! bitrate = ""
! sys.stderr.write("Bitrate no valido.\n")
!
ag.getAlbumFromDB(artist,album,bitrate)
***************
*** 788,792 ****
bitrate=sys.stdin.readline()[:-1]
ag.getAlbumFromFile(f,bitrate)
! except:
print "El Fichero",f,"no existe."
--- 876,880 ----
bitrate=sys.stdin.readline()[:-1]
ag.getAlbumFromFile(f,bitrate)
! except IOError:
print "El Fichero",f,"no existe."
***************
*** 802,805 ****
--- 890,894 ----
#readCookie()
#search(self,cad,maxMatches=None)
+ #match_bitrate(match,bitrate)
#listVersions(self,code)
#queueSong(self,codSong,codVer)
|
|
From: Ricardo B. D. <bo...@us...> - 2001-11-16 09:39:35
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv24504
Added Files:
AudioGalaxy.py
Log Message:
Cedido por Miguel!!
--- NEW FILE: AudioGalaxy.py ---
import urllib,re,sys,string,tempfile,os,httplib
class AudioGalaxy:
def __init__(self):
self.URL = "http://www.audiogalaxy.com"
self.home = self.URL + "/user/home.php?"
self.search_url = self.URL + "/list/searches.php?"
self.artistinfo = self.URL + "/list/artistInfo.php?"
self.song = self.URL + "/list/song.php?"
self.chooseversion = self.URL + "/list/chooseVersion.php?"
#la informacion del usuario debe ser leida de las cookies o
#pedida al usuario
self.username, self.password = self.readCookie()
tmp=tempfile.mktemp()
urllib.urlretrieve(self.home,tmp)
page = open(tmp).read()
os.remove(tmp)
a = re.findall("\<input type=\"hidden\" name=\"SID\" value=\"[0-9a-zA-Z]*\"\>",page)[0]
b = string.split(a,"value=\"")[1]
self.SID=str(b[:-2])
def readCookie(self):
lc=os.listdir('c:\windows\cookies')
for i in lc:
if string.find(i,"audiogalaxy") != -1:
f=open("c:\\windows\\cookies\\"+i)
c=f.read()
f.close()
username=re.findall("cookieUsername\n[^\n]+\n",c)[0]
password=re.findall("cookiePassword\n[^\n]+\n",c)[0]
return string.replace(username,"cookieUsername\n","")[:-1], string.replace(password,"cookiePassword\n","")[:-1]
def urlencode(self,str):
a={}
a["SID"]=self.SID
a["searchType"]="0"
a["searchStr"]=str
return urllib.urlencode(a)
def search(self,cad,maxMatches=None):
off=0
a={}
cad = string.replace(cad,"?","")
cad = string.replace(cad,"&"," ")
cad = string.replace(cad,"AND"," ")
cad = string.replace(cad,"(","")
cad = string.replace(cad,")","")
cad = string.replace(cad,".","")
cad = string.replace(cad," "," ")
url = self.search_url+self.urlencode(cad)
mode = []
codartist = ""
nmatches=0
while (off >= 0):
tmp=tempfile.mktemp()
if off != 0:
offset = "&offset="+str(off)
else:
offset = ""
if off == 0 or mode == []:
urllib.urlretrieve(url+offset,tmp)
else:
urllib.urlretrieve(self.artistinfo+"&r="+codartist+offset,tmp)
page = open(tmp).read()
os.remove(tmp)
if off == 0:
mode = re.findall("Found Exact Match",page)
lcodsong=re.findall("songIDs\[[0-9]+\]\.songID = [0-9]+;",page)
lqueued=re.findall("songIDs\[[0-9]+\]\.queued = [0-9]+;",page)
p=string.replace(page,"<span class='match'>","")
p=string.replace(p,"</span>","")
if (off == 0 and mode != []):
lcodartist=re.findall("name=\"artistID\" value=[0-9]+\>",p)
codartist=string.split(lcodartist[0],"value=")[1][:-1]
if len(lcodsong) <= 0:
off = -1
else:
if mode != []: #si ha hallado un acierto perfecto
lartist=re.findall("\<span class=\"artistName\"\>[^<]*\<\/span\>",page)
artist = string.split(lartist[0],">")[1][:-6]
lavail=re.findall("/images/list/a[0-4-]\.gif",page)
lsong=re.findall("class=song\>[^<]*\<\/a\>",p)
else:
lavail=re.findall("/images/list/[0-4z]_0\.gif",page)
lartist=re.findall("artistInfo\.php\?SID=[0-9a-zA-Z]+&r=[0-9]*&fromSearchClick=[0-9]*\"\>[^<]*\<\/a\>",p)
lsong=re.findall("song\.php\?SID=[0-9a-zA-Z]+&g=[0-9]*\" class=song\>[^<]*\<\/a\>",p)
for i in range(len(lcodsong)-1): #quizas sea -1
nmatches=nmatches+1
cod = string.split(lcodsong[i],"=")[1][1:-1]
queued = string.split(lqueued[i],"=")[1][1:-1]
if mode != []:
song=lsong[i][11:-4]
avail=lavail[i][-5]
else:
avail=lavail[i][-7]
artist = string.split(lartist[i],">")[1][:-3]
song = string.split(lsong[i],">")[1][:-3]
a[cod] = [string.upper(song),string.upper(artist),queued,avail,codartist]
if nmatches==maxMatches:
break
if nmatches==maxMatches:
break
if mode != []:
if len(lcodsong) <= 5:
off = -1
else:
off = off + 25
else:
if len(lcodsong) <= 5:
off = -1
else:
off = off + 10
return a,mode!=[]
def listVersions(self,code):
h=httplib.HTTP("www.audiogalaxy.com",80)
h.putrequest("GET","/list/chooseVersion.php?&g="+code)
h.putheader("Accept","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, */*")
h.putheader("Accept-Languaje","en-us")
#h.putheader("Accept-Encoding","gzip, deflate")
h.putheader("Accept-Charset","iso-8859-1,*,utf-8")
h.putheader("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)")
h.putheader("Host","www.audiogalaxy.com")
h.putheader("Content-type","application/x-www-form-urlencoded")
h.putheader("Connection","Keep Alive")
h.putheader("Cookie: $Version=\"1\"; SID="+self.SID+"; cookieUsername="+self.username+"; cookiePassword="+self.password+"; $Domain=\"audiogalaxy.com/\"")
h.endheaders()
ferrcode, errmsg, headers = h.getreply()
f=h.getfile()
p=f.read()
p=string.replace(p," ","")
s=re.findall("name=\"fileSetIDStr\" value=\"[a-zA-Z0-9]+\"\>",p)
s2=re.findall("[0-9]+,[0-9,]+",p)
s3=re.findall("[0-9]+kbps",p)
s4=re.findall("\>[0-9]+:[0-9]+\<",p)
s5=re.findall("\>[0-9]+\<",p)
a={}
for i in range(len(s)):
code=string.split(s[i],"value=\"")[1][:-2]
size=s2[i]
bitrate=s3[i][:-4]
time=s4[i][1:-1]
qty=s5[i][1:-1]
a[code] = size,bitrate, time, qty
return a
def queueSong(self,codSong,codVer):
tmp=tempfile.mktemp()
urllib.urlretrieve(self.chooseversion+"SID="+self.SID+"&action=queue&songID="+codSong+"&fileSetIDStr="+codVer,tmp)
page = open(tmp).read()
os.remove(tmp)
def filterUnavailableSong(self,l):
for i in l.keys():
if l[i][3] == "-" or l[i][3] == "z":
del l[i]
return l
def filterByName(self,l,name):
c=string.upper(name)
for i in l.keys():
s=l[i][0]+l[i][1]
if string.find(s,c) == -1:
del l[i]
return l
def filterByNames(self,l,lnames):
ln=[]
for i in lnames:
ln = ln + [string.upper(i)]
for i in l.keys():
s=l[i][0]+l[i][1]
for j in ln:
if string.find(s,c) != -1:
break
del l[i]
return l
def filterExactName(self,l,name):
n=string.upper(name)
for i in l.keys():
if l[i][0] != n and l[i][1] != n: #cancion y artista respectivamente
del l[i]
return l
def filterAnyExactName(self,l,lname):
ln=[]
for i in lnames:
ln = ln + [string.upper(i)]
artist = 0
song = 0
for i in l.keys():
s=l[i][0]
a=l[i][1]
for j in ln:
if j == s:
song = 1
elif j == a:
artist = 1
if artist==song==1:
break
if (artist!= 1 or song!=1):
del l[i]
return l
def listExactMatches(self,l,song,lnames,avail=1):
ln=[]
lmat=[]
for i in lnames:
ln = ln + [string.upper(i)]
sn = string.upper(song)
sn = string.replace(sn,"?","")
sn = string.replace(sn,"AND"," ")
sn = string.replace(sn,"&"," ")
sn = string.replace(sn,"(","")
sn = string.replace(sn,")","")
sn = string.replace(sn,".","")
sn = string.replace(sn," "," ")
artist = 0
song = 0
for i in l.keys():
s=l[i][0]
a=l[i][1]
d=l[i][3] #disponibiliad de la cancion
if d=="z" or d=="-":
d=-1
d=int(d)
s = string.replace(s,"?","")
s = string.replace(s,"AND"," ")
s = string.replace(s,"&"," ")
s = string.replace(s,"(","")
s = string.replace(s,")","")
s = string.replace(s,".","")
s = string.replace(s," "," ")
for j in ln:
if sn==s or sn==a:
song = 1
if j == a or j==s:
artist = 1
if artist==song==1 and d>=avail:
if not i in lmat:
lmat=lmat+[i]
return lmat
def listPartialMatches(self,l,song,lnames,avail=1):
ln=[]
lmat=[]
for i in lnames:
ln = ln + [string.upper(i)]
sn = string.upper(song)
sn = string.upper(song)
sn = string.replace(sn,"?","")
sn = string.replace(sn,"AND"," ")
sn = string.replace(sn,"&"," ")
sn = string.replace(sn,"(","")
sn = string.replace(sn,")","")
sn = string.replace(sn,".","")
sn = string.replace(sn," "," ")
artist = 0
song = 0
for i in l.keys():
s=l[i][0]
a=l[i][1]
d=l[i][3] #disponibiliad de la cancion
if d=="z" or d=="-":
d=-1
d=int(d)
s = string.replace(s,"?","")
s = string.replace(s,"AND"," ")
s = string.replace(s,"&"," ")
s = string.replace(s,"(","")
s = string.replace(s,")","")
s = string.replace(s,".","")
s = string.replace(s," "," ")
for j in ln:
if string.find(s,sn)!=-1 or string.find(a,sn)!=-1:
song = 1
if string.find(a,j)!= -1 or string.find(s,j)!= -1:
artist = 1
if artist==song==1 and d>=avail:
if not i in lmat:
lmat=lmat+[i]
return lmat
def selectExactMatch(self,l,song,lnames,avail=1):
ln=[]
for i in lnames:
ln = ln + [string.upper(i)]
sn = string.upper(song)
sn = string.upper(song)
sn = string.replace(sn,"?","")
sn = string.replace(sn,"AND"," ")
sn = string.replace(sn,"&"," ")
sn = string.replace(sn,"(","")
sn = string.replace(sn,")","")
sn = string.replace(sn,".","")
sn = string.replace(sn," "," ")
artist = 0
song = 0
for i in l.keys():
s=l[i][0]
a=l[i][1]
d=l[i][3] #disponibiliad de la cancion
if d=="z" or d=="-":
d=-1
d=int(d)
s = string.replace(s,"?","")
s = string.replace(s,"AND"," ")
s = string.replace(s,"&"," ")
s = string.replace(s,"(","")
s = string.replace(s,")","")
s = string.replace(s,".","")
s = string.replace(s," "," ")
for j in ln:
if sn==s or sn==a:
song = 1
if j == a or j==s:
artist = 1
if artist==song==1 and d>=avail:
return i
break
return -1
def selectPartialMatch(self,l,song,lnames,avail=1):
ln=[]
for i in lnames:
ln = ln + [string.upper(i)]
sn = string.upper(song)
sn = string.upper(song)
sn = string.replace(sn,"?","")
sn = string.replace(sn,"AND"," ")
sn = string.replace(sn,"&"," ")
sn = string.replace(sn,"(","")
sn = string.replace(sn,")","")
sn = string.replace(sn,".","")
sn = string.replace(sn," "," ")
artist = 0
song = 0
for i in l.keys():
s=l[i][0]
a=l[i][1]
d=l[i][3] #disponibiliad de la cancion
if d=="z" or d=="-":
d=-1
d=int(d)
s = string.replace(s,"?","")
s = string.replace(s,"AND"," ")
s = string.replace(s,"&"," ")
s = string.replace(s,"(","")
s = string.replace(s,")","")
s = string.replace(s,".","")
s = string.replace(s," "," ")
for j in ln:
if string.find(s,sn)!=-1 or string.find(a,sn)!=-1:
song = 1
if string.find(a,j)!= -1 or string.find(s,j)!= -1:
artist = 1
if artist==song==1 and d>=avail:
return i
break
return -1
def listExactVersions(self,codsong,time,bitrate,diftime=3,minqty=1):
l=self.listVersions(codsong)
lt=string.split(time,":")
tsec=int(lt[0])*60+int(lt[1])
a=[]
for i in l.keys():
if l[i][1] != bitrate:
continue
if int(l[i][3]) < minqty:
continue
ls=string.split(l[i][2],":")
sec=int(ls[0])*60+int(ls[1])
if (tsec>=(sec-int(diftime))) and (tsec <= (sec+int(diftime))):
a=a+[(i,l[i][3])]
return a
def selectExactVersion(self,codsong,time,bitrate,diftime=3,minqty=1):
a=self.listExactVersions(codsong,time,bitrate,diftime,minqty)
min=0
code=""
for i in a:
n=int(i[1])
if n >min:
min = n
code=i[0]
if code=="":
return -1
else:
return code
def getSong(self,artist,album,song,time,bitrate):
song = string.replace(song,"?","")
song = string.replace(song,"&"," ")
song = string.replace(song,"AND"," ")
song = string.replace(song,"(","")
song = string.replace(song,")","")
song = string.replace(song,".","")
song = string.replace(song," "," ")
if string.find(song,"/") != -1:
ls=string.split(song,"/")
p1=string.strip(ls[0])
p2=string.strip(ls[1])
list,cod = self.search(p1,10)
list2,cod = self.search(p2,10)
for i in list2.keys():
list[i] = list2[i]
matches=self.listExactMatches(list,p1,[p2,artist,album,artist+" "+album,album+" "+artist])
matches= matches+[self.listExactMatches(list,p2,[p1,artist,album,artist+" "+album,album+" "+artist])]
if matches == []:
matches=self.listPartialMatches(list,p1,[p2,artist,album,artist+" "+album,album+" "+artist])
matches=matches+[self.listPartialMatches(list,p2,[p1,artist,album,artist+" "+album,album+" "+artist])]
#realizamos una segunda busqueda mas restrictiva
if matches == []:
list,cod = self.search(artist+" "+p1,10)
list2,cod = self.search(artist+" "+p2,10)
for i in list2.keys():
list[i] = list2[i]
matches=self.listExactMatches(list,p1,[p2,artist,album,artist+" "+album,album+" "+artist])
matches= matches+[self.listExactMatches(list,p2,[p1,artist,album,artist+" "+album,album+" "+artist])]
if matches == []:
matches=self.listPartialMatches(list,p1,[p2,artist,album,artist+" "+album,album+" "+artist])
matches=matches+[self.listPartialMatches(list,p2,[p1,artist,album,artist+" "+album,album+" "+artist])]
else:
list, cod = self.search(song,10)
matches=self.listExactMatches(list,song,[artist,album,artist+" "+album,album+" "+artist])
if matches == []:
matches=self.listPartialMatches(list,song,[artist,album,artist+" "+album,album+" "+artist])
#realizamos la busqueda restrictiva
if matches == []:
list, cod = self.search(artist+" "+song,10)
matches=self.listExactMatches(list,song,[artist,album,artist+" "+album,album+" "+artist])
if matches == []:
matches=self.listPartialMatches(list,song,[artist,album,artist+" "+album,album+" "+artist])
for i in matches:
ver=ag.selectExactVersion(i,time,bitrate)
if ver!=-1:
ag.queueSong(i,ver)
sys.stdout.write("OK\n")
return 0
sys.stdout.write("ERROR\n")
return -1
def getAlbum(self,lsongs,artist,album,bitrate):
c=0
for i in lsongs:
sys.stdout.write(string.ljust("Get Song--> "+i[2],60))
song=i[2]
song=string.replace(song,"AND"," ")
c = c + self.getSong(artist,album,song,i[1],bitrate)
return (c)
def getAlbumFromDB(self,artist,album,bitrate):
f=freedb()
l=f.searchDiscs(album)
l=f.filterDiscs(l,artist,album)
cnt=0
ldisc=[]
for i in l:
d,t,nt=f.getDiscInfo(i[0],i[1])
print string.rjust(str(cnt),2),i[2]," Tracks:",string.rjust(str(nt),2)," Total Time:",t
cnt=cnt+1
ldisc=ldisc+[(d,t,nt)]
if ldisc != []:
r=-1
while (r<0 or r>cnt):
sys.stdout.write("\nElige un disco (s+num para descripcion): ")
c=sys.stdin.readline()
if string.upper(c[0]) == "S":
c=string.replace(c,"s","")
c=string.replace(c,"S","")
for i in ldisc[int(c)][0]:
#print i
sys.stdout.write(i[0]+" - "+i[1]+" - "+i[2]+"\n")
r=-1
else:
r=int(c[:-1])
if self.getAlbum(ldisc[r][0],artist,album,bitrate) == 0:
print "\nDisco preparado para bajarse."
else:
print "\nNo se ha podido encontrar el disco completo."
else:
print "\nNo se ha encontrado el disco en la BD."
def getAlbumFromFile(self,file,bitrate):
f=open(file)
t=f.readline()
s=string.split(t,"/")
artist=string.strip(s[0])
album=string.strip(s[1])
t=f.readline()
t=f.readline()
ltracks = []
while t != "":
lt = string.split(t,"-")
nt=string.strip(lt[0])
time=string.strip(lt[1])
name=string.strip(lt[2])
ltracks = ltracks + [(nt,time,name)]
t=f.readline()
if ltracks != []:
if self.getAlbum(ltracks,artist,album,bitrate) == 0:
print "Disco preparado para bajarse."
else:
print "No se ha podido encontrar el disco completo."
else:
print "Error al leer el fichero."
############################### Fin Clase AudioGalaxy ###################
############################### Clase freedb ############################
class freedb:
def __init__(self):
self.URL="http://www.freedb.org/"
def searchDiscs(self, cad):
cad=string.replace(cad," ","+")
tmp=tempfile.mktemp()
urllib.urlretrieve(self.URL+"freedb_search.php?words="+cad+"&allfields=NO&fields=artist&fields=title&allcats=YES&grouping=none",tmp)
page = open(tmp).read()
os.remove(tmp)
p = string.replace(page," ","")
p = string.replace(p,"<font size=-1>","")
discos = re.findall("cat=[A-Za-z]+&id=[a-zA-Z0-9]+\"\>[^<]+\<",p)
oldname=""
lista=[]
for i in discos:
cat=string.split(i,"&id")[0][4:]
a = string.split(i,"id=")[1]
id=string.split(a,"\">")[0]
name=string.upper(string.split(i,"\">")[1][:-1])
name=string.replace(name,"&","AND")
for i in name:
if i in string.digits:
name = oldname
else:
oldname=name
break
lista = lista + [(id,cat,name)]
return lista
def filterDiscs(self,list,artist,disc):
c = artist + " / " + disc
c=string.upper(c)
l2=[]
for i in range(len(list)-1):
if list[i][2] == c:
l2=l2+[list[i]]
return l2
def getDiscInfo(self,code,cat):
tmp=tempfile.mktemp()
urllib.urlretrieve(self.URL+"freedb_search_fmt.php?cat="+cat+"&id="+code,tmp)
page = open(tmp).read()
os.remove(tmp)
total_time=re.findall("total time: [^<]+\<",page)[0][12:-1]
tracks = re.findall("\<td valign=top\>[ 0-9]+\.\</td\>\<td valign=top\> [0-9]+:[0-9]+\</td\>\<td\>\<b\>[^<]+\</b\>",page)
ntracks = len(tracks)
cnt=0
a=[]
for i in tracks:
c=string.replace(i,"<td valign=top>","")
t=re.findall("[0-9]+:[0-9]+",c)[0]
n=string.split(c,"<b>")[1]
n=n[:-4]
cnt = cnt + 1
a=a+[(string.zfill(cnt,2),t,n)]
return a,total_time,ntracks
if __name__ == "__main__":
ag=AudioGalaxy()
if len(sys.argv) <3:
sys.stdout.write("Artista: ")
artist=sys.stdin.readline()[:-1]
sys.stdout.write("Album: ")
album=sys.stdin.readline()[:-1]
sys.stdout.write("Bitrate: ")
bitrate=sys.stdin.readline()[:-1]
ag.getAlbumFromDB(artist,album,bitrate)
else:
if string.upper(sys.argv[1]) == "-R":
f = sys.argv[2]
try:
df=open(f,"r")
df.close
sys.stdout.write("Bitrate: ")
bitrate=sys.stdin.readline()[:-1]
ag.getAlbumFromFile(f,bitrate)
except:
print "El Fichero",f,"no existe."
else:
print "Parametros incorrectos"
#Listado de funciones de AudioGalaxy
#
#readCookie()
#search(self,cad,maxMatches=None)
#listVersions(self,code)
#queueSong(self,codSong,codVer)
#filterUnavailableSong(self,l)
#filterByName(self,l,name)
#filterByNames(self,l,lnames)
#filterExactName(self,l,name)
#filterAnyExactName(self,l,lname)
#listExactMatches(self,l,song,lnames,avail=1)
#listPartialMatches(self,l,song,lnames,avail=1)
#selectExactMatch(self,l,song,lnames,avail=1)
#selectPartialMatches(self,l,song,lnames,avail=1)
#listExactVersions(self,codsong,time,bitrate,diftime=3,minqty=1)
#selectExactVersion(self,codsong,time,bitrate,diftime=3,minqty=1)
#getSong(self,artist,album,song,time,bitrate)
#getAlbum(self,lsongs,artist,album,bitrate)
#getAlbumFromDB(self,artist,album,bitrate)
#Listado de funciones de freedb
#
#searchDiscs(self, cad)
#filterDiscs(self,list,artist,disc)
#getDiscInfo(self,code,cat)
|
|
From: David R. <vr...@us...> - 2001-09-27 22:54:54
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv25218/pyweb
Modified Files:
getlinks.py
Log Message:
Primera versión operativa. Está versión funciona, tarda 25min. en recorrerse todo el sic,
loga los errores de documento no encontrado (404), los de autorizacion requerida(401), los
errores en el codigo html. Es una caña, vamos. Quien me encuentra algún error, o me propone
nuevas funcionalidades?
Index: getlinks.py
===================================================================
RCS file: /cvsroot/jsign/pyweb/getlinks.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** getlinks.py 2001/09/27 12:39:11 1.1
--- getlinks.py 2001/09/27 22:54:50 1.2
***************
*** 19,25 ****
i = string.find(link, '#')
if i >= 0:
! link = link[:i] # Remove #fragment
! words = string.split(link) # Split in whitespace delimited words return
! link = string.join(words, "")
return link
--- 19,26 ----
i = string.find(link, '#')
if i >= 0:
! link = link[:i] # Eliminamos los #
! link = string.replace(link, " ", "") # Eliminamos los blancos
! link = string.replace(link, "\n", "")
! link = string.replace(link, "\r", "")
return link
***************
*** 72,76 ****
if not self.dic_urls.has_key(link):
self.dic_urls[link] = 0
! open(logs["links"],"a+").write("%s\n" % (link))
# Quedan URLs por procesar ?
--- 73,77 ----
if not self.dic_urls.has_key(link):
self.dic_urls[link] = 0
! # open(logs["links"],"a+").write("%s\n" % (link))
# Quedan URLs por procesar ?
***************
*** 92,95 ****
--- 93,106 ----
def base_add(self, alias):
self.base.append(alias)
+
+ def marca_error(self, url):
+ self.dic_urls[url] = 2
+
+ def write_links(self):
+ file_links = open(logs["links"], "a+")
+ for link in [ f for f in self.dic_urls.keys() if self.dic_urls[f] == 1]:
+ file_links.write("%s\n" % (link))
+ file_links.close()
+
# Inicio del script
***************
*** 116,120 ****
else:
parser = URLExtractor(dir_base)
!
# Empezamos por la direccion que nos pasan como parámetro
parser.dic_urls[sys.argv[1]] = 0
--- 127,133 ----
else:
parser = URLExtractor(dir_base)
!
! url_opener = urllib.URLopener()
!
# Empezamos por la direccion que nos pasan como parámetro
parser.dic_urls[sys.argv[1]] = 0
***************
*** 125,137 ****
while url:
parser.actual=url
! open(logs["log"], "a+").write("**********************************************\nDirección: %s\n\n" %(url))
print ( "%d. Procesando %s..." % (count, url))
! try:
! parser.feed(urllib.urlopen(url).read()) # Lanzo el parser ...
! parser.close() # ... y lo cierro
! except:
! open(logs["error"], "a+").write("**********************************************\nDirección: %s\n\n" %(url))
- parser.use_url(url) # Marco la URL como procesada
if parser.has_urls():
url = parser.get_url() # Obtengo una URL no procesada
--- 138,166 ----
while url:
parser.actual=url
! open(logs["log"], "a+").write("\n**********************************************\nDirección: %s\n" %(url))
print ( "%d. Procesando %s..." % (count, url))
! try: # Capturamos los fallos de acceso a urls
! data_html = url_opener.open(url)
!
! try: # Capturamos los fallos con el parser SGML
! parser.feed(data_html.read()) # Lanzo el parser ...
! parser.close() # ... y lo cierro
! parser.use_url(url) # Marco la URL como procesada
! except:
! parser.use_url(url)
! open(logs["error"], "a+").write("Dirección: %s tiene problemas con el parser SGML\n" %(url))
!
! data_html.close()
!
! except IOError, error_code:
! parser.marca_error(url)
! if error_code[0] == "http error":
! if error_code[1] == 401:
! open(logs["error"], "a+").write("Dirección: %s requiere autorización (401)\n" %(url))
! elif error_code[1] == 404:
! open(logs["error"], "a+").write("Dirección: %s no encontrada (404)\n" %(url))
! else:
! open(logs["error"], "a+").write("Dirección: %s tiene un error desconocido\n" %(url))
if parser.has_urls():
url = parser.get_url() # Obtengo una URL no procesada
***************
*** 140,142 ****
--- 169,173 ----
else:
url = None
+
+ parser.write_links()
|
|
From: David R. <vr...@us...> - 2001-09-27 12:53:28
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv32471
Modified Files:
freedb.py
Log Message:
Esta es la versión buena, antes me había equivocado. :P
Index: freedb.py
===================================================================
RCS file: /cvsroot/jsign/pyweb/freedb.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** freedb.py 2001/09/27 12:31:29 1.2
--- freedb.py 2001/09/27 12:53:25 1.3
***************
*** 3,12 ****
class freedb:
def __init__(self):
self.URL="http://freedb.music.sk/search"
def querygroup(self, grupo):
! urllib.urlretrieve(self.URL+"/index.phtml?search="+grupo,"querygroup.tmp")
! page = open('querygroup.tmp').read()
! # Buscamos todos los enlaces a los discos
discos = re.findall("\<small\>\<a href=[^\>]*\>xmcd\<\/a\>\<\/small\>",page)
--- 3,17 ----
class freedb:
def __init__(self):
+
+ # Direccion de la DB de cds de musica freedb
self.URL="http://freedb.music.sk/search"
+ # Función que devuelve todos los discos de un determinado grupo que encuentra en freedb
def querygroup(self, grupo):
!
! # Hacemos la consulta a freedb y la metemos en un string para parsearla
! page = urllib.urlopen(self.URL+"/index.phtml?search="+grupo).read()
!
! # Buscamos todos los enlaces a los discos parseando todos los enlaces "xmcd"
discos = re.findall("\<small\>\<a href=[^\>]*\>xmcd\<\/a\>\<\/small\>",page)
***************
*** 14,25 ****
print "No se ha encontrado ningún resultado."
return
!
for disco in discos:
disc_url=re.search("disc.phtml\?[^\"\>]*", disco).group()
self.querydisc(disc_url)
def querydisc(self, disc_url):
! urllib.urlretrieve(self.URL+"/"+disc_url,"querydisc.tmp")
! page = open("querydisc.tmp").readlines()
for line in page:
if re.search("DTITLE", line):
--- 19,34 ----
print "No se ha encontrado ningún resultado."
return
!
! # Nos recorremos la lista de discos
for disco in discos:
+ # Sacamos las URLs de los discos, buscando los enlaces disc.phtml
disc_url=re.search("disc.phtml\?[^\"\>]*", disco).group()
self.querydisc(disc_url)
+ # Función que devuelve un disco determinado a partir de una determinada dirección de discos de freedb.
def querydisc(self, disc_url):
!
! # Bajamos la pagina web que contiene la informacion del disco, y lo metemos en una lista
! page = urllib.urlopen(self.URL+"/"+disc_url).readlines()
for line in page:
if re.search("DTITLE", line):
***************
*** 38,46 ****
print "Modo de uso:",sys.argv[0],"<nombre del grupo>"
sys.exit()
! for i in sys.argv[1:]:
! group=group+i+"+"
! consulta.querygroup(group[0:-1])
!
!
!
--- 47,53 ----
print "Modo de uso:",sys.argv[0],"<nombre del grupo>"
sys.exit()
! else:
! for i in sys.argv[1:]:
! group=group+i+"+"
! consulta.querygroup(group[0:-1])
|
|
From: David R. <vr...@us...> - 2001-09-27 12:39:14
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv28430
Added Files:
getlinks.py
Log Message:
Esta es la nueva version del programa para extraer todos los links a partir de una determinada
dirección web. Ha mejorado muchísimo con respecto a su primera versión, ya que hace uso del modulo
urlparse (por qué no lo encontraría yo antes?). Echale un vistazo y verás que simple se ha quedado
ahora. Le faltan 2 cosas, reconocer las páginas que sean de error 404 o las que requieran autorización
401, para descartarlas. No sé como se podría hacer.
--- NEW FILE: getlinks.py ---
from sgmllib import *
import urllib, sys, re, string, urlparse
# Expresion regular que define la base de una URL
re_url = re.compile(r"^\s*(https?|ftp|gopher)://([a-zA-Z][a-zA-Z0-9_\-]+(\.[a-zA-Z][a-zA-Z0-9_\-]+)*|([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}))")
# Ficheros donde registraremos los enlaces
logs = { "excludes" : "sic.excludes",
"links" : "sic.links",
"log" : "sic.log",
"extensions" : "sic.extensions",
"error" : "sic.error"
}
def cleanlink(link):
i = string.find(link, '#')
if i >= 0:
link = link[:i] # Remove #fragment
words = string.split(link) # Split in whitespace delimited words return
link = string.join(words, "")
return link
# Clase que se encarga de extraer las direcciones
class URLExtractor(SGMLParser):
def __init__( self , base ):
SGMLParser.__init__(self)
self.base = []
self.base.append(base) # Direccion base de descarga
self.actual='' # Direccion que estamos procesando actualmente
# Vaciamos los ficheros de log
for fichero in logs.keys():
open(logs[fichero], "w")
self.dic_urls = {} # Diccionario en el que se almacenan las ULRs visitadas y por visitar
self.noDownload = ['.pdf','.rtf','.hqx','.jpg','.gif','.jsp','.txt','.zip','.jar','.exe'] # Extensiones a no seguir
self.Download = ['.htm','.html','.thtml','.php','.pl'] # Extensiones a seguir
self.noValidURL = ['ftp','gopher']
self.noValidTAGS = ['mailto','javascript','news']
def start_a(self, attr):
# Buscamos dentro de los atributos del tag <a ...., el href
href = [ v for k,v in attr if k=='href' ]
for t in href:
# Añadimos la entrada en el log
open(logs["log"],"a+").write("Procesando el tag %s\n" % (t))
# Aqui hacemos magia. "link" será el links absoluto que queremos
link = urlparse.urljoin(self.actual, t)
if re_url.match(link) and re_url.match(link).group() in self.base:
link = cleanlink(link) # Eliminamos los # y los espacios
ruta = urlparse.urlparse(link)[2]
elem = string.split(ruta, "/")[-1]
i = string.find(elem, ".")
if i>=0:
extension = elem[i:]
if not extension in self.Download:
open(logs["excludes"], "a+").write("Enlace %s excluido de la dirección %s\n"%(link, self.actual))
return
else:
open(logs["excludes"], "a+").write("Enlace %s excluido de la dirección %s\n"%(link, self.actual))
return
# Si la URL aun no habia sido procesada y es de las que quiero procesar,
if not self.dic_urls.has_key(link):
self.dic_urls[link] = 0
open(logs["links"],"a+").write("%s\n" % (link))
# Quedan URLs por procesar ?
def has_urls(self):
return 0 in self.dic_urls.values()
# Dame una URL que no este procesada
def get_url(self):
return self.dic_urls.keys()[self.dic_urls.values().index(0)]
# Marca una URL como procesada
def use_url(self,u):
self.dic_urls[u] = 1
# Resetea el parser
def reset(self):
SGMLParser.reset(self)
def base_add(self, alias):
self.base.append(alias)
# Inicio del script
if __name__ == "__main__":
if len(sys.argv) < 2 or len(sys.argv)>1 and sys.argv[1] == "--help":
print ("Modo de uso: %s <URL de inicio> [<Dominio Alternativo>]" % (sys.argv[0]))
sys.exit()
if not re_url.match(sys.argv[1]):
print "Dirección incorrecta en el primer parámetro."
sys.exit()
else:
dir_base = re_url.match(sys.argv[1]).group()
if len(sys.argv) == 3:
if not re_url.match(sys.argv[2]):
print "Dirección incorrecta en el segundo parámetro."
sys.exit()
else:
dir_alias = re_url.match(sys.argv[2]).group()
parser = URLExtractor(dir_base)
parser.base_add(dir_alias)
else:
parser = URLExtractor(dir_base)
# Empezamos por la direccion que nos pasan como parámetro
parser.dic_urls[sys.argv[1]] = 0
url = parser.get_url()
print "URL:",url
count = 1
while url:
parser.actual=url
open(logs["log"], "a+").write("**********************************************\nDirección: %s\n\n" %(url))
print ( "%d. Procesando %s..." % (count, url))
try:
parser.feed(urllib.urlopen(url).read()) # Lanzo el parser ...
parser.close() # ... y lo cierro
except:
open(logs["error"], "a+").write("**********************************************\nDirección: %s\n\n" %(url))
parser.use_url(url) # Marco la URL como procesada
if parser.has_urls():
url = parser.get_url() # Obtengo una URL no procesada
parser.reset()
count = count + 1
else:
url = None
|
|
From: David R. <vr...@us...> - 2001-09-27 12:31:33
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv27087/pyweb
Modified Files:
freedb.py
Log Message:
Mejoradas algunas funciones de acceso a los documentos, gracias al modulo urllib.
Index: freedb.py
===================================================================
RCS file: /cvsroot/jsign/pyweb/freedb.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** freedb.py 2001/08/24 07:26:01 1.1
--- freedb.py 2001/09/27 12:31:29 1.2
***************
*** 37,42 ****
--- 37,46 ----
if len(sys.argv) == 1:
print "Modo de uso:",sys.argv[0],"<nombre del grupo>"
+ sys.exit()
for i in sys.argv[1:]:
group=group+i+"+"
consulta.querygroup(group[0:-1])
+
+
+
|
|
From: Ricardo B. D. <bo...@us...> - 2001-09-10 11:51:28
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv28690
Modified Files:
news.py
Added Files:
cddb.py
Log Message:
Soporte para CDDB en lugar de FREEDB !!
--- NEW FILE: cddb.py ---
import urllib, re, sys, string
class cddb:
def __init__(self):
self.URL="http://www.cddb.com/"
def querygroup(self,grupo):
url = self.URL + "php/search1.php3?f=artist&q=" + grupo
while url<>"":
urllib.urlretrieve(url,"querygroup.tmp")
page = open('querygroup.tmp').read()
# Buscamos todos los enlaces a los discos
discos = re.findall("\<A HREF=\"\/xm\/cd\/[^\>]*\>[^\<]*\<\/A\>",page)
if len(discos) == 0:
print "No se ha encontrado ningún resultado."
return
for disco in discos:
disc_url=re.search("xm\/cd\/[^\"\>\/]*/[^\"\>]*", disco).group()
self.querydisc(disc_url)
next = re.findall("A HREF=[^\>]*>[^;]*;NEXT",page)
if len(next) >0:
url = str(re.findall("xm[^\"]*\"",str(next)))
url = self.URL + url[2:-3]
else:
url = ""
def querydisc(self, disc_url):
urllib.urlretrieve(self.URL+disc_url,"querydisc.tmp")
page = open("querydisc.tmp").readlines()
track_n = 1
for line in page:
if re.search("f=artist", line):
artist=str(re.findall("f=artist[^\<]*\<", line))[12:-3]
artist=trans_car(artist)
disc=str(re.findall("f=disc[^\<]*\<", line))[10:-3]
disc = trans_car(disc)
track_n = 1
print "\n[" + urllib.unquote(artist) + " / " + disc +"]"
elif re.search("f=track", line):
track = str(re.findall("f=track[^\<]*\<", line))[11:-3]
track = trans_car(track)
print "\t" + string.zfill(str(track_n),2) + " - "+ track
track_n = track_n + 1
def trans_car(cad):
cad = string.replace(cad,"&","&")
cad = string.replace(cad,"'","'")
cad = string.replace(cad,""","\"")
cad = string.replace(cad,"#","#")
return cad
if __name__ == "__main__":
consulta = cddb()
group=""
if len(sys.argv) == 1:
print "Modo de uso:",sys.argv[0],"<nombre del grupo>"
for i in sys.argv[1:]:
group=group+i+"+"
consulta.querygroup(group[0:-1])
Index: news.py
===================================================================
RCS file: /cvsroot/jsign/pyweb/news.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** news.py 2001/08/31 07:10:58 1.2
--- news.py 2001/09/10 11:51:22 1.3
***************
*** 81,85 ****
if __name__ == "__main__":
! url = 'http://barrapunto.com/barrapunto.rdf'
np = NewsParser()
parse(urllib.urlopen(url), np)
--- 81,85 ----
if __name__ == "__main__":
! url = 'barrapunto.rdf'
np = NewsParser()
parse(urllib.urlopen(url), np)
|
|
From: Ricardo B. D. <bo...@us...> - 2001-08-31 14:06:28
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv16902
Modified Files:
news.py
Log Message:
He añadido una mejora en las clases de infraestructura y ademas he añadido
un primer test de envio de mensajes por maili ... (a mejorar :)
Index: news.py
===================================================================
RCS file: /cvsroot/jsign/pyweb/news.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** news.py 2001/08/28 07:58:05 1.1
--- news.py 2001/08/31 07:10:58 1.2
***************
*** 1,5 ****
--- 1,7 ----
from xml.sax import *
import urllib, sys
+ from smtplib import SMTP
+ # Clases definidas en el documento RDF =====================================================
class RDFElement:
def __init__(self):
***************
*** 7,18 ****
--- 9,34 ----
self.link = ""
+ def __str__(self):
+ return '<a href="' + self.link + '">' + self.title + '</a>'
+
class Channel(RDFElement):
def __init__(self):
self.desc = ""
+ def __str__(self):
+ out = '<h1>Bienvenido al canal <a href="' + self.link + '">' + self.title + '</a><br>'
+ out = out + self.desc + '<br>'
+ return out
+
class Image(RDFElement):
def __init__(self):
self.url = ""
+ def __str__(self):
+ out = '<a href="' + self.link + '">' + self.title + '</a>'
+ out = out + '<img src="' + self.url + '">'
+ return out
+
+ # Clase que se encarga de parsear el documento de noticias y de extraer el texto ===========
class NewsParser(ContentHandler):
def __init__(self):
***************
*** 21,24 ****
--- 37,41 ----
self.news = []
self.actual = None
+ self.output = ""
def startElement(self, name, attributes):
***************
*** 51,72 ****
def endDocument(self):
! sys.stdout.write('<html>' + '\n')
! sys.stdout.write(' <body>' + '\n')
for item in self.news:
! if isinstance(item, Channel):
! sys.stdout.write(' <h1>Bienvenido al canal <a href="' + item.link + '">' + item.title + '</a><br>' + '\n')
! sys.stdout.write(' ' + item.desc + '<br>\n');
! elif isinstance(item, Image):
! sys.stdout.write(' <a href="' + item.link + '">' + item.title + '</a>' + '\n')
! sys.stdout.write(' <img src="' + item.url + '">' + '\n')
! else:
! sys.stdout.write(' Nuevo articulo<br>' + '\n')
! sys.stdout.write(' <a href="' + item.link + '">' + item.title + '</a>' + '\n')
! sys.stdout.write(' </body>' + '\n')
! sys.stdout.write('</html>' + '\n')
if __name__ == "__main__":
! url = 'http://slashdot.org/slashdot.rdf'
! parse(urllib.urlopen(url), NewsParser())
--- 68,89 ----
def endDocument(self):
! self.output = '<html>\n'
! self.output = self.output + '<body>\n'
for item in self.news:
! self.output = self.output + ' ' + str(item) + '\n'
! self.output = self.output + ' </body>\n'
! self.output = self.output + '</html>\n'
!
! def getOutput(self):
! return self.output
if __name__ == "__main__":
! url = 'http://barrapunto.com/barrapunto.rdf'
! np = NewsParser()
! parse(urllib.urlopen(url), np)
!
! a = SMTP('mail.uji.es')
! sys.stdout.write(np.getOutput())
! a.sendmail('bo...@si...','bo...@si...', np.getOutput())
|
|
From: Ricardo B. D. <bo...@us...> - 2001-08-28 07:58:10
|
Update of /cvsroot/jsign/pyweb
In directory usw-pr-cvs1:/tmp/cvs-serv22456
Added Files:
news.py
Log Message:
Utilidad para conectarse al "slashdot" u otro servidor que ofrezca noticias en
format RDF, y generar una página HTML con el resultado del parsing.
--- NEW FILE: news.py ---
from xml.sax import *
import urllib, sys
class RDFElement:
def __init__(self):
self.title = ""
self.link = ""
class Channel(RDFElement):
def __init__(self):
self.desc = ""
class Image(RDFElement):
def __init__(self):
self.url = ""
class NewsParser(ContentHandler):
def __init__(self):
self.nextTag = ""
self.endOf = ""
self.news = []
self.actual = None
def startElement(self, name, attributes):
self.nextTag = name
if name == 'channel':
self.actual = Channel()
elif name == 'item':
self.actual = RDFElement()
elif name == 'image':
self.actual = Image()
def endElement(self,name):
self.endOf = name
self.nextTag = ""
if name in ['channel','image','item']:
self.news.append(self.actual)
def characters(self, content):
if self.nextTag:
if self.nextTag == 'title':
self.actual.title = content
elif self.nextTag == 'link':
self.actual.link = content
elif self.nextTag == 'description':
self.actual.desc = content
elif self.nextTag == 'url':
self.actual.url = content
def endDocument(self):
sys.stdout.write('<html>' + '\n')
sys.stdout.write(' <body>' + '\n')
for item in self.news:
if isinstance(item, Channel):
sys.stdout.write(' <h1>Bienvenido al canal <a href="' + item.link + '">' + item.title + '</a><br>' + '\n')
sys.stdout.write(' ' + item.desc + '<br>\n');
elif isinstance(item, Image):
sys.stdout.write(' <a href="' + item.link + '">' + item.title + '</a>' + '\n')
sys.stdout.write(' <img src="' + item.url + '">' + '\n')
else:
sys.stdout.write(' Nuevo articulo<br>' + '\n')
sys.stdout.write(' <a href="' + item.link + '">' + item.title + '</a>' + '\n')
sys.stdout.write(' </body>' + '\n')
sys.stdout.write('</html>' + '\n')
if __name__ == "__main__":
url = 'http://slashdot.org/slashdot.rdf'
parse(urllib.urlopen(url), NewsParser())
|
|
From: Ricardo B. D. <bo...@us...> - 2001-08-24 09:58:32
|
Update of /cvsroot/jsign/src/es/uji/signclient/xml In directory usw-pr-cvs1:/tmp/cvs-serv27855 Modified Files: SignConfiguration.java Log Message: Index: SignConfiguration.java =================================================================== RCS file: /cvsroot/jsign/src/es/uji/signclient/xml/SignConfiguration.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SignConfiguration.java 2001/08/24 09:55:31 1.2 --- SignConfiguration.java 2001/08/24 09:58:29 1.3 *************** *** 17,21 **** <!ELEMENT ws_port (#PCDATA)> <!ELEMENT p_host (#PCDATA)> ! <!ELEMENT p_port (#PCDATA)> */ --- 17,22 ---- <!ELEMENT ws_port (#PCDATA)> <!ELEMENT p_host (#PCDATA)> ! <!ELEMENT p_port (#PCDATA)> ! */ |
|
From: Ricardo B. D. <bo...@us...> - 2001-08-24 09:55:35
|
Update of /cvsroot/jsign/src/es/uji/signclient/xml In directory usw-pr-cvs1:/tmp/cvs-serv27072 Modified Files: SignConfiguration.java Log Message: Index: SignConfiguration.java =================================================================== RCS file: /cvsroot/jsign/src/es/uji/signclient/xml/SignConfiguration.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SignConfiguration.java 2001/07/24 09:48:47 1.1.1.1 --- SignConfiguration.java 2001/08/24 09:55:31 1.2 *************** *** 1,5 **** package es.uji.signclient.xml; ! /** DTD File: <!ELEMENT root (log_file, sign_servlet, x509, jdbc, webserver, proxy?)> <!ELEMENT x509 (cert_file, ks_password?)> --- 1,5 ---- package es.uji.signclient.xml; ! /** DTD Document File: <!ELEMENT root (log_file, sign_servlet, x509, jdbc, webserver, proxy?)> <!ELEMENT x509 (cert_file, ks_password?)> |