<html><body>
<p>1 new commit in yt:</p>
<p><a href="https://bitbucket.org/yt_analysis/yt/commits/454b81690191/">https://bitbucket.org/yt_analysis/yt/commits/454b81690191/</a> Changeset: 454b81690191 Branch: yt User: ngoldbaum Date: 2016-04-20 18:13:09+00:00 Summary: Merged in xarthisius/yt (pull request #2119)</p>
<p>Enhance commandline image upload/delete Affected #: 3 files</p>
<p>diff -r 605942cb9f98aaa215ee0bd67b0293bdd2302598 -r 454b81690191c4ee1c28f0120f39bf9ee99840ed doc/source/reference/command-line.rst --- a/doc/source/reference/command-line.rst +++ b/doc/source/reference/command-line.rst @@ -80,6 +80,7 @@</p>
<pre>requested), for one or more datasets (default field is
Density)
update Update the yt installation to the most recent version</pre>
<p>+ delete_image Delete image from imgur.com.</p>
<pre> upload_image Upload an image to imgur.com. Must be PNG.
</pre>
<p>@@ -264,3 +265,10 @@</p>
<pre>uploads it anonymously to the website `imgur.com <http://imgur.com/>`_ and
provides you with a link to share with your collaborators. Note that the
image *must* be in the PNG format in order to use this function.</pre>
<p>+ +delete_image +++++++++++++ + +The image uploaded using ``upload_image`` is assigned with a unique hash that +can be used to remove it. This subcommand provides an easy way to send a delete +request directly to the `imgur.com <<a href="http://imgur.com/">http://imgur.com/</a>>`_.</p>
<p>diff -r 605942cb9f98aaa215ee0bd67b0293bdd2302598 -r 454b81690191c4ee1c28f0120f39bf9ee99840ed yt/config.py --- a/yt/config.py +++ b/yt/config.py @@ -57,6 +57,9 @@</p>
<pre>local_standard_filename = 'local001',
answer_tests_url = 'http://answers.yt-project.org/{1}_{2}',
sketchfab_api_key = 'None',</pre>
<p>+ imagebin_api_key = ‘e1977d9195fe39e’, + imagebin_upload_url = '<a href="https://api.imgur.com/3/upload">https://api.imgur.com/3/upload</a>', + imagebin_delete_url = '<a href="https://api.imgur.com/3/image/">https://api.imgur.com/3/image/</a>{delete_hash}',</p>
<pre>thread_field_detection = 'False',
ignore_invalid_unit_operation_errors = 'False',
chunk_size = '1000',</pre>
<p>diff -r 605942cb9f98aaa215ee0bd67b0293bdd2302598 -r 454b81690191c4ee1c28f0120f39bf9ee99840ed yt/utilities/command_line.py --- a/yt/utilities/command_line.py +++ b/yt/utilities/command_line.py @@ -1049,6 +1049,39 @@</p>
<pre> else:
_print_failed_source_update(opts.reinstall)
</pre>
<p>+ +class YTDeleteImageCmd(YTCommand): + args = (dict(short="delete_hash", type=str),) + description = \ + """ + Delete image from imgur.com. + + """ + name = “delete_image” + def __call__(self, args): + headers = {'Authorization': + ‘Client-ID {}'.format(ytcfg.get("yt", “imagebin_api_key"))} + + delete_url = ytcfg.get("yt”, “imagebin_delete_url”) + req = urllib.request.Request( + delete_url.format(delete_hash=args.delete_hash), + headers=headers, method='DELETE’) + try: + response = urllib.request.urlopen(req).read().decode() + except urllib.error.HTTPError as e: + print("ERROR", e) + return {'deleted': False} + + rv = json.loads(response) + if ‘success’ in rv and rv["success"]: + print("\nImage successfully deleted!\n") + else: + print() + print("Something has gone wrong! Here is the server response:") + print() + pprint.pprint(rv) + +</p>
<pre>class YTUploadImageCmd(YTCommand):
args = (dict(short="file", type=str),)
description = \</pre>
<p>@@ -1062,15 +1095,16 @@</p>
<pre> if not filename.endswith(".png"):
print("File must be a PNG file!")
return 1</pre>
<p>+ headers = {'Authorization': + 'Client-ID {}'.format(ytcfg.get("yt", "imagebin_api_key"))} +</p>
<pre>image_data = base64.b64encode(open(filename, 'rb').read())</pre>
<ul><li><p>api_key = ‘e1977d9195fe39e’</p></li>
<li><p>headers = {'Authorization': ‘Client-ID %s’ % api_key} parameters = {'image': image_data, type: ‘base64’,</p>
<pre>'name': filename,
'title': "%s uploaded by yt" % filename}</pre>
<p>data = urllib.parse.urlencode(parameters).encode('utf-8')</p></li>
<li><p>req = urllib.request.Request('<a href="https://api.imgur.com/3/upload">https://api.imgur.com/3/upload</a>', data=data,</p></li>
<li><p>headers=headers)</p></li></ul>
<p>+ req = urllib.request.Request( + ytcfg.get("yt", "imagebin_upload_url"), data=data, headers=headers)</p>
<pre> try:
response = urllib.request.urlopen(req).read().decode()
except urllib.error.HTTPError as e:</pre>
<p>@@ -1078,18 +1112,12 @@</p>
<pre>return {'uploaded':False}
rv = json.loads(response)
if 'data' in rv and 'link' in rv['data']:</pre>
<ul><li><p>delete_cmd = (</p></li>
<li><p>“curl -X DELETE -H 'Authorization: Client-ID {secret}'”</p></li>
<li><p>" <a href="https://api.imgur.com/3/image/">https://api.imgur.com/3/image/</a>{delete_hash}"</p></li>
<li><p>) print() print("Image successfully uploaded! You can find it at:") print(" %s" % (rv['data']['link'])) print() print("If you'd like to delete it, use the following")</p></li>
<li><p>print(" %s" %</p></li>
<li><p>delete_cmd.format(secret=api_key,</p></li>
<li><p>delete_hash=rv['data']['deletehash']))</p></li></ul>
<p>+ print(" yt delete_image %s" % rv['data']['deletehash'])</p>
<pre>print()
else:
print()</pre>
<p>Repository URL: <a href="https://bitbucket.org/yt_analysis/yt/">https://bitbucket.org/yt_analysis/yt/</a></p>
<p>—</p>
<p>This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.</p>
<img src="http://link.bitbucket.org/wf/open?upn=ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27BBAIIv285IzyTcRKG2zLm5dPl0bt5HJ4YA3snP3jcyeJIJobBIebfMVIPcLS1DSfg7D9x-2FUnmoaGrhw3XWEcN-2BG-2BT1wqpmnfi70HA6uQ3CwwkZAUXpg-2FhT3KZSO64g2h2hVXdgXBfFRiPTnogaaketflzXNJMTNJHC0y9d9AyeU5uB26OvKvh-2BQ1zHAZe240k-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>
</body></html>