Skip to content

Instantly share code, notes, and snippets.

@Krever
Last active October 6, 2024 23:43
Show Gist options
  • Save Krever/45df3f9af50efb5676eea0c433f4b466 to your computer and use it in GitHub Desktop.
Save Krever/45df3f9af50efb5676eea0c433f4b466 to your computer and use it in GitHub Desktop.
Find Audible whishlist title worth buying.

Scripts are based on python audible lib, install accordign to docs: https://audible.readthedocs.io/en/latest/index.html

  1. Modify auth.py with your credentials
  2. Run auth.py - your creds will be saved in creds.txt for further calls
  3. Run dump_whishlist.py - your whishlist will be saved in whishslist.json
  4. Run filter-whishlist-for-sale.py - it will printout all titles below the credit price
import audible
# Authorize and register in one step
auth = audible.Authenticator.from_login(
"email",
"pass",
locale="US",
with_username=False
)
# Save credentials to file
auth.to_file("creds.txt")
import json
import audible
auth = audible.Authenticator.from_file("creds.txt")
with audible.Client(auth=auth) as client:
collected = []
page = 0
while True:
stats = client.get(
"/1.0/wishlist",
num_results="50",
page=page,
response_groups="contributors, media, price, product_attrs, product_desc, product_extended_attrs, "
"product_plan_details, product_plans, rating, sample, sku, customer_rights, relationships"
)
page += 1
collected.extend(stats["products"])
print(len(collected))
if len(collected) == stats["total_results"]:
break
with open("whishlist.json", "w") as file1:
file1.write(json.dumps(collected))
import json
CREDIT_PRICE = 12
with open('whishlist.json') as json_data:
data = json.load(json_data)
def is_below_credit_price(x):
if x["price"] is None:
return False
return x["price"]["lowest_price"]["base"] < CREDIT_PRICE
def is_free(x):
if x["customer_rights"] is None:
return False
return x["customer_rights"]["is_consumable"] == True
below_credit = filter(is_below_credit_price, data)
sorted_by_price = sorted(below_credit, key=lambda x: x["price"]["lowest_price"]["base"])
free = filter(is_free, data)
all = list(free) + list(sorted_by_price)
for x in all:
price = 0 if x["customer_rights"]["is_consumable"] else round(x["price"]["lowest_price"]["base"], 2)
link = "https://www.audible.com/pd/" + x["asin"]
print(x["title"] + "\t" + str(price) + "\t" + link)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment