Skip to content

Instantly share code, notes, and snippets.

@gdakram
Last active October 20, 2017 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdakram/37c56d1d23125067db6e2bb4e02f1356 to your computer and use it in GitHub Desktop.
Save gdakram/37c56d1d23125067db6e2bb4e02f1356 to your computer and use it in GitHub Desktop.
Poeditor Python Curl Wrapper Scripts
import sys
import subprocess
from optparse import OptionParser
import json
parser = OptionParser()
parser.add_option("-l", "--language", dest="language", help="The language file to download.")
parser.add_option("-t", "--api-token", dest="api_token", help="poeditor api token.")
parser.add_option("-i", "--project-id", dest="project_id", help="poeditor project id.")
(options, args) = parser.parse_args()
if not options.language:
print("Language not specified.")
sys.exit()
poe_command_pieces = []
poe_command_pieces.append("curl -s -X POST https://poeditor.com/api/")
poe_command_pieces.append("-F api_token={0}".format(options.api_token))
poe_command_pieces.append("-F id={0}".format(options.project_id))
poe_command_pieces.append("-F action=export")
poe_command_pieces.append("-F language={0}".format(options.language))
poe_command_pieces.append("-F filters=translated")
poe_command_pieces.append("-F type=android_strings")
poe_command = ' '.join(map(str, poe_command_pieces)).split(' ')
output = json.loads(subprocess.check_output(poe_command))
# Download the file
download_url = output['item']
print("Download url for \"{0}\" language is: {1}".format(options.language, download_url))
output = subprocess.check_output("curl -s {0} -o {1}.xml".format(download_url, options.language).split(' '))
import sys
import subprocess
from optparse import OptionParser
from os import path
parser = OptionParser()
parser.add_option("-f", "--file", dest="file", help="The file to upload.")
parser.add_option("-t", "--api-token", dest="api_token", help="poeditor api token.")
parser.add_option("-i", "--project-id", dest="project_id", help="poeditor project id.")
(options, args) = parser.parse_args()
if path.exists(options.file) == False:
print("File {0} not found.".format(options.file))
sys.exit()
poe_command_pieces = []
poe_command_pieces.append("curl -s -X POST https://poeditor.com/api/")
poe_command_pieces.append("-F api_token={0}".format(options.api_token))
poe_command_pieces.append("-F id={0}".format(options.project_id))
poe_command_pieces.append("-F file=@{0}".format(options.file))
poe_command_pieces.append("-F action=upload")
poe_command_pieces.append("-F sync_terms=1")
poe_command_pieces.append("-F updating=terms")
poe_command = ' '.join(map(str, poe_command_pieces)).split(' ')
output = subprocess.check_output(poe_command)
print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment