import random, sys, httplib2, win32clipboard, webbrowser, time, zipfile, os, urllib, requests
from copy import deepcopy
from bs4 import SoupStrainer
from bs4 import BeautifulSoup
from urllib2 import Request
from urllib2 import urlopen
from tqdm import tqdm
from Tkinter import *
#When I wrote this, only God and I knew what I was writing
#Now only God knows
#
#added GUI -todes
#(toads_tf also knows)
def download_zip(page,path,cname):
data = "
http://sizzlingstv.s3.amazonaws.com/stv/"+ page[-6:] +".zip"
filename = page[-6:] + ".zip"
try:
urllib.urlretrieve (data, filename)
print data
except:
print("No zip file was found, ending program...")
os.remove(filename)
time.sleep(5)
exit()
for i in tqdm(range(100)):
time.sleep(0.02)
try:
zip_ref = zipfile.ZipFile(filename, 'r')
demoname = str(zip_ref.namelist()[0])
print(demoname)
zip_ref.extractall(path)
zip_ref.close()
if cname != '':
os.rename(path+'\\'+demoname,path+'\\'+cname+'.dem')
os.remove(filename)
except Exception as e:
print str(e)
gameVar = StringVar()
top = Toplevel()
top.title('Error')
msg = Message(top,text="Something went wrong while exporting. Try putting your Team Fortress 2\\tf folder path here, but with double slashes. (\\\, not \)")
msg.pack()
gameDir = Entry(top,textvariable=gameVar,width=20)
gameDir.pack()
changeBtn = Button(top,text='Retry',command=lambda:download_zip(link.get(),gameVar.get(),''),width=7)
changeBtn.pack()
TOPP = Toplevel()
TOPP.title('Complete!')
mensaje= Message(TOPP,text=filename + " From " + data + " has been downloaded and extracted.")
mensaje.pack()
time.sleep(5)
window = Tk()
window.title('Sizzlingstats Downloader')
link = StringVar()
customName = StringVar()
info = Label(window,text='Please copy the .ss link below:')
info.pack()
linkBox = Entry(window,textvariable=link,width=30)
linkBox.pack()
infoS = Label(window,text='Name .dem file (optional, leave blank for default name):')
infoS.pack()
nameBox = Entry(window,textvariable=customName,width=30)
nameBox.pack()
goBtn = Button(window,text='Go',command=lambda:download_zip(link.get(),"C:\\Program Files (x86)\\Steam\\steamapps\\common\\Team Fortress 2\\tf",customName.get()),width=10)
goBtn.pack()
window.mainloop()