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 --> எண்') 
info-farmer
  • 255
  • 3
  • 18
  • 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. – jpmc26 May 13 '18 at 11:33
  • yes. I am doing manually. My motive is to avoid those steps. Is [this](https://stackoverflow.com/questions/36945500/how-to-delete-rows-not-columns-in-a-csv-file) thread helpful? If it is how? – info-farmer May 14 '18 at 03:36

1 Answers1

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)
info-farmer
  • 255
  • 3
  • 18