1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
def pilote(fichier, dex) :
flux = open(fichier, 'r')
for n, ligne in enumerate(flux) :
dex = indexe(dex, ligne.split(), n + 1)
flux.close()
prd(dex)
return dex
ponctuation = '(/-+,.")'
def nettoie(mot) :
new = ''
for x in mot :
if x not in ponctuation : new += x
else : pass
return new
def get_href(ligne) :
x = ligne.find('href=')
if x < 0 : return
ref = ligne[x+6:].split('"')[0]
if ref.startswith('http:') : return ref
def indexe(dex, mots, ligne) :
hrefs = []
for ligne in dex : hrefs.append(get_href(ligne))
for mot in mots :
mot = nettoie(mot)
if mot.lower() in go_get_list() : dex = ajoute(dex, mot, ligne)
else : pass
return dex
def ajoute(dex, mot, ligne) :
if mot in dex :
if ligne in dex[mot] : pass
else : dex[mot].append(ligne)
else : dex[mot] = [ligne]
return dex
stoplist = 'ce de du en le in la mais on ou par pas pour qui un une'.split()
golist = 'forums accessibles main Server universitaires fermeture organisation versions tools shrubbery '.split()
def prd(d) :
for c in sorted(d) :
print '\t', c, ':', d[c]
def put_list(golist) :
flux = open('go.list', 'w')
flux.write('\n'.join(golist))
flux.close()
def go_get_list() :
flux = open('go.list', 'r')
get = flux.read().split()
flux.close()
return get
def put_list(stoplist) :
flux = open('stop.list', 'w')
flux.write('\n'.join(stoplist))
flux.close()
def get_list() :
flux = open('stop.list', 'r')
stoplist = flux.read().split()
flux.close()
return stoplist |
Partager