-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelescuff
executable file
·145 lines (128 loc) · 3.4 KB
/
telescuff
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
#!/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 eztv pages to scrape.
EZTV=15
# Email address to send failures to.
EMAIL=""
# Neocities username.
USER=""
# Neocities password.
PASS=""
# Whether to scrape movie rentals
MOVIERENTALS=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:,e:,m:,u:,p: --longoptions weeks:,rating:,eztv:,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
;;
-e|--eztv)
EZTV="$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
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 'movies', 'tv' or 'all'."
exit 4
;;
esac
pushd "$SCRAPER"
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 "[email protected]" "https://$USER:[email protected]/api/upload"
echo "{\"lastModified\": \"$(date -Iseconds)\"}" > moviesupdated.json
curl -F "[email protected]" "https://$USER:[email protected]/api/upload"
fi
fi
if [ $TVSHOWS -eq 1 ]; then
last_modified="$(stat -c %y tvshows.html)"
# Scrape tv shows chart.
node --unhandled-rejections=strict tvshows.puppeteer.js --pages=$EZTV
# $CASPER --ignore-ssl-errors=true --ssl-protocol=any --output-encoding=utf8 tvshows.js $EZTV
curr_modified="$(stat -c %y tvshows.html)"
# Email if failure
if [ $? -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 "[email protected]" "https://$USER:[email protected]/api/upload"
echo "{\"lastModified\": \"$(date -Iseconds)\"}" > tvupdated.json
curl -F "[email protected]" "https://$USER:[email protected]/api/upload"
fi
fi
popd