Skip to content

Instantly share code, notes, and snippets.

@Fabiensk
Created May 2, 2015 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fabiensk/41ba8352f4663e941ba0 to your computer and use it in GitHub Desktop.
Save Fabiensk/41ba8352f4663e941ba0 to your computer and use it in GitHub Desktop.
Search in Wikivoyage history dump
#!/usr/bin/python
import sys, re
def check(expr, text):
res = expr.search(text)
if res==None:
return None
return res.group(1)
def main():
re_ip = re.compile("<ip>(.*)</ip>")
re_user = re.compile("<username>(.*)</username>")
re_timestamp = re.compile("<timestamp>(.*)</timestamp>")
fn = sys.argv[1]
text = " ".join(sys.argv[2:]).strip()
if len(text)==0:
print("No text")
return
f = open(fn, "rt")
ip = None
user = None
timestamp = None
for line in f:
tmp = check(re_ip, line)
if tmp!=None:
ip = tmp
user = None
continue
#
tmp = check(re_user, line)
if tmp!=None:
ip = None
user = tmp
continue
#
tmp = check(re_timestamp, line)
if tmp!=None:
timestamp = tmp
continue
#
if line.find(text)!=-1:
print("Found: {}, {}".format(ip or user, timestamp))
return
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment