Skip to content

Instantly share code, notes, and snippets.

@yanunon
Created April 21, 2013 04:40
Show Gist options
  • Save yanunon/5428502 to your computer and use it in GitHub Desktop.
Save yanunon/5428502 to your computer and use it in GitHub Desktop.
将Android文档中Google Analytics的js链接去掉,方便离线阅读
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright © 2013 Yang Junyong <yanunon@gmail.com>
import sys
import os
GA_JS_STR = 'document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));'
def main(doc_dir):
for r in os.walk(doc_dir):
for filename in r[2]:
fpath = os.path.join(r[0], filename)
ext = fpath[fpath.rfind('.')+1:]
if ext.lower() != 'html':
continue
f = open(fpath, 'r')
fs = f.read()
f.close()
fs = fs.replace(GA_JS_STR, '')
f = open(fpath, 'w')
f.write(fs)
f.close()
if __name__ == '__main__':
doc_dir = '.'
if len(sys.argv) > 2:
doc_dir = sys.argv[1]
main(doc_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment