-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteFeed.cgi
executable file
·103 lines (72 loc) · 1.69 KB
/
writeFeed.cgi
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
#!/bin/bash -e
# vim: set ts=4 sw=4
exec 2>&1
cat <<END
Cache-Control: no-cache
Content-Type: text/plain
END
source settings.txt
if [[ -z "$FeedLimit" || $FeedLimit == *[!0-9]* ]]
then
FeedLimit=500
fi
dir="files/"
userId=$(curl -sb "$HTTP_COOKIE" "http://$HTTP_HOST/getUserId.php")
file=$(find $dir -name "${userId}-*")
if [ -z "$file" ]
then
file=${dir}${userId}-$(echo $(od -An -N3 -i /dev/urandom))
fi
# call with either "head" or "tail"
function setUnixDate
{
line=$($1 -n 1 "$file")
engDate=$(echo "$line" | cut -d '|' -f 2 )
unixDate=$(date +%s -d "$(echo $engDate)")
}
# getStatuses, optional parameter $sinceDate
function getStatuses
{
newLines=0
if [ -f "$file" ]
then
newLines=$(wc -l < "$file")
fi
lines=$(( $newLines - 1))
while [ $newLines -gt $lines ]
do
lines=$newLines
params="limit=$FeedLimit"
if [ -f "$file" ]
then
setUnixDate "tail"
# "until" is inclusive, and we don't want to include a status we already have
lastDate=$(($unixDate - 1))
params="$params&until=$lastDate"
fi
if [ -n "$1" ]
then
params="$params&since=$1"
fi
# echo $params
curl -sb "$HTTP_COOKIE" "http://$HTTP_HOST/getFeed.php?$params" >> $file
newLines=$(wc -l < $file)
done
}
# if file exists get newer posts
if [ -f "$file" ]
then
# echo $firstdate
# have to do this ahead of the file move
setUnixDate "head"
# It looks like "since" is not inclusive, but what the hell
nextDate=$(($unixDate + 1))
tmp=$(tempfile)
mv "$file" "$tmp"
getStatuses $nextDate
$(cat "$tmp" >> "$file")
fi
# get older posts
getStatuses
echo "Finished, backup file: <a href=\"$file\">userId:$userId</a>"
exit