Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import cgi
  4. import re
  5. form = cgi.FieldStorage()
  6.  
  7. searchParam = form.getvalue('searchString')
  8.  
  9. print('Content-type:text/html\n')
  10. print('<!DOCTYPE html>')
  11. print('<html><body>')
  12. print('<p>',searchParam,'</p>\n<hr>')
  13.  
  14. with open('test2_animals_1.txt') as f:
  15. fileData = f.readlines()
  16.  
  17. for index, line in enumerate(fileData):
  18. print('<p>Line ', index+1, ' - ', line, '</p>')
  19. print('<p>Total number of lines in the file = ', len(fileData), '</p>\n<hr>')
  20.  
  21. matchedLines = 0
  22. unmatchedLines = 0
  23.  
  24. print("<h1>Lines that don't contain '", searchParam, "'</h1>")
  25. for line in fileData:
  26. if(re.search(searchParam, line) == None):
  27. unmatchedLines+=1
  28. print("<p>", line, '</p>')
  29. else:
  30. matchedLines+=1
  31.  
  32. print('<p>Lines matching input string: ', matchedLines, '</p>')
  33. print('<p>Lines not matching input string: ', unmatchedLines, '</p>')
  34.  
  35. print('</body></html>')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement