Created
March 7, 2018 17:43
-
-
Save danmou/20170f2e7468f9f1d3dce16b5262c03e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import base64 | |
import requests | |
import json | |
import subprocess | |
import tempfile | |
image = tempfile.NamedTemporaryFile().name | |
subprocess.run(['gnome-screenshot', '-a', '-f', image, '--display=:0'], check=True) | |
image_uri = "data:image/png;base64," + base64.b64encode(open(image, "rb").read()).decode('ascii') | |
r = requests.post("https://api.mathpix.com/v3/latex", | |
data=json.dumps({'src': image_uri}), | |
headers={"app_id": "", "app_key": "", | |
"Content-type": "application/json"}) | |
result = json.loads(r.text) | |
if result["error"]: | |
result = result["error"] | |
else: | |
result = result["latex"] | |
subprocess.run(['xclip', '-selection', 'clipboard'], input=result.encode('ascii')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment