Mercurial > public > sg101
comparison oembed/management/commands/oembed_refresh.py @ 948:f2fbe2b0d25d
Use unicode to log messages.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 16 May 2015 15:02:04 -0500 |
parents | 602639621257 |
children |
comparison
equal
deleted
inserted
replaced
947:49646a78e965 | 948:f2fbe2b0d25d |
---|---|
47 for p in providers: | 47 for p in providers: |
48 if re.match(p.url_regex, oembed.url): | 48 if re.match(p.url_regex, oembed.url): |
49 endpoint = p.api_endpoint | 49 endpoint = p.api_endpoint |
50 break | 50 break |
51 else: | 51 else: |
52 logger.error("No provider found for %s", oembed) | 52 logger.error(u"No provider found for %s", oembed) |
53 return | 53 return |
54 | 54 |
55 html = None | 55 html = None |
56 try: | 56 try: |
57 result = get_oembed(endpoint, oembed.url, fmt='json', | 57 result = get_oembed(endpoint, oembed.url, fmt='json', |
58 maxwidth=settings.OEMBED_MAXWIDTH, | 58 maxwidth=settings.OEMBED_MAXWIDTH, |
59 maxheight=settings.OEMBED_MAXHEIGHT, | 59 maxheight=settings.OEMBED_MAXHEIGHT, |
60 scheme='https') | 60 scheme='https') |
61 except urllib2.HTTPError as ex: | 61 except urllib2.HTTPError as ex: |
62 if 400 <= ex.code < 500: | 62 if 400 <= ex.code < 500: |
63 logger.error("Server could not handle request for %s: %d", oembed, ex.code) | 63 logger.error(u"Server could not handle request for %s: %d", oembed, ex.code) |
64 html = error_html(oembed) | 64 html = error_html(oembed) |
65 else: | 65 else: |
66 logger.critical("Server error during request for %s: %d", oembed, ex.code) | 66 logger.critical(u"Server error during request for %s: %d", oembed, ex.code) |
67 | 67 |
68 except urllib2.URLError as ex: | 68 except urllib2.URLError as ex: |
69 logger.critical("Failed to reach provider for %s: %s", oembed, ex.reason) | 69 logger.critical(u"Failed to reach provider for %s: %s", oembed, ex.reason) |
70 else: | 70 else: |
71 html = result['html'] | 71 html = result['html'] |
72 | 72 |
73 if html: | 73 if html: |
74 logger.info("Updating %s", oembed) | 74 logger.info(u"Updating %s", oembed) |
75 oembed.html = html | 75 oembed.html = html |
76 oembed.save() | 76 oembed.save() |
77 | 77 |
78 | 78 |
79 class Command(NoArgsCommand): | 79 class Command(NoArgsCommand): |