Created
August 7, 2009 11:44
-
-
Save prasincs/163858 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Search Links in markdown files | |
# Author: Prasanna Gautam | |
# Usage: search-link.py <regular-expression> | |
# | |
import sys | |
import glob | |
import re | |
linksDict = {} | |
def buildLinkDict(): | |
p = re.compile(r'\[(.+)\](?:\s+)?\(?(.+)\)?') | |
for fileName in glob.glob("*.mkd"): | |
f = open(fileName) | |
for line in f.readlines(): | |
m = p.match(line) | |
if m: | |
linksDict[m.group(1)] = m.group(2) | |
def main(): | |
"""docstring for main""" | |
buildLinkDict() | |
searchTerm = sys.argv[1] | |
for key in linksDict: | |
if re.search(searchTerm,key): | |
print key, linksDict[key] | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment