Automatically download the newest daily build

TaPol

New member
Hi, not sure if this is a my end issue since the latest system updates took place, but I am receiving the following log when attempting to run the updater. Any assistance is gratefully received. Thanks so much. TaPol =)

13/11/2020 2:37:07 PM
Checking http://ci.kolmafia.us/ for the latest version of KoLMafia...
An error occurred while downloading data from http://ci.kolmafia.us/
Exception Message: The request was aborted: Could not create SSL/TLS secure channel.
 

MCroft

Developer
Staff member
Hi, not sure if this is a my end issue since the latest system updates took place, but I am receiving the following log when attempting to run the updater. Any assistance is gratefully received. Thanks so much. TaPol =)

13/11/2020 2:37:07 PM
Checking http://ci.kolmafia.us/ for the latest version of KoLMafia...
An error occurred while downloading data from http://ci.kolmafia.us/
Exception Message: The request was aborted: Could not create SSL/TLS secure channel.
This was supposed to be fixed by Matt's changes in this post: https://kolmafia.us/threads/automatically-download-the-newest-daily-build.2856/page-8#post-160053

Can you make sure you've got that version and retry?
 

matt.chugg

Moderator
This was supposed to be fixed by Matt's changes in this post: https://kolmafia.us/threads/automatically-download-the-newest-daily-build.2856/page-8#post-160053

Can you make sure you've got that version and retry?

Definitly not the correct version, the correct version has https in the error message url.

An error occurred while downloading data from http://ci.kolmafia.us/ <-- old
An error occurred while downloading data from https://ci.kolmafia.us/ <-- new

(although I missed the one on line 106, but not going to recompile just for that)


** EDIT **

Post #158 updated

Fixed all occurences of urls in logging to https
Bumped the assembly number to 1.2
Added assembly number to log output
 
Last edited:

TaPol

New member
Definitly not the correct version, the correct version has https in the error message url.

An error occurred while downloading data from http://ci.kolmafia.us/ <-- old
An error occurred while downloading data from https://ci.kolmafia.us/ <-- new

(although I missed the one on line 106, but not going to recompile just for that)


** EDIT **

Post #158 updated

Fixed all occurences of urls in logging to https
Bumped the assembly number to 1.2
Added assembly number to log output
Thanks so much for replying so quickly, really appreciate it. I had downloaded the new files, but had forgotten to delete the .txt from the ends. Now that's done it appears to be working perfectly. Thanks again, TaPol =D
 

Rinn

Developer
If you want something simpler here's my update python script (requires wget atm, but that could be changed)

Code:
"""Updates KolMafia"""
import os
import sys
import json
import urllib.request
import urllib.error
import urllib.parse

def main():
    """Main entry point"""
    last_url = r'https://ci.kolmafia.us/job/Kolmafia/lastSuccessfulBuild'
    json_url = r'%s/api/json/' % last_url
    print('Reading %s' % json_url)
    page = urllib.request.Request(json_url, headers={'User-Agent': 'Mozilla/5.0'})
    response = urllib.request.urlopen(page)
    body = response.read().decode('ISO-8859-1')
    json_data = json.loads(body)
    jar_url = r'%s/artifact/%s' % (last_url, json_data['artifacts'][0]['relativePath'])
    print('Downloading %s' % json_url)
    print('\n')
    return os.system(r'wget -nc %s' % jar_url)

if __name__ == "__main__":
    sys.exit(main())
 

MCroft

Developer
Staff member
I can't change the file from txt. How do I do this, or how else do I get this to work?
Since this is a windows script, I'll assume you mean in windows. I found this on-line.

 

philmasterplus

Active member
If you want something simpler here's my update python script (requires wget atm, but that could be changed)

-snip-

I modified Rinn's script to work without wget. This should work with Python 3.6+.

Python:
#!/usr/bin/env python
"""Updates KolMafia"""
import json
import pathlib
import sys
import urllib.request


def main():
    """Main entry point"""
    LAST_URL = "https://ci.kolmafia.us/job/Kolmafia/lastSuccessfulBuild"
    json_url = f"{LAST_URL}/api/json/"
    print("Reading", json_url)
    with urllib.request.urlopen(json_url) as response:
        body = response.read().decode("ISO-8859-1")
    json_data = json.loads(body)

    jar_name = json_data["artifacts"][0]["fileName"]
    latest_jar_path = json_data["artifacts"][0]["relativePath"]
    jar_url = f"{LAST_URL}/artifact/{latest_jar_path}"

    if pathlib.Path(jar_name).exists():
        print(jar_name, "already exists.")
        return 0

    print("Downloading", jar_url)
    CHUNK_SIZE = 1024 * 1024  # 1MB
    with urllib.request.urlopen(jar_url) as jar_response, open(
        jar_name, mode="wb"
    ) as jarfile:
        while True:
            chunk: bytes = jar_response.read(CHUNK_SIZE)
            jarfile.write(chunk)
            print(".", end="", flush=True)
            if len(chunk) < CHUNK_SIZE:
                break

    print("\nDownload complete!")
    return 0


if __name__ == "__main__":
    sys.exit(main())
 
Last edited:

SketchySolid

New member
It would probably make sense to write this script in java, since every who's running the Kolmafia.jar file is going to have java installed already. Then it can be cross-platform, and work out-of-the-box.
 

MCroft

Developer
Staff member
It would probably make sense to write this script in java, since every who's running the Kolmafia.jar file is going to have java installed already. Then it can be cross-platform, and work out-of-the-box.
This is a user-space issue, and you can find different versions for different platforms in the parent folder on this forum. There have been multiple creations of a daily downloader, including a Node.JS version and a pure Java version (or there was 10 years ago).

There's room for you to create whatever you'd like and post it here and support it, if that works for you.

If none of these work for you and you don't want to make a new one, there's always just going to the server and pressing the download link, or pulling from SVN and building with ANT or your IDE.

Lots of solutions work here.
 

oldcheese

New member
When I attempt to open the script it simply immediately closes my command prompt without updating anything.

The error I get is the following

---------------
12/04/2021 15:41:09
Checking http://ci.kolmafia.us/ for the latest version of KoLMafia...
An error occurred while downloading data from http://ci.kolmafia.us/
Exception Message: The request was aborted: Could not create SSL/TLS secure channel.
---------------

Is this due to some lack at my end?
 

MCroft

Developer
Staff member
When I attempt to open the script it simply immediately closes my command prompt without updating anything.

The error I get is the following



Is this due to some lack at my end?
looks like it's an older script. http://... was retired a while back. Get the latest version and it should all work.
 

philmasterplus

Active member
My old Python 3 auto-update script broke down yesterday due to some issue on ci.kolmafia.us. Now that KoLmafia lives on GitHub, it made sense to tweak the script to download from GitHub instead:

Python:
#!/usr/bin/env python
"""Updates KolMafia"""
import json
import pathlib
import sys
import urllib.request


def main():
    """Main entry point"""
    RELEASES_URL = "https://api.github.com/repos/kolmafia/kolmafia/releases"

    print(f"Visiting {RELEASES_URL}")
    with urllib.request.urlopen(RELEASES_URL) as response:
        body = response.read().decode("ISO-8859-1")
    json_data = json.loads(body)

    first_asset = json_data[0]["assets"][0]
    jar_name = first_asset["name"]
    jar_download_url = first_asset["browser_download_url"]

    if pathlib.Path(jar_name).exists():
        print(f"{jar_name} already exists.")
        return 0

    print(f"Downloading {jar_download_url}")
    CHUNK_SIZE = 1024 * 1024  # 1MB
    with urllib.request.urlopen(jar_download_url) as jar_response, open(
        jar_name, mode="wb"
    ) as jarfile:
        while True:
            chunk: bytes = jar_response.read(CHUNK_SIZE)
            jarfile.write(chunk)
            print(".", end="", flush=True)
            if len(chunk) < CHUNK_SIZE:
                break

    print("\nDownload complete!")
    return 0


if __name__ == "__main__":
    sys.exit(main())

(If you're still using Python <3.6, please update it.)
 

MCroft

Developer
Staff member
very cool. Once we have the pipelines stable, you may want to switch back to the jenkins builds. They should be running more checks...
 
Top