Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Error handling for non-post URLs

  • Loading branch information...
commit 69dd5b0a932a5e5a0849466912f112a1e3b58bcb 1 parent 60482a8
Liam Cooke authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 scripts/post_info.py
11 scripts/post_info.py
View
@@ -44,6 +44,8 @@
indents = lambda i: ' ' * i
+class TumblrURLException(Exception): pass
+
def tidy_json(j):
j = j.strip()
return j[j.index('{') : j.rindex('}') + 1]
@@ -54,7 +56,7 @@ def find_int(path):
return int(p)
except ValueError:
pass
- raise ValueError
+ raise TumblrURLException
def api_url(post_url):
url = urlparse(post_url)
@@ -97,7 +99,12 @@ def main():
parser.print_help()
return 1
- post = tumblr_post(args[0])
+ try:
+ post = tumblr_post(args[0])
+ except TumblrURLException:
+ sys.stderr.write('Error: URL must point to a single Tumblr post.\n')
+ return 1
+
pretty_print(post['info'])
print('\nReblog URL: %s' % post['reblog-url'])
Please sign in to comment.
Something went wrong with that request. Please try again.