Python program for Tech Support Cheat Sheet

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

SmartViking
Posts: 7
Joined: Sun Feb 06, 2011 11:04 am UTC

Python program for Tech Support Cheat Sheet

Postby SmartViking » Sun Feb 06, 2011 5:44 pm UTC

Hello, I saw the comic located at http://xkcd.com/627/ not too long ago, and I think it was kind of funny, because of the fact that the sheet could look very much like a real computer program which made it pretty ironic.
And I decided I should make a real program out of it, because when you have the sheet right in front of you it's simpler to do. The source code will be quoted into phpBB "code" at the bottom of this post, but read the post for higher usability gain.
The program should be pretty bug-less but I haven't played around with it so much, so I can't tell for sure.
By default, the program will act exactly(unless I've made a typo) the same as the comic.


The supported arguments:
  • --version
    ^ No biggie it's just there.
  • --nointro
    ^ Removes the default intro information about the programs origin, and goes right into problem solving mode.
  • --bugfix
    ^ It removes a bug from the original sheet where the human element would be trapped inside a start()-working()-times() loop that wouldn't get anywhere. How ever then it's not completely the same as the comic so it's only an argument.
  • --about
    ^ Just some "about" thing, that modifiers can eventually add themselves on to if they change anything and want to give it to someone else
No IDEs have been touched in the making of this program


(I'm new to this forum so I don't know which kinds of people hang out here)

For people who want to run it: This will work on all operative systems with the python interpreter installed, if it doesn't then it would only need very small changes to run(ie, if it doesn't run in ™©Windows©™, remove the shebang line(#/usr/bi..)).
If you are using Linux, you probably already have the python interpreter installed, and on "OSX" the situation should be much the same but I have no idea. To make it run on a *nix system, copy-paste the source code into a text file, give yourself permissions to execute it(chmod +x filename), and run from the shell.

For developers: I've done some small changes to the source to make it easier to read. Read all the comments and you should be able to follow the program pretty nicely.
But there is of course a much better tool, the sheet itself, here is an image with the sheet, and all the functions with arrows so you can understand what does what, it should help a lot: http://smartviking.com/pictures/overview.png

For moderators: I read about the links rule but since I have used quite a while to make this program I think this should be allowed as an exception. I read a few threads on this forum, but I couldn't find anything to say. Therefore I took the chance and posted this anyway, because I simply doesn't have time to post 5 good posts right now, if I where to post anything it would only be stupid posts that where in the way, so it wouldn't help in any way In this particular case, the contribution is worth an exception.

I hope you like it, and be sure to post what you think about it! :)

Code: Select all

#!/usr/bin/env python
## pass --nointro as an argument for not including the introduction part
# Added lines of #'s between functions definitions to make the program easier to read.
import sys, time
intro = 1
bugfix = 0
for argument in sys.argv:
  if argument == "--version":
    print "Uhm.. version.. 0.1 lets go with that."
    sys.exit(0)
  if argument == "--nointro":
    intro = 0
  if argument == "--bugfix":
    bugfix = 1   
  if argument == "--about":
    #Add yourself under me with whatever you did, or simply take away the "--about" argument if thats what you want.
    print "Originally created by Smart Viking"

    sys.exit(0)
#######  The function under, before main, is simply there for creating new definitions fast under development
#The reason i can use the "buttonmenu" variable on all functions is because a variable only exists in the function unless you make it otherwise
# def replace():
#   print ""
#   buttonmenu = raw_input("[/]>: ")
#   if buttonmenu == "" or buttonmenu == "":
#     action
#   elif buttonmenu == "" or buttonmenu == "":
#     action
#   elif buttonmenu == "quit" or buttonmenu == "exit":
#     print "later..."
#     sys.exit(0)
#   else:
#     print "not an option"
#     replace()
####### Define main()
def main():
  if intro:
    print """This program is inspired by an xkcd comic, which can be located here: http://xkcd.com/627/ """
    print "This simple guide should help you to solve your computer problems.\n"
    print "Use your keyboard to navigate through this helpful program."
###########################################################################################
  def start():
    print """
    Find a menu item or button which looks related to what you want to do.

A/a)  Ok"""
    if bugfix:
      print "B/b)  I can't find one and i have been trying to fix this for more than 10 minutes"
    else:
      print "B/b)  I can't find one"

    buttonmenu = raw_input ("\033[1m[a/b]>: \033[0m")
    if buttonmenu == "a" or buttonmenu == "A":
      print "Click it."
      time.sleep(1.5)
      working()
    elif buttonmenu == "b" or buttonmenu == "B":
      rando()
    elif buttonmenu == "quit" or buttonmenu == "exit":
      print "\nlater..."
      sys.exit(0)
    else:
      print "not an option"
      start()
############################################################################################
  def working():
    print """
    Did it work?

Y/y)  Yes
N/n)  No"""
    buttonmenu = raw_input("\033[1m[n/y]>: \033[0m")
    if buttonmenu == "y" or buttonmenu == "Y":
      print "You are done! :D"
      time.sleep(3)
      sys.exit()
    elif buttonmenu == "n" or buttonmenu == "N":
      times()
    elif buttonmenu == "quit" or buttonmenu == "exit":
      print "\nlater..."
      sys.exit(0)
    else:
      print "not an option"
      working()
############################################################################################
  def times():
    print """
    Have you been trying this for over half an hour?

Y/y)  Yes
N/n)  No"""
    buttonmenu = raw_input("\033[1m[y/n]>: \033[0m")
    if buttonmenu == "y" or buttonmenu == "Y":
      print "\n    Ask someone for help or give up."
      time.sleep(3)
      sys.exit(0)
    elif buttonmenu == "n" or buttonmenu == "N":
      start()
    elif buttonmenu == "quit" or buttonmenu == "exit":
      print "\nlater..."
      sys.exit(0)
    else:
       print "not an option"
       times()
############################################################################################
  def rando():
    print """
    Pick one at random.

A/a)  Ok
B/b)  I've tried them all"""
    buttonmenu = raw_input("\033[1m[a/b]>: \033[0m")
    if buttonmenu == "a" or buttonmenu == "A":
      print "Click it."
      time.sleep(2)
      working()
    elif buttonmenu == "b" or buttonmenu == "B":
      print """
    Google the name of the program plus a few words related to what you want to do. Follow any instructions.
"""
      raw_input("press enter...")
      working()
    elif buttonmenu == "quit" or buttonmenu == "exit":
      print "\nlater..."
      sys.exit(0)
    else:
      print "not an option"
      rando()
############################################################################################
############################################################################################

  #This is where start() get executed, the rest of the program will bounce around by launching different functions based upon the user input
  start()
#This is where the program gets executed after reading the function definitions
main()

EDIT: There was a very ugly mix of tabs and spaces in the code, the python interpreter for some reason did not like the continuous random indention caused by different settings in different editors. fixed.

User avatar
Jorpho
Posts: 6279
Joined: Wed Dec 12, 2007 5:31 am UTC
Location: Canada

Re: Python program for Tech Support Cheat Sheet

Postby Jorpho » Thu Feb 10, 2011 2:46 am UTC

Interesting.

You know something like getopt or argparse might be a good idea if you add more command-line arguments for some reason, right?

SmartViking
Posts: 7
Joined: Sun Feb 06, 2011 11:04 am UTC

Re: Python program for Tech Support Cheat Sheet

Postby SmartViking » Fri Feb 11, 2011 10:31 am UTC

Jorpho wrote:Interesting.

You know something like getopt or argparse might be a good idea if you add more command-line arguments for some reason, right?


Yeah have heard of it. Never used it though, I'm pretty new to programming and python, and with the programs I have made so far a simple for loop have been working well, but when I'm going to assign values and the like with arguments I could see that it would be more efficient to use a module. :)

User avatar
Mat
Posts: 414
Joined: Fri Apr 21, 2006 8:19 pm UTC

Re: Python program for Tech Support Cheat Sheet

Postby Mat » Wed Feb 16, 2011 8:15 pm UTC

I think it should track how long you have been running the program instead of prompting the user. That way you don't need the bugfix :)

Also, my 2c on the code: maybe try modelling it like a state machine rather than having functions for each state that are all intermingled with each other. e.g. something like:

Code: Select all

class ProblemSolver:
  def __init__(self):
    start = State('Start')
    menu = State('Find a menu..')
    click = State('click it')
    pick = State('pick one')
    menu.choices.extend((Action('ok',click),Action('cant find one',pick))) = click
    start.choices.append(Action('start',menu))
    ...
    self.state = start
    self.final = end

  def run(self):
    while self.state is not self.final:
      self.state = self.state.next()

class State:
  def __init__(self, text):
    self.text = text
    self.choices = []

  def next(self):
    print self.text

    if len(self.choices) > 1:
      # prompt for choice and return new state
    else:
      return self.choices[0].target

class Action:
  def __init__(self, text, target):
    self.text = text
    self.target = target

SmartViking
Posts: 7
Joined: Sun Feb 06, 2011 11:04 am UTC

Re: Python program for Tech Support Cheat Sheet

Postby SmartViking » Thu Feb 17, 2011 1:29 pm UTC

That's probably a better solution, with the classes. I don't know how to make them though, as I haven't gotten so much into classes. I tried implementing a class for shooting on my top down shooter and I just failed, even though classes seems pretty easy it gets so much harder when you want to do it yourself with your own stuff. I'm learning though, I might do something like that when I understand classes more in the future. I've only been into python(and programming) for some months, there's an awful lot of lego bricks that needs to get placed, so much new ztuff to learn. But of course as with anything you learn faster and faster as you try, when I see other programming languages, I can somehow understand them even though I've never tried them before so that's awesome. :) (Don't know if any of that made sense)
EDIT: What is especially interesting is how one day something looks totally greek a week later you know how to do it, you think your brain would soon get full of information, unable to store more of it but it's an amazing organ, it never seems to run out of storage. :)

archeleus
Posts: 240
Joined: Wed Sep 29, 2010 1:49 pm UTC
Location: Valenvaryon
Contact:

Re: Python program for Tech Support Cheat Sheet

Postby archeleus » Thu Feb 17, 2011 4:34 pm UTC

Spoiler:
Image


Code: Select all

printf("Have you tried turning it off and on again?\n");


(Just fucking google it/RTFM would also work).
I write a blog rant here.

SmartViking
Posts: 7
Joined: Sun Feb 06, 2011 11:04 am UTC

Re: Python program for Tech Support Cheat Sheet

Postby SmartViking » Thu Feb 17, 2011 5:20 pm UTC

archeleus wrote:
Spoiler:
Image


Code: Select all

printf("Have you tried turning it off and on again?\n");


(Just fucking google it/RTFM would also work).


What's with the negative attitude? Of course I've google'd it, and of course I read the manual, but it takes time to learn new things, and I'm ok with that, 'tis how it works.

User avatar
Jorpho
Posts: 6279
Joined: Wed Dec 12, 2007 5:31 am UTC
Location: Canada

Re: Python program for Tech Support Cheat Sheet

Postby Jorpho » Thu Feb 17, 2011 6:13 pm UTC

I believe Mr. Archeleus intended that line as a succinct replacement for the flow chart in general rather than as a personal directive.

User avatar
Dason
Posts: 1311
Joined: Wed Dec 02, 2009 7:06 am UTC
Location: ~/

Re: Python program for Tech Support Cheat Sheet

Postby Dason » Thu Feb 17, 2011 7:29 pm UTC

Jorpho wrote:I believe Mr. Archeleus intended that line as a succinct replacement for the flow chart in general rather than as a personal directive.

I was under the same impression.
double epsilon = -.0000001;


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 7 guests