I'm trying to make a script that downloads from a specific website etc... it's done and everything.
The problem is I need to compile it to a .exe for people to use and I noticed there isn't a py3exe to do this...
So I downloaded python 2, and tried to just replace all my urllib.request with urllib2
and http.cookiejar with cookielib but the program didn't work.
It wouldn't let me log in like py3 did. I think there might be a difference in the default headers between py2 and py3 but I don't wanna go through all that work if I can get a straight answer here.
I'm writing this in windows and logging into an invision powerboard board.
Any style/writing comments also appreciated.
Also how do you split strings by spaces :?. info.split(' ') didn't work. Had to use a pretty sketch workaround, data[0][7:] lol
A way to compile py3 code would be most perfect though, but google failed me at that.
here's my code. py3 version which works
"""
log in (DONE)
download map (DONE)
copy to beta folder (DONE)
check if you have newest version
set up so viewing patch notes page causes it to automatically check
"""
import http.cookiejar
import urllib.request
###Get info from file
info = open('info.txt', 'r')
data=[line.strip() for line in info.readlines()]
accnt = data[0][7:]
passwd = data[1][8:]
higherversion = data[2][15:]
lowerversion = data[3][14:]
destination = data[4][13:]
info.close
###Cookies
cookies = http.cookiejar.LWPCookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookies))
urllib.request.install_opener(opener)
###Login
print('logging in...\n')
urllib.request.urlopen(urllib.request.Request('http://beta.getdota.com/index.php?app=core&module=global§ion=login&do=process',
urllib.parse.urlencode({
'referer': 'http%3A%2F%2Fbeta.getdota.com%2Findex.php%3F&username=' + accnt + '&password=' + passwd,
'username': accnt,
'password': passwd
})))
###Download to directory
print('downloading...\n')
current = int(lowerversion) + 588
file = urllib.request.urlopen('http://beta.getdota.com/index.php?app=downloads&module=display§ion=download&do=confirm_download&id=' + str(current))
output = open(destination + higherversion + '_Beta' + lowerversion + '.w3x' ,'wb')
output.write(file.read())
output.close()
###Rewrite info with increased lowerversion
info = open('info.txt', 'w')
info.write(data[0] + '\n')
info.write(data[1] + '\n')
info.write(data[2] + '\n')
info.write('lowerversion= ' + str(int(lowerversion) + 1) + '\n')
info.write(data[4] + '\n')
info.close
Thanks, another weird bug is that if I call the program from the python interpreter it doesn't rewrite info.txt (just makes a blank file) but if i just rightclick the sorucecode and do open with it does O.o