[Python] WolframAlpha - Feedback please!

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Hey guys!

One of the things I've been trying to do this semester at college, is to get ALL of my notes and stuff completely on a computer. It hasn't been hard with notes, but this semester I took a math class. So, I started using Google Docs, with their equation editor to take my math notes on the computer.

I've also been using Wolfram Alpha consistently to graph equations (or simply to look them up, for homework), but it's a slow process when I have a ton of equations to do.

Instead, of constantly opening up new tabs, I decided to write a program to do it for me:

Code:
import os,sys

FIREFOX = '"C:\\Program Files\\Mozilla Firefox\\firefox.exe"'
WOLFRAMALPHA = 'http://www.wolframalpha.com/input/?i='
wolframList = []

if (sys.argv):
    sys.argv.pop(0)
    
if (not sys.argv):
    print "Please enter an equation: "
    wolframList.append(raw_input(':').strip())
    
for arg in sys.argv:
    if os.path.exists(arg):
        if os.path.isfile(arg):
            with open(arg) as f:
                for line in f:
                    wolframList.append(line)
        else:
            wolframList.append(arg)
    else:
        wolframList.append(arg)
        

for equation in wolframList: 
    os.system(FIREFOX + " " + WOLFRAMALPHA +  equation.replace('+','%2B').replace(' ','+'))

Basically the program is made to be run from command line. If you simply run it without any arguments, it will ask you to input an equation. If you run it and give it an equation (such "5 + 12pi"), or even multiple equations (such as "5","42","3.14159"), it will use these equations. If you give it a file, it will open that file and use each line as an equation.

Then, it will open all the equations into Firefox Tabs.

Anyone have any feedback they're willing to share about the code or the idea? :)
 

Xienoph

You can change this now in User CP.
Reaction score
43
Instead of doing the URL encoding yourself, why not use urllib.urlencode?

Also, it is "best practice" to do file pathing using an available path library. That way, you can make your code run in multiple platforms.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top