-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelescuff
More file actions
executable file
·171 lines (150 loc) · 3.92 KB
/
telescuff
File metadata and controls
executable file
·171 lines (150 loc) · 3.92 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
# Go into this script's folder.
cd "$(dirname `realpath $0`)"
# In case things are stored in local, and we're running in cron.
export PATH="$PATH:/usr/local/bin"
# Number of weeks of movie charts to scrape.
WEEKS=8
# Minimum rating of movies.
RATING=6
# Number of days to retain in the EZTV RSS cache.
RSS_DAYS=7
# Email address to send failures to.
EMAIL=""
# Neocities username.
USER=""
# Neocities password.
PASS=""
# Whether to scrape movie rentals
MOVIERENTALS=0
# Whether to refresh the EZTV RSS cache
RSSFEED=0
# Whether to scrape tv shows
TVSHOWS=0
# casperjs executable
CASPER=${CASPER:-casperjs}
# Script path
SCRAPER=${SCRAPER:-.}
# Parse the command line options.
PARSED=`getopt --options w:,r:,d:,m:,u:,p: --longoptions weeks:,rating:,rss-days:,mail:,user:,pass: --name "$0" -- "$@"`
if [[ $? -ne 0 ]]; then
exit 2
fi
# -- use eval with "$PARSED" to properly handle the quoting
eval set -- "$PARSED"
while true; do
case "$1" in
-w|--weeks)
WEEKS="$2"
shift 2
;;
-r|--rating)
RATING="$2"
shift 2
;;
-d|--rss-days)
RSS_DAYS="$2"
shift 2
;;
-m|--mail)
EMAIL="$2"
shift 2
;;
-u|--user)
USER="$2"
shift 2
;;
-p|--pass)
PASS="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
if [ "$WEEKS" = "" -a "$RATING" != "" ]; then
echo "Must specify number of weeks if rating is specified (-w/--weeks)."
exit 4
fi
# -- handle non-option arguments
case "$1" in
rss)
RSSFEED=1
shift 2
;;
movies)
MOVIERENTALS=1
shift 2
;;
tv)
TVSHOWS=1
shift 2
;;
all)
MOVIERENTALS=1
TVSHOWS=1
shift 2
;;
*)
echo "$0: unsupported scrape source '$1'. Must be 'rss', 'movies', 'tv' or 'all'."
exit 4
;;
esac
pushd "$SCRAPER"
get_mtime() {
if [ -f "$1" ]; then
stat -c %y "$1"
else
echo ""
fi
}
if [ $MOVIERENTALS -eq 1 ]; then
# Scrape rentals chart.
node --unhandled-rejections=strict rentals.puppeteer.js --weeks=$WEEKS --rating=$RATING
# Email if failure
if [ $? -ne 0 -a "$EMAIL" != "" ]; then
echo "Emailing failure to $EMAIL";
echo "Failed at $(date)" | mail -a "Message-ID:<scripts@telescuff>" -s "rentals script failed" $EMAIL;
elif [ "$USER" != "" ]; then
echo "Uploading movierentals to Neocities";
curl -F "movierentals.html=@movierentals.html" "https://$USER:$PASS@neocities.org/api/upload"
echo "{\"lastModified\": \"$(date -Iseconds)\"}" > moviesupdated.json
curl -F "moviesupdated.json=@moviesupdated.json" "https://$USER:$PASS@neocities.org/api/upload"
fi
fi
if [ $RSSFEED -eq 1 ]; then
# Refresh the local EZTV RSS cache.
node --unhandled-rejections=strict eztv.rss.js --max-days=$RSS_DAYS
# Email if failure
if [ $? -ne 0 -a "$EMAIL" != "" ]; then
echo "Emailing failure to $EMAIL";
echo "Failed at $(date)" | mail -a "Message-ID:<scripts@telescuff>" -s "eztv rss script failed" $EMAIL;
fi
fi
if [ $TVSHOWS -eq 1 ]; then
last_modified="$(get_mtime tvshows.html)"
# Build TV show page from the local RSS cache plus IMDb enrichment.
node --unhandled-rejections=strict tvshows.puppeteer.js
tv_status=$?
curr_modified="$(get_mtime tvshows.html)"
# Email if failure
if [ $tv_status -ne 0 ] || [ "$curr_modified" == "$last_modified" ]; then
echo "Failed, not uploading"
if [ "$EMAIL" != "" ]; then
echo "Emailing failure to $EMAIL";
echo "Failed at $(date)" | mail -a "Message-ID:<scripts@telescuff>" -s "tvshows script failed" $EMAIL;
fi
elif [ "$USER" != "" ]; then
echo "Uploading tvshows to Neocities";
curl -F "tvshows.html=@tvshows.html" "https://$USER:$PASS@neocities.org/api/upload"
echo "{\"lastModified\": \"$(date -Iseconds)\"}" > tvupdated.json
curl -F "tvupdated.json=@tvupdated.json" "https://$USER:$PASS@neocities.org/api/upload"
fi
fi
popd