விக்கிமூலம்:பைத்தான்3நிரல்கள்/தலைப்பைநகர்த்தலின் பக்கங்கள்

விக்கிமூலம் இலிருந்து

தொடர்புடையன[தொகு]

  • விக்கிமூலம்:பைத்தான் நிரல்கள்
  • விக்கிமூலம்:பைத்தான்3நிரல்கள்/தலைப்பைநகர்த்தல்
  • குறிப்புரை : பொதுவகத்தில் மூலக்கோப்புகளை ஏற்றும் பொழுது நூலின் உள்ளே இருக்கும் தலைப்பு குறித்து ஆராய்ந்து பதிவேற்ற வேண்டும். அவசர சூழ்நிலைகளில் இதனை நடைமுறைப்படுத்துதல் கடினம். பிறகு, நூலினை ஆயும் பொழுது, அந்நூலின் தலைப்பு விக்கிவிதிகளுக்கு ஏற்பவும், நூலின் உரிமைப்பதிவுக்கு ஏற்பவும் மாற்றபடுகிறது. மெய்ப்புப்பணி முடியாத நூல் என்றால், அதைச்செய்வது எளிது. எழுத்தாவண மின் நூல் உருவாக்கப்பட்டு இருந்தால், முந்தைய பெயர் இணைக்கப்பட்டுள்ளபெரியார்.pdf இந்த நுட்பம் வழியே கண்டறிந்து, தலைப்பு மட்டும் அல்லாமல், நூலின் உள்ளேயுள்ள தரவுகளிலும் மாற்ற வேண்டிய அவசியம் வரும். அச்சூழ்நிலையில் இந்த நிரல் உதவும். இதன் பணிகள்90% முடிந்ததன. எனினும், இந்நிரல் இயக்கிய பின்பு, மாற்றமடைந்த பக்கங்களை சரிபார்த்துக் கொள்ள வேண்டும்.

எடுத்துக்காட்டு:

நிரலாக்கம்[தொகு]

from bs4 import BeautifulSoup # this library helps to extract / harvest the web page data.
import requests, csv, time, re, pywikibot

# always double check your input data
# https://ta.wikisource.org/wiki/special:WhatLinksHere/அட்டவணை:தந்தை பெரியார்.pdf
earlier_index_name = 'அட்டவணை:தந்தை பெரியார்.pdf'
earlier_index_name_only = earlier_index_name.split(':')[1].split('.')[0]
print(earlier_index_name_only)
new_index_name = 'அட்டவணை:தந்தை பெரியார், நீலமணி.pdf'
new_index_name_only = new_index_name.split(':')[1].split('.')[0]
print(new_index_name_only)

checking_namespace = 'special:WhatLinksHere/' + earlier_index_name 
whatslinks_url = 'https://ta.wikisource.org/wiki/' + checking_namespace
print(whatslinks_url + '\n')


index_links_data = requests.get(whatslinks_url).content
soup = BeautifulSoup(index_links_data,'lxml')
#linked_pages1 = soup.find('div',id="mw-content-text").text#"mw-whatlinkshere-list")
linked_pages = soup.find('ul',id="mw-whatlinkshere-list").text
search_key = earlier_index_name + ' எந்தப் பக்கத்திலும் இந்தப் பக்கம் இணைக்கப்படவில்லை.'
if search_key in linked_pages:
	print('your input index name may be wrong.')
else:
	print('your input index name is having data.')
	
	# checking breaks in new_index_name 
	wiki_project = pywikibot.Site('ta', 'wikisource')
	wiki_page = pywikibot.Page(wiki_project, new_index_name)
	new_index_name_data_all = wiki_page.text
	new_index_name_data_all_list = new_index_name_data_all.split('\n')
	#print(new_index_name_data_all_list)

# checking every line of the given index and if content page available replace the earlier_index_name with new_index_name.	
for sNo,index_line in enumerate (new_index_name_data_all_list) :
	if new_index_name_only in index_line and '{{' in index_line :
		index_line_crop = index_line.split('}}')[0].split('{{')[1]
		print(index_line_crop)
		content_page = pywikibot.Page(wiki_project, index_line_crop)
		content_page_data = content_page.text
		#print(content_page_data)
		if new_index_name_only in content_page_data:
			print('seems that new name replaced')
		else:
			print('seems that old name exists')

			if '{{Dtpl' in content_page_data :
				if not new_index_name_only in content_page_data:
					content_page_data_replaced = content_page_data.replace(earlier_index_name_only,new_index_name_only) 
					print(content_page_data_replaced)
					content_page.text = content_page_data_replaced
					#content_page.save(new_index_name_only) 
					# மேலடியில் தலைப்பு இருந்தால் நீக்காதபடி செய்யணும். நூற்தொகுப்பு வார்ப்புவை spilt செய்து பழைய பெயரை புதிய பெயருக்கு மாற்ற வேண்டும்.
	else:
		# checking every line of the given index
		print('checking....no needed data line')
	
	time.sleep(1)

		

		
	#subpage தரவினுள், page name என்பதிலுள்ள தலைப்பை மட்டும் பதுப்பெயருக்கு மாற்ற வேண்டும். புதிய பெயர் அடுத்த பக்கம், முந்தைய பக்கம் என்ற வார்ப்புரு அலகுகளில் மாற்றாதபடி நுட்பம் செய்யணும்.
	# எ-கா https://ta.wikisource.org/w/index.php?title=%E0%AE%A4%E0%AE%A8%E0%AF%8D%E0%AE%A4%E0%AF%88_%E0%AE%AA%E0%AF%86%E0%AE%B0%E0%AE%BF%E0%AE%AF%E0%AE%BE%E0%AE%B0%E0%AF%8D%2C_%E0%AE%A8%E0%AF%80%E0%AE%B2%E0%AE%AE%E0%AE%A3%E0%AE%BF%2F%E0%AE%AA%E0%AF%86%E0%AE%B0%E0%AE%BF%E0%AE%AF%E0%AE%BE%E0%AE%B0%E0%AF%88%E0%AE%AA%E0%AF%8D_%E0%AE%AA%E0%AF%86%E0%AE%B1%E0%AF%8D%E0%AE%B1%E0%AF%86%E0%AE%9F%E0%AF%81%E0%AE%A4%E0%AF%8D%E0%AE%A4_%E0%AE%AA%E0%AE%BE%E0%AE%95%E0%AF%8D%E0%AE%95%E0%AE%BF%E0%AE%AF%E0%AE%9A%E0%AE%BE%E0%AE%B2%E0%AE%BF%E0%AE%95%E0%AE%B3%E0%AF%8D&type=revision&diff=1290293&oldid=1290288
	
	linked_pages_list = soup.find('ul',id="mw-whatlinkshere-list").text.split(' (← ')
	list_items_count = len(linked_pages_list)
	print(list_items_count) 
	#listing_items 
	for serial_number,the_page in enumerate (linked_pages_list):
		human_serial_number = serial_number+1 # python start numbering from '0'. so, adding '1'.
		the_page_clean = the_page.replace('இணைப்புக்கள் | தொகு)', '').replace('(உள்ளிடப்பட்டுள்ளது)','').replace('\n', '')
		list_coined = str(human_serial_number) +  '. ' + the_page_clean
		the_page_clean_data_count =  len(the_page_clean)
		if the_page_clean_data_count != 0 :
			print(the_page_clean) # skipped if the above 'for loop' contains empty string
			time.sleep(1)
			
			# cleaning the linked pages.
			if 'ஆசிரியர்:' in the_page_clean:
				print('clean the pagelink break')				
				# clean the pagelink break
				wiki_project = pywikibot.Site('ta','wikisource')
				wiki_url = pywikibot.Page(wiki_project,the_page_clean)
				the_page_clean_data = wiki_url.text
				#print(the_page_clean_data)
				# going to replace the new_index_name as above / 9th line
				the_page_clean_data_changed = the_page_clean_data.replace(earlier_index_name_only,new_index_name_only) 
				print(the_page_clean_data_changed)
				wiki_url.text = the_page_clean_data_changed 
				#wiki_url.save(new_index_name_only)
				time.sleep(15)
			else:
				print('Already cleaned the pagelink break')
				
				
				
			if new_index_name_only in the_page_clean:
				print('clean the pagelink break')
				# clean the pagelink break
				wiki_project = pywikibot.Site('ta','wikisource')
				wiki_url = pywikibot.Page(wiki_project,the_page_clean)
				the_page_clean_data = wiki_url.text
				#print(the_page_clean_data)
				# going to replace the new_index_name as above / 9th line
				the_page_clean_data_changed = the_page_clean_data.replace(earlier_index_name_only,new_index_name_only) 
				print(the_page_clean_data_changed)
				wiki_url.text = the_page_clean_data_changed 
				#wiki_url.save(new_index_name_only)
				time.sleep(15)
			else:
				print('Already cleaned the pagelink break')