Post: Need advice on this python script. Working on update system.
03-17-2013, 03:45 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); So im trying to work on some sort of update system with a python application im working on. Here is just a snippet of it.

    
import requests
import sys

appversion = "103"

def checkUpdates(appversion):
updateURL = "https://localhost/tests.php"
package = {'tool':'checkforupdate', 'version':appversion}
updateRequest = requests.get(updateURL, params=package)
if updateRequest.text == "updatenow":
print "New update available!"
if updateRequest.text == "current":
print "Running Latest Version"

checkUpdates(appversion)


Sends a GET request to a central server. (localhost for now) The server will send back a string or some sort of data. Here is the PHP script the central server will be running.

    
<?php
error_reporting(0);
$tool = $_GET['tool'];
$version = $_GET['version'];

if(empty($tool) or empty($version)) {
exit(); //could return something
}

if($version < "102") { // number could be a variable. data from database
echo "updatenow";
}
else {
echo "current";
}
?>


Obviously the php script would verify it more but for now its staying simple. Version would probably have an is_numeric() call in it. Proper precautions from SQL injection could also be done.

I just want to see if this would be the best way. Is there a better and smaller way to do it? FTP is not an option for this at the moment. Feedback would be nice.
(adsbygoogle = window.adsbygoogle || []).push({});

The following 2 users say thank you to | Crayawn | for this useful post:

iTMG-, mikkel9999
03-17-2013, 04:07 AM #2
Pichu
RIP PICHU.
Although I wouldn't know how to do it in Python as I haven't messed with it far enough to do this:

Getting and reading the data from an XML file would be a good option. If the value in the XML version file is greater than the file you have running when it checks, simply alert the user there is an update. Define a location on a host that will contain the updated file(s).

Then simply request to download them.
03-17-2013, 04:12 AM #3
looks nice. hopefully it works.
03-17-2013, 04:14 AM #4
Originally posted by Pichu View Post
Although I wouldn't know how to do it in Python as I haven't messed with it far enough to do this:

Getting and reading the data from an XML file would be a good option. If the value in the XML version file is greater than the file you have running when it checks, simply alert the user there is an update. Define a location on a host that will contain the updated file(s).

Then simply request to download them.


That is actually a good idea. I havent thought about something like that. I might try experimenting with that method.

The following user thanked | Crayawn | for this useful post:

Pichu
03-17-2013, 04:55 AM #5
Pichu
RIP PICHU.
Originally posted by another user
That is actually a good idea. I havent thought about something like that. I might try experimenting with that method.


It's what I do whenever I want to create an updater for a program. I assume you have your own host because you have your own website. Just stick the XML file somewhere in it.
03-17-2013, 02:00 PM #6
Sloth
Banned
Originally posted by another user
So im trying to work on some sort of update system with a python application im working on. Here is just a snippet of it.

    
import requests
import sys

appversion = "103"

def checkUpdates(appversion):
updateURL = "https://localhost/tests.php"
package = {'tool':'checkforupdate', 'version':appversion}
updateRequest = requests.get(updateURL, params=package)
if updateRequest.text == "updatenow":
print "New update available!"
if updateRequest.text == "current":
print "Running Latest Version"

checkUpdates(appversion)


Sends a GET request to a central server. (localhost for now) The server will send back a string or some sort of data. Here is the PHP script the central server will be running.

    
<?php
error_reporting(0);
$tool = $_GET['tool'];
$version = $_GET['version'];

if(empty($tool) or empty($version)) {
exit(); //could return something
}

if($version < "102") { // number could be a variable. data from database
echo "updatenow";
}
else {
echo "current";
}
?>


Obviously the php script would verify it more but for now its staying simple. Version would probably have an is_numeric() call in it. Proper precautions from SQL injection could also be done.

I just want to see if this would be the best way. Is there a better and smaller way to do it? FTP is not an option for this at the moment. Feedback would be nice.

For my programs I used a text document containing the latest update version and my program checks against that when ran.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo