Reputation: 13
I'm developing a script in Python 2.7. I want to make sure that the script is always up to date via github. What I've tried is to create a file on github where I put the latest version number in and then in the python script I download that file and compare it with the version number of the program. This is my current script but it doesn't really work:
import sys
import os
import urllib
current_version = """1.4"""
print ("\a")
print ("Checking for latest verion..")
urllib.urlretrieve ("https://raw.githubusercontent.com/[myname]/[myproject]/master/version_latest", "version_latest")
version = open('version_latest', 'r').read()
if version == current_version:
vlatest = "1"
else:
vlatest = "2"
if vlatest == 2:
print ("Please get the latest version of this program here:")
print ("https://github.com/[myname]/[myproject]")
print ("You can't use the program without it!")
print ("\a")
os.system("start https://github.com/[myname]/[myproject]")
raw_input("Press enter to exit")
sys.exit()
else:
print ("You have the latest verion! Program will start automaticly!")
Thanks for the help!
Upvotes: 0
Views: 827
Reputation: 1030
What error is coming. However, what i can see is that you are assigning version no as string and checking it as integer in your if condition. So, either convert it in to int by int() method or convert your integer to string by str(2) # 2 is your version no.
Alternative Way:
However, you can simply do one thing, just name the python script in such a way that it also contains version no too, something like parsing_1_4.py if version no is 1.4. By this, you don't need to open your script, just check the name of python file, parse the version no & compare it with the version no stored in your file. if they are equal, good, else update the script and note to update the script name too(New Version No.).
Upvotes: 1
Reputation: 2146
Change
if vlatest == 2
To
if vlatest == "2"
You are using different types, so they are not equal. Use the same type and you'll be fine
Upvotes: 0