User:Graham87/Logs.py

This page contains a quick script I wrote to enumerate the number of entries for each day in the old log pages; see this entry in my personal timeline for November 2016 for more details.

  1. !python3

import datetime

from dateutil import parser #Parse the dates

import fileinput #To process a list of files to input

import sys

dates={}

files=[]

fin=open('protlist.txt') #A file containing a list of log files in plain text format, one file per line; I happened to be working on the protection log when I last modified this file

for line in fin:

files.append(line.strip())

fin.close()

for line in fileinput.input(files):

if '[[User:' in line and '200' in line:

try:

date=str(parser.parse(line[line.find(':')-2:line.find('[')]).date())

except ValueError:

print(fileinput.filename(), fileinput.fileno())

print(line)

sys.exit()

dates[date]=dates.get(date,0)+1#Count the number of instances of each date

fout=open('protdates.txt','w') #The file containing the dates

date_list=list(dates)

date_list.sort()

for item in date_list:

fout.write(item+chr(9)+str(dates[item])+'\n')