Created
May 2, 2015 20:11
-
-
Save Fabiensk/41ba8352f4663e941ba0 to your computer and use it in GitHub Desktop.
Search in Wikivoyage history dump
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/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