Created
June 12, 2017 11:59
-
-
Save kerma/9eb2b1af259bc8a8a327092601c52554 to your computer and use it in GitHub Desktop.
Audible sorted wishlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Sort Audible wishlist by ranking into txt file | |
# Save As http://www.audible.com/wl/ref=a_wl_c1_pg?sortType=rank&sortOrder=dsc&totalAsinsPerPage=100&page=1 for input | |
import re | |
import requests | |
def get_rating(wishlist, url_part): | |
url = 'https://www.audible.com' + url_part | |
print('Getting {}'.format(url)) | |
response = requests.get(url) | |
print('Response: {}'.format(response)) | |
rating_pattern = 'ratingValue">(.*)<' | |
m = re.search(rating_pattern, response.text) | |
if not m: | |
return | |
rating = m.group(1) | |
title_pattern = '<h1 class="adbl-prod-h1-title" itemprop="name">(.*)<' | |
m = re.search(title_pattern, response.text) | |
title = 'CANNOT_PARSE' | |
if m: | |
title = m.group(1) | |
wishlist.append( | |
(float(rating), title, url) | |
) | |
if __name__ == '__main__': | |
wishlist = [] | |
with open('Wish List _ Audible.com.htm') as f: | |
c = f.read() | |
for i in c.split('\n'): | |
m = re.search(r'href="(/pd/.*tlnk)?"', i) | |
if m: | |
get_rating(wishlist, m.group(1)) | |
sorted_wl = sorted(wishlist, key=lambda x: x[0], reverse=True) | |
with open('sorted_wishlist.txt', 'w') as f: | |
for entry in sorted_wl: | |
f.write('{} | {} | {}\n'.format(*entry)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment