Created
October 23, 2014 10:36
-
-
Save thekindlyone/46575be82f5df0fed724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
from time import asctime,localtime,sleep | |
import sys | |
if len(sys.argv)==3: | |
command=sys.argv[1] | |
sleeptime=int(sys.argv[2])*60 | |
elif len(sys.argv)==2: | |
command=sys.argv[1] | |
sleeptime=30*60 # default 30 mins | |
else: | |
print "USAGE: ",os.path.basename(sys.argv[0]),' "<command>" <sleeptime(optional)>' | |
sys.exit() | |
connected=False | |
count=1 | |
while not connected: | |
print 'attempt #',count,' at ',asctime(localtime()) | |
count+=1 | |
try: | |
r=requests.get('http://www.paranatural.net/') # test page to get which is known to work with default user agent | |
except: | |
sleep(sleeptime) #sleep for an hour | |
continue | |
connected=r.status_code == 200 | |
else: | |
print 'success!! attempt no. #',count,' at ',asctime(localtime()) | |
os.system(command) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
H:\droidtut>on-net-sched.py "youtube-dl https://www.youtube.com/playlist?list=PLB03EA9545DD188C3" 1 | |
attempt # 1 at Thu Oct 23 15:48:02 2014 | |
attempt # 2 at Thu Oct 23 15:49:02 2014 | |
attempt # 3 at Thu Oct 23 15:50:03 2014 | |
success!! attempt no. # 4 at Thu Oct 23 15:50:04 2014 | |
[youtube:playlist] PLB03EA9545DD188C3: Downloading webpage | |
[download] Downloading playlist: Android Development For Absolute Beginners | |
[youtube:playlist] playlist Android Development For Absolute Beginners: Collected 40 video ids (downloading 40 of them) | |
.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one, but instead of GET I would use HEAD - saves some time and bandwidth .