
09-17-2007
|
| Administrator
Join Date: Jun 2007
Posts: 3,729
BRL$: 35,139.65 Thanks: 0
Thanked 7 Times in 7 Posts
Rep Power: 406 | | Short python script to php Hi All. Never registered, but been browsing around in here for a while now.I've been charged with getting a visual html diff. The closest I've found is a python script. Unfortunately our host will not install mod_python and we have limited control over .ht* files. Could someone familiar with both python and php possibly convert this script? I've been working on this myself but am totally confused and lost...Code:---------import difflib, stringdef isTag(x): return x[0] == ""def textDiff(a, b): """Takes in strings a and b and returns a human-readable HTML diff.""" out = [] a, b = html2list(a), html2list(b) s = difflib.SequenceMatcher(None, a, b) for e in s.get_opcodes(): if e[0] == "replace": # @@ need to do something more complicated here # call textDiff but not for html, but for some html... ugh # gonna cop-out for now out.append(''+''.join(a[e[1]:e[2]]) + ''+''.join(b[e[3]:e[4]])+"") elif e[0] == "delete": out.append(''+ ''.join(a[e[1]:e[2]]) + "") elif e[0] == "insert": out.append(''+''.join(b[e[3]:e[4]]) + "") elif e[0] == "equal": out.append(''.join(b[e[3]:e[4]])) else: raise "Um, something's broken. I didn't expect a '" + `e[0]` + "'." return ''.join(out)def html2list(x, b=0): mode = 'char' cur = '' out = [] for c in x: if mode == 'tag': if c == '>': if b: cur += ']' else: cur += c out.append(cur); cur = ''; mode = 'char' else: cur += c elif mode == 'char': if c == ' | |
__________________ █ High Quality To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
█ Powerful To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
█ To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
To receive latest updates about BRL Forums, Subscribe to Latest Updates Thread.
| | | |