def browse_amazon_url(self):
'''Opens Amazon page for current book's ASIN using user's local store'''
# Try to use the nearest Amazon store to the user.
# If this fails we'll default to .com, the user will have to manually
# edit the preferences file to fix it (it is a simple text file).
if not prefs['tld']:
import json
from collections import defaultdict
from urllib2 import urlopen, URLError
try:
country = json.loads(urlopen('http://ipinfo.io/json').read())['country']
except (URLError, KeyError):
country = 'unknown'
country_tld = defaultdict(lambda: 'com', {'AU': 'com.au', 'BR': 'com.br', 'CA': 'ca', 'CN': 'cn', 'FR': 'fr',
'DE': 'de', 'IN': 'in', 'IT': 'it', 'JP': 'co.jp', 'MX': 'com.mx',
'NL': 'nl', 'ES': 'es', 'GB': 'co.uk', 'US': 'com'})
prefs['tld'] = country_tld[country]
webbrowser.open('https://www.amazon.{0}/gp/product/{1}/'.format(prefs['tld'], self._asin_edit.text()))
评论列表
文章目录