Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -88,8 +88,9 @@ def parse_google_translate_html(filepath):
|
|
| 88 |
elif param.startswith('tl='):
|
| 89 |
output_lang = param.split('=')[1]
|
| 90 |
elif param.startswith('q='):
|
| 91 |
-
input_text =
|
| 92 |
|
|
|
|
| 93 |
language = f"{input_lang} -> {output_lang}"
|
| 94 |
else:
|
| 95 |
input_text = ''
|
|
@@ -99,7 +100,7 @@ def parse_google_translate_html(filepath):
|
|
| 99 |
date_match = re.search(r'(\d{1,2}\s+\w{3}\s+\d{4}),\s+(\d{2}:\d{2}:\d{2}\s+\w+)', text)
|
| 100 |
|
| 101 |
if translation_match and date_match:
|
| 102 |
-
|
| 103 |
date_str, time_str = date_match.groups()
|
| 104 |
try:
|
| 105 |
date = datetime.strptime(f"{date_str} {time_str}", '%d %b %Y %H:%M:%S %Z')
|
|
@@ -112,8 +113,7 @@ def parse_google_translate_html(filepath):
|
|
| 112 |
translations.append({
|
| 113 |
'Date': formatted_date,
|
| 114 |
'Time': formatted_time,
|
| 115 |
-
'
|
| 116 |
-
'Translated Text': translated_text,
|
| 117 |
'Language': language
|
| 118 |
})
|
| 119 |
|
|
@@ -137,7 +137,7 @@ def google_translate_to_csv(filepath):
|
|
| 137 |
|
| 138 |
try:
|
| 139 |
with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
|
| 140 |
-
fieldnames = ['Date', 'Time', '
|
| 141 |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
| 142 |
|
| 143 |
writer.writeheader()
|
|
@@ -150,7 +150,7 @@ def google_translate_to_csv(filepath):
|
|
| 150 |
except Exception as e:
|
| 151 |
print(f"Error writing to CSV file: {str(e)}")
|
| 152 |
return None
|
| 153 |
-
|
| 154 |
def dataManipulator(converter, filepath):
|
| 155 |
global output_file
|
| 156 |
output_file = filepath
|
|
|
|
| 88 |
elif param.startswith('tl='):
|
| 89 |
output_lang = param.split('=')[1]
|
| 90 |
elif param.startswith('q='):
|
| 91 |
+
input_text = param.split('=')[1]
|
| 92 |
|
| 93 |
+
input_text = input_text.replace('+', ' ')
|
| 94 |
language = f"{input_lang} -> {output_lang}"
|
| 95 |
else:
|
| 96 |
input_text = ''
|
|
|
|
| 100 |
date_match = re.search(r'(\d{1,2}\s+\w{3}\s+\d{4}),\s+(\d{2}:\d{2}:\d{2}\s+\w+)', text)
|
| 101 |
|
| 102 |
if translation_match and date_match:
|
| 103 |
+
output_text = translation_match.group(1)
|
| 104 |
date_str, time_str = date_match.groups()
|
| 105 |
try:
|
| 106 |
date = datetime.strptime(f"{date_str} {time_str}", '%d %b %Y %H:%M:%S %Z')
|
|
|
|
| 113 |
translations.append({
|
| 114 |
'Date': formatted_date,
|
| 115 |
'Time': formatted_time,
|
| 116 |
+
'Requested translation': input_text,
|
|
|
|
| 117 |
'Language': language
|
| 118 |
})
|
| 119 |
|
|
|
|
| 137 |
|
| 138 |
try:
|
| 139 |
with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
|
| 140 |
+
fieldnames = ['Date', 'Time', 'Requested translation', 'Output', 'Language']
|
| 141 |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
| 142 |
|
| 143 |
writer.writeheader()
|
|
|
|
| 150 |
except Exception as e:
|
| 151 |
print(f"Error writing to CSV file: {str(e)}")
|
| 152 |
return None
|
| 153 |
+
|
| 154 |
def dataManipulator(converter, filepath):
|
| 155 |
global output_file
|
| 156 |
output_file = filepath
|