User:Jhawthorn/linkconvert
Jump to navigation
Jump to search
A little python script I threw together to convert links to the MegaTokyo board to the new phpbb board on osdev.org Accepts anything with a threadid= or start=msg followed by a number including a full URL.
Standalone version
- N.B. This still requires python, just not topic_map.txt or message_map.txt
Download from http://www.osdev.org/mediawiki/images/c/ce/Linkconvert.zip
Using external files
This requires the files topic_map.txt and message_map.txt to be in the current directory. They are available from zip archives here: http://www.osdev.org/phpBB2/viewtopic.php?p=83433#83433
#!/usr/bin/env python """ A little python script I threw together to convert links to the MegaTokyo board to the new phpbb board on osdev.org Accepts anything with a "threadid=" or "start=msg" followed by a number including a full URL. """ import re import sys topics = file("topic_map.txt").read() messages = file("message_map.txt").read() def search(f, number): regex = re.compile("".join((number, ",\d+")),) s = re.search(regex, f) if s: return s.group()[len(number)+1:] else: return None data = sys.stdin.readline() while data: s1 = re.search(re.compile("start=msg\d+"), data) s2 = re.search(re.compile("threadid=\d+"), data) if s1: s = search(messages, s1.group()[9:]) print "".join(("http://www.osdev.org/phpBB2/viewtopic.php?p=", s, "#" , s)) elif s2: s = search(topics, s2.group()[9:]) print "".join(("http://www.osdev.org/phpBB2/viewtopic.php?t=", s)) data = sys.stdin.readline()