This code works nicely for my purposes, but I would like to improve it exponentially.
What are some steps I can take? I'm interested in optimization, refactoring, and clean-code.
def do_GET(self):
qs = {}
path = self.path
print path
if path.endswith('robots.txt'):
self.send_response(500)
self.send_header('Connection', 'close')
return
if '?' in path:
path, tmp = path.split('?', 1)
qs = urlparse.parse_qs(tmp)
print path, qs
if 'youtube' in path:
ID = qs.get('vID')
LTV = qs.get('channelID')
EMAIL = qs.get('uEmail')
TIME = qs.get('Time')
userID = qs.get('uID')
URL = qs.get('contentUrl')
channelID = str(LTV)[2:-2]
print channelID
uEmail = str(EMAIL)[2:-2]
print uEmail
ytID = str(ID)[2:-2]
print ytID
ytURL = str("https://www.youtube.com/tv#/watch?v=%s" % ytID)
print ytURL
uTime = str(TIME)[2:-2]
print uTime
uID = str(userID)[2:-2]
print uID
contentUrl = str(URL)[2:-2]
print contentUrl
if sys.platform == "darwin":
subprocess.Popen('./killltv', shell=True)
sleep(1)
subprocess.Popen('./killltv', shell=True)
sleep(1)
subprocess.Popen('./test.py %s'%ytURL, shell=True)
elif sys.platform == "linux2":
subprocess.Popen('./killltv', shell=True)
sleep(1)
subprocess.Popen('./test.py %s'% ytURL, shell=True)
#subprocess.Popen('chromium-browser https://www.youtube.com/tv#/watch?v=%s'% ytID, shell=True)
sleep(2)
#subprocess.Popen("./fullscreen", shell=True)
elif sys.platform == "win32":
os.system('tskill chrome')
browser = webbrowser.open('http://youtube.com/watch?v="%s"'% ytID)
log.warn("'%s':,video request:'%s' @ %s"% (channelID, ytID, time))
#playyt = subprocess.Popen("/Users/Shared/ltv.ap
sys.platform
iswin32
? If you add certain details about what you are trying to do bytest.py
then the os specific code can be converted into loops based on values stored in dictionaries with key beingsys.platform
. – Aseem Bansal Jul 30 '13 at 13:12