You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Error occurred when I use sync from MyClipping.txt. I can see the reason comes from the language.
Describe the solution you'd like
A clear and concise description of what you want to happen.
I wrote a script to change the highlight and bookmark record into English. After running the script, the plugin works.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
You can paste this script somewhere in the readme in case other Chinese need help. Or maybe you can integrate into the workflow to convert while you detect it's Chinese
Additional context
Add any other context or screenshots about the feature request here.
Here is the code below. Btw, thanks for your efforts. I love it:
importrefromdatetimeimportdatetime# Function to convert Chinese day of the week to Englishdefchinese_day_to_english(day):
days= {
'星期一': 'Monday',
'星期二': 'Tuesday',
'星期三': 'Wednesday',
'星期四': 'Thursday',
'星期五': 'Friday',
'星期六': 'Saturday',
'星期日': 'Sunday'
}
returndays.get(day, '')
# Function to convert Chinese date string to English date stringdefconvert_chinese_to_english_hl(chinese_str):
ifnotisinstance(chinese_str, str):
print(chinese_str)
raiseTypeError("The str should be a string.")
# Extract parts using regex for both 上午 and 下午match=re.match(r"您在位置 #(\d+-\d+)的标注 \| 添加于 (\d{4})年(\d{1,2})月(\d{1,2})日(星期[一二三四五六日]) (上午|下午)(\d{1,2}):(\d{2}):(\d{2})", chinese_str)
ifnotmatch:
raiseValueError("String format is incorrect")
# Extracted partslocation=match.group(1)
year=match.group(2)
month=match.group(3)
day=match.group(4)
weekday_cn=match.group(5)
period=match.group(6)
hour=int(match.group(7))
minute=match.group(8)
second=match.group(9)
# Convert to 24-hour format if period is '下午'ifperiod=='下午'andhour!=12: # Skip if it's 12 PM since it is already in 24-hour formathour+=12elifperiod=='上午'andhour==12: # Convert 12 AM to 00hour=0# Convert weekday to Englishweekday_en=chinese_day_to_english(weekday_cn)
# Reformat date and timedatetime_obj=datetime(year=int(year), month=int(month), day=int(day), hour=hour, minute=int(minute), second=int(second))
date_en=datetime_obj.strftime("%d %b %Y %H:%M:%S")
# Assemble final stringresult=f"Your Highlight at location {location} | Added on {weekday_en}, {date_en}"returnresultdefconvert_chinese_to_english_bm(chinese_str):
ifnotisinstance(chinese_str, str):
print(chinese_str)
raiseTypeError("The str should be a string.")
# Extract parts using regex for both 上午 and 下午match=re.match(r"您在位置 #(\d+)的书签 \| 添加于 (\d{4})年(\d{1,2})月(\d{1,2})日(星期[一二三四五六日]) (上午|下午)(\d{1,2}):(\d{2}):(\d{2})", chinese_str)
ifnotmatch:
raiseValueError("String format is incorrect")
# Extracted partslocation=match.group(1)
year=match.group(2)
month=match.group(3)
day=match.group(4)
weekday_cn=match.group(5)
period=match.group(6)
hour=int(match.group(7))
minute=match.group(8)
second=match.group(9)
# Convert to 24-hour format if period is '下午'ifperiod=='下午'andhour!=12: # Skip if it's 12 PM since it is already in 24-hour formathour+=12elifperiod=='上午'andhour==12: # Convert 12 AM to 00hour=0# Convert weekday to Englishweekday_en=chinese_day_to_english(weekday_cn)
# Reformat date and timedatetime_obj=datetime(year=int(year), month=int(month), day=int(day), hour=hour, minute=int(minute), second=int(second))
date_en=datetime_obj.strftime("%d %b %Y %H:%M:%S")
# Assemble final stringresult=f"Your Bookmark at location {location} | Added on {weekday_en}, {date_en}"returnresult# Function to find and replace all matches in a documentdeffind_and_replace_all_hl(document):
pattern=r"您在位置 #(\d+-\d+)的标注 \| 添加于 (\d{4})年(\d{1,2})月(\d{1,2})日(星期[一二三四五六日]) (上午|下午)(\d{1,2}):(\d{2}):(\d{2})"matches=re.finditer(pattern, document)
formatchinmatches:
original_text=match.group(0)
english_str=convert_chinese_to_english_hl(original_text)
document=document.replace(original_text, english_str, 1)
returndocumentdeffind_and_replace_all_bm(document):
pattern=r"您在位置 #(\d+)的书签 \| 添加于 (\d{4})年(\d{1,2})月(\d{1,2})日(星期[一二三四五六日]) (上午|下午)(\d{1,2}):(\d{2}):(\d{2})"matches=re.finditer(pattern, document)
formatchinmatches:
original_text=match.group(0)
english_str=convert_chinese_to_english_bm(original_text)
document=document.replace(original_text, english_str, 1)
returndocumentdefread_txt_file(file_path, num_lines=5):
try:
withopen(file_path, 'r', encoding='utf-8') asfile:
content=file.read()
returncontentexceptExceptionase:
print(f"Error reading file: {e}")
returnNonedefwrite_txt_file(file_path, content):
try:
withopen(file_path, 'w', encoding='utf-8') asfile:
file.write(content)
exceptExceptionase:
print(f"Error writing to file: {e}")
# Example usagefile_path='/path/My Clippings.txt'# Replace with your actual file pathoutput_file_path='/path/My Clippings-new.txt'# file_content = read_txt_file(file_path, num_lines=5) # Read first 5 linesfile_content=read_txt_file(file_path) # Read first 5 linesiffile_content:
print(file_content)
english_document=find_and_replace_all_hl(file_content)
english_document=find_and_replace_all_bm(english_document)
write_txt_file(output_file_path, english_document)
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Error occurred when I use sync from MyClipping.txt. I can see the reason comes from the language.
Describe the solution you'd like
A clear and concise description of what you want to happen.
I wrote a script to change the highlight and bookmark record into English. After running the script, the plugin works.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
You can paste this script somewhere in the readme in case other Chinese need help. Or maybe you can integrate into the workflow to convert while you detect it's Chinese
Additional context
Add any other context or screenshots about the feature request here.
Here is the code below. Btw, thanks for your efforts. I love it:
The text was updated successfully, but these errors were encountered: