#!/usr/bin/env python
import webbrowser
class Tors:
def getSearch(self):
#Gets the search that the user is looking for
u_input = raw_input('Enter search: ')
return u_input
def getEngine(self):
#Gets the engine the user would like to use to search
engine = raw_input('Enter engine: ')
return engine
def setEngine(self,eng):
#Converts the users engine input to lowercase; Useful for error prevention. Reduces the number of possibilites for the if statements
#Does nothing if eng is already lowercase
eng = eng.lower()
#Sets eng to the site specified by the user in getEngine()
#Resulting eng will be modified to url_eng
#All sites have a "TEMP", symbolizing the search from getSearch()
if eng == 'tpb' or eng == 'thepiratebay':
url_eng = 'http://thepiratebay.se/search/TEMP/0/77/0'
elif eng == 'kat'or eng == 'kickasstorrents':
url_eng = 'http://kat.ph/usearch/TEMP/'
elif eng == 'torrentz' or eng == 'tz':
url_eng = 'http://torrentz.eu/search?f=TEMP'
elif eng == 'youtube' or eng == 'ytube' or eng == 'yt':
url_eng = 'http://www.youtube.com/results?search_query=TEMP'
elif eng == 'google' or eng == 'goo' or eng == 'goog':
url_eng = 'http://www.google.com/#hl=en&tbo=d&output=search&sclient=psy-ab&q=TEMP'
else:
print(eng+': is not an engine currently supported. To add an engine you will need to modify the script yourself')
return url_eng
def setUrl(self,torEng,u_in):
#Replaces the "TEMP" with the users input from getSearch()
#This results in the last modification to the url
full_url = torEng.replace('TEMP',u_in)
return full_url
def navigateUrl(self,complete_url):
#Displays the complete_url to the screen
#Uses the webbrowser function to navigate to the fully modified url (complete_url)
print('Search Url: '+complete_url)
webbrowser.open_new_tab(complete_url)
#Creates a Tors() object capable of accesing Tors() functions
#This allows the script to access functions inside the Tors() class
newSearch = Tors()
#The Users Input
userIn = newSearch.getSearch()
#The Users Engine Input
tEng = newSearch.getEngine()
#The Temporary Url (http://thepiratebay.se/search/TEMP/0/77/0) to set the engine
tempUrl = newSearch.setEngine(tEng)
#The modified url that replaces TEMP with the users input from getSearch()
modUrl = newSearch.setUrl(tempUrl,userIn)
#Navigates the the "modUrl". Which is the site followed by the serach provided
newSearch.navigateUrl(modUrl)
↧
Am I using proper code structure
↧