source: ValBot/drive_slash_adding.sh@ 1166

Last change on this file since 1166 was 1151, checked in by iritscen, 4 years ago

Adding scripts and instructions for using Pywikibot on OniGalore.

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/bin/bash
2
3IFS="
4"
5
6CORE="/path/to/Pywikibot/core"
7SUMMARY="added ending slash to URL and/or upgrading http to https to satisfy redirect"
8RATE=6
9FIX_START=0
10FIX_END=0
11
12cd "$CORE"
13if [ ! -f "pwb.py" ]; then
14 echo "drive_slash_adding.sh: Can't launch Pywikibot!"
15 exit
16fi
17
18echo "drive_slash_adding.sh: Starting at fix $FIX_START..."
19
20FIX_CUR=0
21LAST_RUN=0
22for THE_LINE in `cat "/path/to/ValExtLinks report.txt"`; do
23 #echo "drive_slash_adding.sh: Considering '$THE_LINE'..."
24 if [[ "$THE_LINE" =~ .*trailing.* ]] && [[ ! "$THE_LINE" =~ .*w/index.php.* ]]; then
25 #echo "drive_slash_adding.sh: This URL needs to be fixed."
26 let FIX_CUR+=1
27
28 if [ $FIX_CUR -lt $FIX_START ]; then
29 continue
30 fi
31
32 if [ $FIX_END -gt 0 ] && [ $FIX_CUR -gt $FIX_END ]; then
33 echo "drive_slash_adding.sh: Stopped after fix $FIX_END."
34 exit
35 fi
36
37 # Wait for rate limit to expire if we have run the Python script before in this session
38 if [ $LAST_RUN -gt 0 ]; then
39 CUR_TIME=$(date +%s)
40 WAIT_REMAINDER=$(($RATE - $CUR_TIME + $LAST_RUN))
41 if [ $WAIT_REMAINDER -gt 0 ]; then
42 echo "drive_slash_adding.sh: Waiting $WAIT_REMAINDER second(s)."
43 sleep $WAIT_REMAINDER
44 fi
45 fi
46 ON_PAGE=${THE_LINE#*page \'}
47 ON_PAGE=${ON_PAGE%%\'*}
48 FROM_LINK=${THE_LINE#*URL \'}
49 FROM_LINK=${FROM_LINK%%\'*}
50 TO_LINK=${THE_LINE%\'*}
51 TO_LINK=${TO_LINK##*\'}
52
53 #if [[ "$THE_LINE" =~ ${FROM_LINK}[^a-zA-Z/] ]]; then
54 # echo "URL is not isolated, skipping."
55 # continue
56 #fi
57
58 LAST_RUN=$(date +%s)
59 echo "pwb.by replace '-page:\"$ON_PAGE\" \"$FROM_LINK\" \"$TO_LINK\""
60 python pwb.py replace -page:"$ON_PAGE" "$FROM_LINK" "$TO_LINK" -summary:"$SUMMARY"
61 fi
62done
Note: See TracBrowser for help on using the repository browser.