book_config.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:X-Ray_Calibre_Plugin 作者: szarroug3 项目源码 文件源码
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()))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号