Skip to content

Instantly share code, notes, and snippets.

@marccarre
Created October 24, 2020 08:46
Show Gist options
  • Star 36 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marccarre/645fe68da31678f9191cd3aafecfea1b to your computer and use it in GitHub Desktop.
Save marccarre/645fe68da31678f9191cd3aafecfea1b to your computer and use it in GitHub Desktop.
List all available versions of Kindle for Mac and Kindle for PC.
#!/usr/bin/env python
'''
List all available versions of Kindle for Mac and Kindle for PC.
Dependencies:
- asyncio==3.4.3
- aiohttp==3.6.3
'''
import os
import sys
import asyncio
import aiohttp
MAX_ATTEMPTS = int(os.environ.get('MAX_ATTEMPTS', 3)) # Maximum number of attempts per URL.
RATE_LIMIT = int(os.environ.get('RATE_LIMIT', 64)) # Number of active requests at any given time.
'''
Build numbers (5XXXX) increment:
- by 1000 for minor versions
- by 1 for patch versions -- with gaps, as some builds are not released.
'''
VERSIONS = [
{'build': 55000, 'version': '1.26'},
{'build': 56000, 'version': '1.27'},
{'build': 57000, 'version': '1.28'},
{'build': 58000, 'version': '1.29'},
{'build': 59000, 'version': '1.30'},
]
'''
For example:
- Kindle 1.26
- https://s3.amazonaws.com/kindleforpc/55076/KindleForPC-installer-1.26.55076.exe
- https://s3.amazonaws.com/kindleformac/55093/KindleForMac-55093.dmg
- Kindle 1.30
- https://s3.amazonaws.com/kindleforpc/59056/KindleForPC-installer-1.30.59056.exe
- https://s3.amazonaws.com/kindleformac/59055/KindleForMac-1.30.59055.dmg
'''
URL_PATTERNS = [
'https://s3.amazonaws.com/kindleforpc/{build}/KindleForPC-installer-{version}.{build}.exe',
'https://s3.amazonaws.com/kindleformac/{build}/KindleForMac-{build}.dmg',
'https://s3.amazonaws.com/kindleformac/{build}/KindleForMac-{version}.{build}.dmg',
]
async def main():
async with aiohttp.ClientSession() as session:
urls = await fetch_all(session)
print('\n'.join(sorted([url for url in urls if url])))
async def fetch_all(session):
tasks = []
semaphore = asyncio.Semaphore(RATE_LIMIT)
for v in VERSIONS:
for build in range(v['build'], v['build'] + 1000):
for pattern in URL_PATTERNS:
url = pattern.format(build=build, version=v['version'])
task = asyncio.create_task(fetch(session, semaphore, url))
tasks.append(task)
results = await asyncio.gather(*tasks)
return results
async def fetch(session, semaphore, url):
for attempt in range(1, MAX_ATTEMPTS + 1):
try:
async with semaphore:
response = await session.head(url)
return url if response.status == 200 else None
except Exception as e:
if attempt < MAX_ATTEMPTS:
print('Attempt #%d: Retrying on %s as got: %s.' % (attempt, url, e), file=sys.stderr)
else:
print('Failed on %s with: %s' % (url, e), file=sys.stderr)
if __name__ == '__main__':
asyncio.run(main())
@DreamSworK
Copy link

$ py list_kindle_releases.py
https://s3.amazonaws.com/kindleformac/57029/KindleForMac-57029.dmg
https://s3.amazonaws.com/kindleformac/59055/KindleForMac-1.30.59055.dmg
https://s3.amazonaws.com/kindleformac/60175/KindleForMac-1.31.60175.dmg
https://s3.amazonaws.com/kindleformac/61055/KindleForMac-1.32.61055.dmg
https://s3.amazonaws.com/kindleformac/61174/KindleForMac-1.32.61174.dmg
https://s3.amazonaws.com/kindleformac/62000/KindleForMac-1.33.62000.dmg
https://s3.amazonaws.com/kindleformac/63038/KindleForMac-1.34.63038.dmg
https://s3.amazonaws.com/kindleformac/63102/KindleForMac-1.34.63102.dmg
https://s3.amazonaws.com/kindleformac/64250/KindleForMac-1.35.64250.dmg
https://s3.amazonaws.com/kindleformac/65105/KindleForMac-1.36.65105.dmg
https://s3.amazonaws.com/kindleformac/65229/KindleForMac-1.36.65229.dmg
https://s3.amazonaws.com/kindleformac/65255/KindleForMac-1.36.65255.dmg
https://s3.amazonaws.com/kindleformac/65551/KindleForMac-1.36.65551.dmg
https://s3.amazonaws.com/kindleforpc/59056/KindleForPC-installer-1.30.59056.exe
https://s3.amazonaws.com/kindleforpc/60103/KindleForPC-installer-1.31.60103.exe
https://s3.amazonaws.com/kindleforpc/60170/KindleForPC-installer-1.31.60170.exe
https://s3.amazonaws.com/kindleforpc/61078/KindleForPC-installer-1.32.61078.exe
https://s3.amazonaws.com/kindleforpc/61109/KindleForPC-installer-1.32.61109.exe
https://s3.amazonaws.com/kindleforpc/62002/KindleForPC-installer-1.33.62002.exe
https://s3.amazonaws.com/kindleforpc/63025/KindleForPC-installer-1.34.63025.exe
https://s3.amazonaws.com/kindleforpc/63040/KindleForPC-installer-1.34.63040.exe
https://s3.amazonaws.com/kindleforpc/63098/KindleForPC-installer-1.34.63098.exe
https://s3.amazonaws.com/kindleforpc/63103/KindleForPC-installer-1.34.63103.exe
https://s3.amazonaws.com/kindleforpc/65039/KindleForPC-installer-1.36.65039.exe
https://s3.amazonaws.com/kindleforpc/65107/KindleForPC-installer-1.36.65107.exe
https://s3.amazonaws.com/kindleforpc/66010/KindleForPC-installer-1.37.66010.exe

@televisi
Copy link

televisi commented Mar 18, 2023

I got this error, what would be wrong with mine? Thanks

root@ubuntu:/tmp/kindle# pip --version
pip 21.3.1 from /tmp/kindle/env/lib/python3.6/site-packages/pip (python 3.6)
root@ubuntu:/tmp/kindle# python --version
Python 3.6.9
root@ubuntu:/tmp/kindle# pip list
Package             Version
------------------- -------
aiohttp             3.8.4
aiosignal           1.2.0
asn1crypto          0.24.0
async-timeout       4.0.2
asyncio             3.4.3
asynctest           0.13.0
attr                0.3.2
attrs               22.2.0
charset-normalizer  3.0.1
cryptography        2.1.4
root@ubuntu:/tmp/kindle# python list_kindle_releases.py 
Traceback (most recent call last):
  File "list_kindle_releases.py", line 81, in <module>
    asyncio.run(main())
AttributeError: module 'asyncio' has no attribute 'run'

@Young-Lord
Copy link

AttributeError: module 'asyncio' has no attribute 'run'

Python version too old. Update to at least Python 3.7 should fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment