|
1 | 1 | #!/user/bin/python |
| 2 | +import subprocess |
2 | 3 | import urllib.request |
| 4 | +import re |
| 5 | +import os |
3 | 6 | import email.utils |
4 | 7 | import hashlib |
5 | 8 | import json |
6 | 9 | import xml.etree.ElementTree |
7 | 10 |
|
| 11 | + |
8 | 12 | app_image_url = "https://cdn.anythingllm.com/latest/AnythingLLMDesktop.AppImage" |
9 | 13 | check_version_url = "https://cdn.anythingllm.com/latest/version.txt" |
10 | | -f = urllib.request.urlopen(check_version_url) |
11 | | -last_modified_tuple = email.utils.parsedate(f.info()['Last-Modified']) |
12 | | -latest_version = f.read().decode('ascii') |
| 14 | +result = subprocess.run(['curl', '-si', check_version_url], stdout=subprocess.PIPE) |
| 15 | +output_lines = result.stdout.decode().splitlines() |
| 16 | +for line in output_lines: |
| 17 | + m = re.match('^last-modified: (.*)', line) |
| 18 | + if m: |
| 19 | + last_modified_str = m.group(1) |
| 20 | + break |
| 21 | + |
| 22 | +if not last_modified_str: |
| 23 | + print("Failed to get last-modified") |
| 24 | + exit(1) |
| 25 | + |
| 26 | +last_modified_tuple = email.utils.parsedate(last_modified_str) |
| 27 | +latest_version = output_lines[-1].strip() |
13 | 28 | last_modified = f"{last_modified_tuple[0]}-{last_modified_tuple[1]:02}-{last_modified_tuple[2]:02}" |
14 | 29 | latest = (latest_version, last_modified) |
15 | 30 |
|
|
32 | 47 | # Open the URL and read its content |
33 | 48 | app_image_sha256_hash = hashlib.sha256() |
34 | 49 |
|
| 50 | +file_name = 'AnythingLLMDesktop.AppImage' |
35 | 51 | # Open the URL and read the content in chunks |
36 | | -with urllib.request.urlopen(app_image_url) as response: |
| 52 | +result = subprocess.run(['curl', '-Lo', file_name, app_image_url], stdout=subprocess.PIPE) |
| 53 | +with open(file_name, 'rb') as response: |
37 | 54 | while True: |
38 | 55 | chunk = response.read(1024 * 1024) |
39 | 56 | if not chunk: |
40 | 57 | break |
41 | 58 | # Update the hash with the current chunk |
42 | 59 | app_image_sha256_hash.update(chunk) |
43 | | - |
| 60 | +os.remove(file_name) |
44 | 61 | # Return the final hash as a hexadecimal string |
45 | 62 | latest_version_sha256 = app_image_sha256_hash.hexdigest() |
46 | 63 | print("Done.") |
|
0 commit comments