Advertisement
Guest User

Untitled

a guest
May 24th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1.  
  2. #!/usr/bin/python
  3. #coding utf8
  4.  
  5. import sys
  6. import os
  7. import re
  8.  
  9. def readJson() :
  10.  
  11. curDir = "./"
  12.  
  13. pattern = re.compile("^introduce_[\d]+.json$")
  14.  
  15. for dir in os.listdir(curDir) :
  16.  
  17. if pattern.match(dir) == None:
  18. continue
  19.  
  20. json = open(dir, "r")
  21.  
  22. jsonContent = formatJson(json)
  23.  
  24. json.close()
  25.  
  26. newjson = open('../jsons/'+ os.path.splitext(dir)[0]+'.json', "a")
  27.  
  28. newjson.write(jsonContent)
  29.  
  30. newjson.close( )
  31.  
  32. def formatJson(json) :
  33. pattern = re.compile("\"introduce\": \"")
  34.  
  35. jsonContent = ""
  36.  
  37. for line in json:
  38.  
  39. if pattern.match(line) != None:
  40.  
  41. line = re.sub(pattern, "\"introduce\": \"        ", line)
  42.  
  43. pattern = re.compile("<br>")
  44.  
  45. line = pattern.sub('<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', line)
  46.  
  47. pattern = re.compile("<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"")
  48.  
  49. line = pattern.sub('<br>', line)
  50.  
  51. jsonContent += line
  52.  
  53. return jsonContent
  54.  
  55. if __name__ == '__main__':
  56.  
  57. readJson()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement