Have I mentioned that Python is my favouritest programming language ever? If not I am mentioning it now. Granted, I am a nub at programming, last year I knew no programming language and didn't intend to learn more than what I would at University (which to my knowledge was just java) I couldn't even TOUCH Linux. Now it's my prefered choice for OS (though only Ubuntu, I'm still learning ;) )
Oh god I sound so blooming
smug in that paragraph.
Though I might like to point out that I'm a nub to computing (the last year has shown me that), I don't actually
like talking about how amazing I am at these things. I feel that some elitist is about to look at what I have written and sneer and chortle at my nubishness.
"Python? Ubuntu? What lark! What an uneducated individual but I suppose simple things please simple minds ;)"I don't really have to imagine it since I already know someone like that. Lets say his name is Phil (it isn't actually). Phil is a know-it-all/cynical cunt/elitist and although I don't mind his crap he does annoy the crap out of me so that the only option I have is trolling him, which is not difficult. All I have to say is "The only useful command in vim is :q" and watch him blather about how I'm wrong and that vim is the best damn text editor in the world putting him in the pool of fanboyism that I shown with Python or Ubuntu.
However as much as I'd like to talk about my crazy adventures with Phil I wanted to get to my original point. I
really like Python. Not as much as i'd make a
website dedicated to how amazing the programming language I like is, but more to a point where it's would be the only language I'd use. Of course that doesn't make much sense but to be honest, me and Python was like (and mind the cheesyness of this) the perfect couple. Ok it's simple, but that's how programming should be. Writing about 4 lines of code that look like english is easier than writing what seems to be like advanced maths.
Would this mean I'd like
ruby? Possibly, but I'd prefer to stay faithful to my lover. Also I can't think how I would do
one-line-solutions for
Project Euler with ruby. I'll stick with what I know at the moment.
Anyway, what I was getting to is that I like to use Python anywhere I can. I sneak it in my Pseudocode. I make solutions with it that are smaller than my Java ones. I even use it at work. Really.
I am bilingual (i.e. I know English and Welsh), and this summer I've been lucky to get a job doing translating. Not quite what I was made for. Just because someone is able to speak two language doesn't really mean that they can translate perfectly between the two. Luckily for me I have someone helping me however this person is not the fluent in welsh and therefore I have to help her tel her what is a particular word was and whatnot.
Anyway, I had enough of checking the dictionary myself and sent the online dictionary to her. The problem was that if one dictionary didn't have a word the other would and so you'd have to look in all of them (which was 3 in total, not much but still a pain to look over). The other thing was that you'd have to switch to "English to Welsh" mode before sending the word otherwise it wouldn't find anything. What I needed therefore was a little thing that would get the word and show a list of the welsh vesion. This in Python was as simple as importing the webbrowser module and doing the following:
webbrowser.open("http://www.bbc.co.uk/cgi-bin/wales/learnwelsh/welsh_dictionary.pl?gair="+raw_input("What is the word?: "))
A few problems came from this. It was only one dictionary so:
word = raw_input("What is the word?: ")
webbrowser.open("http://www.bbc.co.uk/cgi-bin/wales/learnwelsh/welsh_dictionary.pl?gair="+word)
webbrowser.open('http://www.geiriadur.net/atebion.php?term='+word+'&direction=ew&type=all&whichpart=exact')
This gave a seperate problem since it only gave the last webpage. Funnily enough I managed to make it pop up two windows in Visual Basic (using the macro maker in word as a guide) I also managed to make it little bit more clever by looking for the word that someone has selected instead of having to type it in. I felt that having 2 popups was a bit too much though. Plus the websites were pretty distracting.
My plan was therefore to grab the data of both pages keep the useful data and print it out on one page. While the first (urllib2) and last (webbrowser) was simple the middle (re) was a bit tricky. I had no experience whatsoever with regular expressions, still I tried. After hours of figuring out why it wasn't working I ended up having to remove any \n, \t and \r characters so that the whole webpage HTML was on one line. Numerous fiddling about and the thing was working.
However I wanted to do what I did with the first version (i.e. a select word and push butan thing). The VisualBasic was easy however the way I had to get it working was to have the VB pointing to:
"..../Dictionary2.py " + Word
Also I thought I should have it as an exe since other people are going to use this. This was something that Phil was going to laugh at. "What you want to use py2exe so you can make buggy programs? HA!". Fortunately I ignored him and did the program anyway. You can get it with the link below (This contains the code as well):
AFALS ENGLISH TO WELSH DICTIONARY GRABBERIf you want to know the final what the VB script is so you can run it in Word it's this:
TheWord = "[whatever the path is]Dictionary2.exe " + Selection.Text
Shell TheWord, vbMinimizedFocus
(Funnily enough I got Phil to see the code. He found nothing wrong)
To use it either use the VB script, double click it and type in the word you want or in command line just use "Dictionary2.exe [whatever the word is]". THIMPLE.
Known quirks: Firefox complains when trying to run it. However the list is made if you just look at "Dictionary.html" in the folder.Now the next step is to get this thing to do my work for me...