0

I want to clean-up 12,000 wiki pages from this wiki category. For that, i am having all the 12,000 wikipages in a csv file. When my code runs, it modifies the page, one by one. How can i delete a previous row while reading a (next) row of a CSV file by python3 ? If it is possible, it will be easy to share the remaining rows of the csv file to another wiki contributor. Otherwise, i should manually open the csv file to delete 'the completed rows'.

My code as simplified;-

import csv
import pywikibot

with open('0.csv', 'r') as csvfile:
    reader = csv.reader(csvfile,delimiter="~")
    for row in reader:
    #if len(row) == 8:
        wikiPage1 = row[0]
        indexPages = row[5]
        print (wikiPage1)

        site = pywikibot.Site('ta', 'wiktionary')
        page1 = pywikibot.Page(site, wikiPage1)

        page1.text = page1.text.replace('Number','எண்')
        page1.save(summary=''Number --> எண்') 
2
  • You'd be better served by writing out a record of the ones you've done and then having a second script that generates a new file of incomplete ones. Alternatively, you could put the list of pages to edit in a database (e.g., sqlite) with a done column and just update the record when you complete each one. CSV isn't really a great choice here. I suppose an Excel file might work better, too. Commented May 13, 2018 at 11:33
  • yes. I am doing manually. My motive is to avoid those steps. Is this thread helpful? If it is how? Commented May 14, 2018 at 3:36

1 Answer 1

0

I learned from two web pages page-1, page-2 of this site.

The below code do this target;-

#-*- coding: utf-8 -*-

#bringing the needed library modules
import csv, time, subprocess

#subprocess.call("sed -i `` 1d 0-123.csv",shell=True)

WAIT_TIME = 10
with open('0-123.csv', 'r') as csvfile:
    reader = csv.reader(csvfile,delimiter="~")
    for row in reader:
#removing the first line of the csv        
        subprocess.call("sed -i `` 1d 0-123.csv",shell=True)
        wiktHeader1 = row[0]#.decode('utf-8')
        print ()
        print (wiktHeader1 + ' = படி-1: விக்சனரியின் தலைப்புச்சொல்.')
        time.sleep(WAIT_TIME)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.