#-*- coding: utf-8 -*- import csv, pywikibot, time, datetime, subprocess, re, tamil, os, schedule, sys from pathlib import Path # pathlib module since the version 3.4. # https://www.pythontutorial.net/python-basics/python-check-if-file-exists/ # எனது நிரலகத்தில் இதன் பெயர் : wikt-cat-uploader-uniform-thesaurus.py #----------------------------------------------------------------------------------------- #PAWS கருவியில் logout செய்தால், No module error வரும். #அச்சூழ்நிலையில், மறுபடியும் நிறுவ வேண்டிய பைத்தான் நூற்கட்டகங்கள்/பொதிகள் = pip install Open-Tamil, schedule #command_for_UTC = subprocess.call('pip install Open-Tamil',shell=True) #command_for_module_openTamil = subprocess.call('pip install Open-Tamil',shell=True) #command_for_module_schedule = subprocess.call('pip install schedule',shell=True) #------------------------------------------------------------------------------------------ # எப்பொழுதும் கீழுள்ள இடுபெயர்கள் (vaiables) சரியாக உள்ளனவா என சரிரார்த்துக் கொள்ளவும். Always verify the below variables and the template before start inputCsvFile = 'wikt-cat-uploader-siddha-single.csv' pageStopLimit = 50 # [:3] பட்டியில் உள்ள முதல் மூன்று வரை மாற்றங்களை ஏற்படுத்துக. https://stackoverflow.com/questions/41137927/how-to-limit-the-number-of-strings-in-print Wait_Time = 60 message = 'And then, it will do 50 edits for every hour ...' #choose the right templates #'{{subst:noun-ta-all| '{{subst:noun-ta-nigandiyam|' ''{{subst:noun-ta-nigandiyam-thesaurus|' wiktFormBegin = '{{subst:noun-ta-nigandiyam|' wiktFormEnd = '}}' # கீழுள்ள வரிகளைக் கொண்டு எளிமையாக நேரத்தினைப்பெறலாம். மேலுள்ளவை அதிக வரிகளை இடத்தேவையில்லை. command_time_UTC = subprocess.call("TZ=UTC date",shell=True) command_time_UTC = subprocess.call('cat /etc/timezone',shell=True) command_time_UTC = subprocess.call("TZ=Asia/Calcutta date",shell=True) print('The script is running ... kindly wait for an hour')# will start its edit on 11.00 A.M. IST. so, wait please.') print(message) # tutorial: https://pypi.org/project/schedule/ def runNigandiumSiddha(): print(message) #if you are using other than ta.wiktionary, change the below category names in your language. granthaList = ['ஸ','ஷ', 'ஹ', 'க்ஷ', 'ஶ்ரீ', 'ஜ'] granthaCategory = '[[பகுப்பு:கிரந்த எழுத்துள்ள சொற்கள்]]' granthaCatFile = 'wikt-cat-0LetterGrantha.txt' path1_to_file = granthaCatFile path1 = Path(path1_to_file) compoundCategory = '[[பகுப்பு:கூட்டுச்சொற்கள்]]' compoundCatFile = 'wikt-cat-0LetterCompound.txt' path2_to_file = compoundCatFile path2 = Path(path2_to_file) #classifying the header, according to its letter count oneLetterCat = '[[பகுப்பு:ஓரெழுத்துச் சொற்கள்]]' twoLetterCat = '[[பகுப்பு:இரண்டெழுத்துச் சொற்கள்]]' threeLetterCat = '[[பகுப்பு:மூன்றெழுத்துச் சொற்கள்]]' fourLetterCat = '[[பகுப்பு:நான்கெழுத்துச் சொற்கள்]]' letterCountCatFile = 'wikt-cat-0LetterCount.txt' path3_to_file = letterCountCatFile path3 = Path(path3_to_file) # it helps already exist word only. wiktPageExistAddCat = 'wiktPageExistAddCat.txt' path4_to_file = wiktPageExistAddCat path4 = Path(path4_to_file) with open(inputCsvFile, 'r') as inputFile1: csvReader = csv.reader(inputFile1,delimiter="~") serialNum = 0 for row in csvReader: string = 'Going to stop by number = ' + str(pageStopLimit) serialNum = serialNum+1 numString = str(serialNum) + ' ' + string if serialNum < pageStopLimit+1 : print(numString) print(str(serialNum) + ' wikitionary page created. check the input file and rerun') #removing the first line of the csv # https://www.gnu.org/software/sed/manual/html_node/sed-script-overview.html#sed-script-overview # https://www.educba.com/sed-command-in-linux/ subprocess.call("sed -i `` 1d wikt-cat-uploader-siddha-single.csv",shell=True) #separating the csv data wiktHeader = row[0].strip().replace('# ','').replace('#','').replace('[','').replace(']','') wiktHeaderLen = len(tamil.utf8.get_letters(wiktHeader)) # wiktMeaning = row[1].strip() meaning = row[1].strip() searchPattern1 = '[\.\,]+$' wiktMeaning = re.sub(searchPattern1,'',meaning) # wiktThesaurus = row[2].strip() print(wiktHeader) print(meaning) print(wiktMeaning) # எடுத்தப் பக்கத்தரவில்,தலைப்புச்சொல்லில் உள்ள எழுத்தெண்ணிக்கைகளுக்கு ஒப்ப பகுப்பு இட, தலைப்புச்சொல்லிலுள்ள எழுத்துக்களை எண்ணுகிறேன். # https://pypi.org/project/Open-Tamil/ # https://www.slideshare.net/tshrinivasan/open-tamilpresentationta # to unuse the already created category data, removing the category file if path1.is_file(): print(f'The file {path1_to_file} created') os.remove(granthaCatFile) # இக்கோப்பிலே, தலைப்புச்சொல்லுக்குக்கேற்ற எண்ணிக்கைப் பகுப்பு சேரும். எனவே, ஏற்கனவே இக்கோப்பு இருப்பின் அழிக்கும். அப்பொழுதே எண்ணிக்கைப் பகுப்பு தவறாக வராது. else: print(f'The file {path1_to_file} does not exist') for grantha in granthaList: if grantha in wiktHeader: print(wiktHeader + 'is' + granthaCategory) with open (granthaCatFile,'w') as outFile: outFile.write(granthaCategory) break# it stops when grantha word comes else: print('granthaCategory is not present') with open (granthaCatFile,'w') as outFile: outFile.write('') with open(granthaCatFile, 'r') as outputGranthaCatFile: outputGranthaFileData = outputGranthaCatFile.read() print('the GranthaCat = ' + outputGranthaFileData) if path2.is_file(): print(f'The file {path2_to_file} created') os.remove(compoundCatFile) # இக்கோப்பிலே, தலைப்புச்சொல்லுக்குக்கேற்ற எண்ணிக்கைப் பகுப்பு சேரும். எனவே, ஏற்கனவே இக்கோப்பு இருப்பின் அழிக்கும். அப்பொழுதே எண்ணிக்கைப் பகுப்பு தவறாக வராது. else: print(f'The file {path2_to_file} does not exist') headerSpace = len(wiktHeader.split()) if headerSpace > 1: print('this is a compound word.') with open (compoundCatFile,'w') as outputCompoundCatFile: outputCompoundCatFile.write(compoundCategory) else: print('this is not a compound word.') with open (compoundCatFile,'w') as outputCompoundCatFile: outputCompoundCatFile.write('') with open(compoundCatFile, 'r') as outputCompoundCatFile: outputCompoundCatFileData = outputCompoundCatFile.read() print('the compoundCat = ' + outputCompoundCatFileData) if path3.is_file(): print(f'The file {path3_to_file} created') os.remove(letterCountCatFile) # இக்கோப்பிலே, தலைப்புச்சொல்லுக்குக்கேற்ற எண்ணிக்கைப் பகுப்பு சேரும். எனவே, ஏற்கனவே இக்கோப்பு இருப்பின் அழிக்கும். அப்பொழுதே எண்ணிக்கைப் பகுப்பு தவறாக வராது. else: print(f'The file {path3_to_file} does not exist') if wiktHeaderLen == 1: with open (letterCountCatFile,'w') as outputFile1: outputFile1.write(oneLetterCat) elif wiktHeaderLen == 2: with open (letterCountCatFile,'w') as outputFile1: outputFile1.write(twoLetterCat) elif wiktHeaderLen == 3: with open (letterCountCatFile,'w') as outputFile1: outputFile1.write(threeLetterCat) elif wiktHeaderLen == 4: with open (letterCountCatFile,'w') as outputFile1: outputFile1.write(fourLetterCat) else: print('The header is above five letters') with open (letterCountCatFile,'w') as outputFile1: outputFile1.write('') with open(letterCountCatFile, 'r') as output0letterCatFile: output0letterCatFileData = output0letterCatFile.read() print('the 0letterCat = ' + output0letterCatFileData) wikiProject = pywikibot.Site('ta','wiktionary') wiktHeaderPage = pywikibot.Page(wikiProject, wiktHeader) wiktPageDataExistSize = len(wiktHeaderPage.text.strip()) print('wiktPageDataExistSize = ' + str(wiktPageDataExistSize)) if wiktPageDataExistSize ==0: print('this wiktHeaderPage does not exist. So creating ...') allCurrentPageData = wiktFormBegin + '# ' + wiktMeaning + '| |' + wiktFormEnd allCatData = outputGranthaFileData + '\n' + outputCompoundCatFileData + '\n' + output0letterCatFileData + '\n' addCurrentPageDataAllCat = allCurrentPageData + '\n' + allCatData print('addCurrentPageDataAll is below;-') print(addCurrentPageDataAllCat) wiktHeaderPage.text = addCurrentPageDataAllCat summary = allCurrentPageData.replace(wiktFormBegin,'').replace(wiktFormEnd,'') wiktHeaderPage.save(summary) print() print('" '+ str(serialNum) + ' "'+ ' wiktionary pages "checked."' + ' it will save up to ' + str(pageStopLimit)) # Create class that acts as a countdown def countdown(s): # Calculate the total number of seconds total_seconds = s # While loop that checks if total_seconds reaches zero # If not zero, decrement total time by one second while total_seconds > 0: # Timer represents time left on countdown timer = datetime.timedelta(seconds = total_seconds) # Prints the time left on the timer print(timer, end="\r" + 'The page creater code starts in seconds ⇒⇒⇒ ') # Delays the program one second time.sleep(1) # Reduces total time by one second total_seconds -= 1 print('\nThe countdown timing completed! So, the page creater code running ... ') countdown(Wait_Time) else: print('this wiktHeaderPage already exists. So, checking the wiktHeader categories to add ...') else: print(' Total page target ' + '"' + str(pageStopLimit) + '"'+ ' completed. check the output at your contributions log or at the recent changes page.') break # https://schedule.readthedocs.io/en/stable/examples.html#examples #schedule.every(3).seconds.do(runNigandiumSiddha) #schedule.every(1).hours.until("13:30").do(runNigandiumSiddha) #UTC --> 7 P.M. IST schedule.every(1).hours.at("01:11").do(runNigandiumSiddha) #schedule.every(1).hours.do(runNigandiumSiddha) while True: schedule.run_pending() message2 = 'The script stopped its function at 7.00 P.M. IST 19.00 IST --> 13:30 UTC' print(message2) with open ('wikt-ta-clean-schedule.txt', 'a') as timerOutput: timerOutput.write(message2 + '\n')