# created by Gábor Bodnár 2020-12-24
# you can download SQLSaturday session files, which does not req authentication
# order from the newest to older files in batch . The latest is: 28874
# https://www.sqlsaturday.com/SessionDownload.aspx?suid=28865
# https://www.sqlsaturday.com/SessionDownload.aspx?suid=16007
# https://www.sqlsaturday.com/SessionDownload.aspx?suid=28134 (you can download from logged in site)
import sys
import os
import ntpath
import wget
from shutil import move
from colorama import init
init()
# set from hinumber to lonumber separeted folde by step, basefolder the directory on your local computer
hinumber=28874
lonumber=24000
step=1000
basefolder='C:\\SQLSatruday\\presentations\\'
# download routine
for i in range(hinumber, lonumber,-1):
print('i:',str(i))
if i % step ==0 or i==hinumber:
print(i)
subdir=str(i)
downloadfolder=basefolder+subdir
print('basefolder:',basefolder)
print('subdir:',subdir)
print('downloadfolder',downloadfolder)
if not os.path.exists(downloadfolder):
os.makedirs(downloadfolder)
file_base_url='https://www.sqlsaturday.com/SessionDownload.aspx?suid='
file_url = file_base_url+ str(i)
file_name = wget.download(file_url,out=downloadfolder)
directory= os.path.dirname(file_name)
origpath=os.path.realpath(file_name)
filenev=os.path.basename(file_name)
print(' origpath:',origpath)
print(' Filenev:',filenev)
strfilenev=str(filenev)
if strfilenev=='SessionDownload.aspx' or strfilenev == 'SessionDownload (1).aspx' :
print('\033[31m' + str(i) + '\033[0m' )
f= open( basefolder+"\\download_"+subdir+"_url_error.txt","a")
f.write(file_url+'\n')
f.close()
ujfilenev=str(i)+'_'+str(filenev)
ujutvonal=directory+'\\' +ujfilenev
move(origpath,ujutvonal)
print('new downloaded file:',ujutvonal)