Advertisement
Guest User

NEERC Standings Filter

a guest
Dec 4th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import re
  3.  
  4. team_re = re.compile('<td class="party">(.*?)</td>')
  5. data = open("standings.html").read()
  6.  
  7. seen_uni = set()
  8. replacements = set()
  9.  
  10. data = data.replace('../standings-wt.css','http://neerc.ifmo.ru/standings-wt.css')
  11.  
  12. c = 0
  13. for match in team_re.finditer(data):
  14. match = match.groups()[0]
  15. uni, team = match.rsplit('(', 1)
  16. uni, team = uni.strip(), '(' + team
  17. su = uni[:-1] if uni[-1].isdigit() else uni
  18. if su in seen_uni:
  19. replacements.add((match, '<del>%s</del>' % match))
  20. else:
  21. c += 1
  22. replacements.add((match, '<b>%d:</b> %s' % (c, match)))
  23. seen_uni.add(su)
  24.  
  25. for x, y in replacements:
  26. data = data.replace('<td class="party">%s</td>' % x, '<td class="party">%s</td>' % y)
  27.  
  28. with open("standings-unique.html", "wb") as f:
  29. f.write(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement