<commit_before>#!/usr/bin/python
# encoding: utf-8
from __future__ import division, print_function, unicode_literals, absolute_import

import sys

from workflow import Workflow, web, ICON_WEB

def main(wf):
    import argparse
    import re
    import requests
    import json    # Get args from Workflow, already in normalized Unicode

    args_wf = wf.args
    # print("#DUPA_-1")
    # print(args_wf[0])

    parser = argparse.ArgumentParser(description='Translate sentences using the DeepL API.')
    parser.add_argument('-l', '--language', default='PL', dest='lang',
                        help="The language to translate into. Defaults to English.")
    parser.add_argument('text', nargs='+', help="The text to be translated.")
    # print("#DUPA_0")
    args = parser.parse_args()
    # print(args)
    # print("#DUPA_1")
    text = " ".join(args.text)
    # print("#DUPA_2")
    # print(text)

    sp = re.compile("([^\.!\?;]+[\.!\?;]*)")
    sentences = [s for s in sp.split(text) if len(s) > 0]
    payload = {
        "jsonrpc": "2.0", "method": "LMT_handle_jobs", "id": 1,
        "params": {
            "jobs": [{"kind": "default", "raw_en_sentence": s} for s in sentences],
            "lang": {"user_preferred_langs": ["EN", "DE"],
                    "source_lang_user_selected": "auto",
                    "target_lang": args.lang},
            "priority": 1}}
    # print(payload)
    r = requests.post('https://deepl.com/jsonrpc', data=json.dumps(payload))
    translations = json.loads(r.text)['result']['translations']
    # print(translations)

    result = ""
    for translation in translations:
        # print(translation)
        beams = sorted(translation['beams'], key=lambda b: -1 * b['score'])
        for beam in beams:
            wf.add_item(title=wf.decode(beam['postprocessed_sentence']), valid=True, icon=ICON_WEB)

    # wf.add_item(
    #     'No results found',
    #     'Select to view google search',
    #     arg = 'http://www.google.com/',
    #     valid = True)


    wf.send_feedback()
<commit_msg>Fix encoding problems and remove debugging statements<commit_after>#!/usr/bin/python
# encoding: utf-8
from __future__ import division, print_function, unicode_literals, absolute_import

import sys

from workflow import Workflow, web, ICON_WEB

def main(wf):
    import argparse
    import re
    import requests
    import json    # Get args from Workflow, already in normalized Unicode

    parser = argparse.ArgumentParser(description='Translate sentences using the DeepL API.')
    parser.add_argument('-l', '--language', default='PL', dest='lang',
                        help="The language to translate into. Defaults to English.")
    parser.add_argument('text', nargs='+', help="The text to be translated.")
    args = parser.parse_args()
    text = " ".join(wf.args)

    sp = re.compile("([^\.!\?;]+[\.!\?;]*)")
    sentences = [s for s in sp.split(text) if len(s) > 0]
    payload = {
        "jsonrpc": "2.0", "method": "LMT_handle_jobs", "id": 1,
        "params": {
            "jobs": [{"kind": "default", "raw_en_sentence": s} for s in sentences],
            "lang": {"user_preferred_langs": ["EN", "DE"],
                    "source_lang_user_selected": "auto",
                    "target_lang": args.lang},
            "priority": 1}}
    r = requests.post('https://deepl.com/jsonrpc', data=json.dumps(payload))
    translations = json.loads(r.text)['result']['translations']
    result = ""
    for translation in translations:
        # print(translation)
        beams = sorted(translation['beams'], key=lambda b: -1 * b['score'])
        for beam in beams:
            wf.add_item(title=wf.decode(beam['postprocessed_sentence']), valid=True, icon=ICON_WEB)

    wf.send_feedback()

{'fraction_non_alphanumeric': 0.15632490013315578, 'fraction_numerical': 0.005059920106524634, 'mean_word_length': 2.8801652892561984, 'pattern_counts': {'":': 24, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2584960', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1160, 'n_words': 288}