-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwothin
executable file
·127 lines (106 loc) · 3.21 KB
/
wothin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# wothin: Webpage Opener Thinner
# Input is a .txt file in ~/.lowo/wothin of the format <lowo file name (no .txt)> <each page to open every . days>
# Distributes the webpages over that period.
# Added hrut support [2021-06-20 Sun] (changed whole thing to separately handle phases; simpler this way)
if [[ $# == 1 ]] ; then
ffront=${1%.*}
file=$HOME/.lowo/wothin/$ffront.txt
tmplowo=$HOME/.lowo/tmp_$ffront.txt
if [ ! -f "$file" ] ; then
echo "Can't find the file $file."
exit 1
fi
if [ -f "$tmplowo" ] ; then
echo "I've found $tmplowo, please remove it first."
exit 1
fi
else
echo "Usage: wothin <filename>"
exit 1
fi
touch "$tmplowo"
# Deal with hrut
if [[ -f ~/.hrut/hrut.pkl ]]
then
hrutvalue=$(hrut)
if [[ $hrutvalue -gt 100 ]]
then
hrutvalue="100"
fi
else
hrutvalue="100"
fi
# echo "Hrutvalue: $hrutvalue"
#Idea: go through each line of wothin file. Open line-of-file / period integer * hrutvalue / 100 upper integer part many, going in cycles.
no=$(cat $file | wc -l)
for i in `seq 1 $no`;
do
# Read line, get lowo filename and its period (i.e., how many days for the full file once)
loff=$(sed -n "$i p" $file)
lowofile=$(echo $loff|awk '{ print($1) }')
period=$(echo $loff|awk '{ print($2) }')
# Create clean list of webpages; notice: first line will be empty!!
cllowo=""
nol=$(cat $HOME/.lowo/$lowofile.txt | wc -l)
for j in `seq 1 $nol`;
do
url=$(sed -n "$j p" $HOME/.lowo/$lowofile.txt)
if [[ "$url" != "" ]] && [[ "$url" != "#"* ]] && [[ "$url" != "#" ]]
then
cllowo="$cllowo
$url"
fi
done
# echo "cllowo: $cllowo"
# Get no of jobs in cleaned lowofile, this is how many total we have.
noofjobs=$(($(echo "$cllowo"|wc -l)-1))
#echo "noofjobs: $noofjobs"
# How many lines do we need to do per day? Notice upper integer part:
portion=$((($noofjobs+$period-1)/$period))
# Correct by hrut
hportion=$(($portion*$hrutvalue/100))
#echo "portion: $hportion"
# Find where to start, phase is the line number we stopped at last time.
phfile=$HOME/.lowo/wothin/$lowofile"_phase"
if [ ! -f "$phfile" ] ; then
phase=0
else
phase=$(cat $phfile)
fi
# Write the new phase.
nph=$(($phase+$hportion))
# echo "old phase: $phase"
# echo "new phase: $nph"
# We start today with job phase+1 on line phase+2 BECAUSE first line of cllowo is empty!!
startl=$(($phase+2))
# echo "startl: $startl"
# And stop with job no = the new phase value nph. The first line of cllowo is empty!!
stopa=$(($nph+1))
# echo "stopa: $stopa"
##### if [[ $nph -lt $phase ]]
###### We rolled over or are watching empty virtual lines. We stop on the last job.
##### then
##### stope=$(($noofjobs+1))
#####echo "stope: $stope"
##### echo "$cllowo"|sed -n "$startl","$stope"p >> $tmplowo
##### else
###### No rollover. We may be watching empty virtual lines though so the lines interval may be out of range but that's ok, sed will be empty.
if [[ $stopa -ge $startl ]]
then
echo "$cllowo"|sed -n "$startl","$stopa"p >> $tmplowo
fi
#####fi
#
# Keep going until portion*period, imagine virtual empty lines at end of file.
virtuallines=$(($portion*$period))
if [[ $nph -ge $virtuallines ]]
then
nph=0
fi
echo "$nph" > $phfile
# echo "virtuallines: $virtuallines"
done
lowo "tmp_$ffront"
silent_cpucsekk
rm "$tmplowo"