Last active
October 20, 2017 22:02
-
-
Save gdakram/37c56d1d23125067db6e2bb4e02f1356 to your computer and use it in GitHub Desktop.
Poeditor Python Curl Wrapper Scripts
This file contains hidden or 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
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(' ')) | |
This file contains hidden or 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
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