ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Test_URL.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
File size: 3493 byte(s)
Log Message:
Initial Import

File Contents

# User Rev Content
1 ninoborges 8 ##This is a program written for Patty Mason to connect to 150 + URLs and test
2     ##if they are working. This program will read the URLs from a comma seperated
3     ##file and test each URL's connection
4     #Eborges
5     #04.16.02
6    
7     import urllib, sys, string
8    
9     class GUI:
10     def __init__(self,root,input_file, output_file):
11     root.title("URL Tester")
12     #input_file = "None \t \t "
13     #output_file = "None"
14     Label(root, text="Welcome").pack(side=TOP)
15     Label(root, text="Input File: ").pack(side=LEFT)
16     e=StringVar()
17     Entry(root,state = "disabled", width = 10, textvariable=e).pack(side=LEFT)
18     e.set(input_file)
19     Label(root, text="\tOutput File: "+output_file).pack(side=LEFT)
20     #Tkinter.Button
21     menu = Menu(root)
22     root.config(menu=menu)
23     filemenu = Menu(menu)
24     menu.add_cascade(label="File", menu=filemenu)
25     info = filemenu.add_command(label="New", command=self.input_callback)
26     ## root.quit dosent seem to work in windows... so using root.destroy instead
27     filemenu.add_command(label="Exit", command=root.destroy)
28     def input_callback(self):
29     input_file = tkFileDialog.askopenfilename(parent=root)
30     #test_it(input_file)
31     #output_file = tkSimpleDialog.askstring("OutPut File Please", "What would you like the OutPut File called?", parent=root)
32     output_file = tkFileDialog.asksaveasfilename(parent=root)
33     #test_it(output_file)
34     #test_it(outputb_file)
35     #url_tester(input_file, output_file)
36     t1=Toplevel(root)
37     #canvas = Canvas(t1, width = 400, height = 400)
38     #frm = Frame(canvas, relief=GROOVE, borderwidth=2)
39     #Label(frm, text= url_tester(input_file, output_file)).pack()
40     info =url_tester(input_file, output_file)
41     Message(t1, text = info).pack()
42     return output_file, input_file
43    
44     def test_it(what):
45     print what
46     def url_tester(input_file, output_file):
47     #info = sys.stdout
48     #input_file = "U:\\" + input_file
49     f = open(input_file,"r")
50     contents = f.readlines()
51     f.close()
52     #output_file = "U:\\" + output_file
53     o=open(output_file,'w')
54     info = ""
55     for x in contents:
56     Split = string.split(x,"\n")
57     url = Split[0]
58     #print url
59     #print x
60     #url = x
61     try:
62     f=urllib.urlopen(url)
63     #url = url + "\t\tAlive!\n"
64     url = url + '\t\t' +" Alive!"
65     o.write(url)
66     except IOError:
67     #url = url + "\t\tDead!\n"
68     url = url + '\t\t' + " Dead!"
69     o.write(url)
70     #print url
71     info = info + "\n" + url
72     #info = sys.stdout()
73     #print len(contents)
74     return info
75    
76     if __name__ == '__main__':
77     if len(sys.argv) < 2:
78     #print "Sorry but this program requires both an input and output file.\nThe Syntax is\nTest_URL.py <inputfile> <outputfile>"
79     from Tkinter import *
80     import tkFileDialog
81     import tkSimpleDialog
82     root=Tk()
83     display = GUI(root,"None","None")
84     root.mainloop()
85     else:
86     input_file = sys.argv[1]
87     output_file = sys.argv[2]
88     print "WebSite \t \t | Active or Dead"
89     print "-----------------------------------------------"
90     url_tester(input_file, output_file)
91     print "Done!\nThese results have also been written to " + output_file + " on your U drive"
92