Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. #Instalar python cualquier version
  2. #Asegurarse que este agregado en la variable de entorno PATH de Windows
  3. #entrar a una ventana de DOS y ejecutar: pip install schedule requests
  4. #copiar el siguiente script en un archivo y ejecutar con : python ruta/a/archivo
  5.  
  6. import schedule
  7. import sys
  8. import time
  9. import random
  10. from time import strftime, localtime
  11. import requests
  12.  
  13. SEG=10
  14. #En comentarios los servidores que responden lento.
  15. URL_SPEEDTEST= [
  16.     "http://speedtest31.amx.com.pe/speedtest/random350x350.jpg",
  17.     "http://speedtest11.amx.com.pe/speedtest/random350x350.jpg",
  18.     "http://medidor1.optical.com.pe/speedtest/random350x350.jpg",
  19.     "http://medidor.fiberluxperu.com/speedtest/random350x350.jpg",
  20.     "http://ookla-was.telefonica.net.pe/speedtest/random350x350.jpg",
  21.     "http://speedtest.bitel.com.pe/speedtest/random350x350.jpg",
  22.     "http://speedtest21.amx.com.pe/speedtest/random350x350.jpg",
  23.     "http://ookla-are.telefonica.net.pe/speedtest/random350x350.jpg",
  24.     "http://speedtest41.amx.com.pe/speedtest/random350x350.jpg"
  25.                 ]
  26.  
  27. def getRandomURL():
  28.     return URL_SPEEDTEST[random.randint(0,len(URL_SPEEDTEST)-1)]
  29.  
  30. def downloadFile(URL=None):
  31.     if (URL == ""):
  32.         URL_END=getRandomURL()
  33.     else:
  34.         URL_END=URL
  35.  
  36.     print("["+strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()) + "]::Llamando url - " + URL_END)
  37.     r = requests.get(URL_END, timeout=3)
  38.     return
  39.  
  40. schedule.every(SEG).seconds.do(downloadFile,"")
  41.  
  42. print("[Cada " + str(SEG) + " Segundos / Ctrl + C Cancela]")
  43. downloadFile(getRandomURL())
  44.  
  45. try:
  46.     while True:
  47.         schedule.run_pending()
  48.         time.sleep(1)
  49. except KeyboardInterrupt:
  50.     sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement