-
Notifications
You must be signed in to change notification settings - Fork 5
/
Scraper_Twitter-new.sh
executable file
·78 lines (66 loc) · 2.2 KB
/
Scraper_Twitter-new.sh
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
#!/usr/bin/env bash
# The "new" version was created for parallel Tweeting while switching to a new Twitter
# handle. Also using this opportunity to clean up the code in this file.
#
# Scrape the Oakland Counmcil Legistar webpage and then Tweet upcoming meetings
# Written by Howard Matis - April 14, 2019
# Version 2.2 refelects moving code to different directory
VERSION="2.3"
source `dirname "$0"`/councilmatic.conf
DIR=`dirname "$0"` #/usr/local/councilmatic for production
export PATH=$PATH:`dirname "$0"`
#
cd $DIR
pwd
if [ -e geckodriver.log ]
then
rm geckodriver.log #This file gets big quickly
echo "Removed gecko log file!"
else
echo "nok"
fi
CURRENTYEAR=`date +"%Y"`
CURRENTMONTH=`date +"%m"`
CURRENTDAY=`date +"%d"`
FIRSTDAY=$CURRENTMONTH"/"$CURRENTDAY"/"$CURRENTYEAR # uncomment for debug
echo "The starting day is "$FIRSTDAY
# Here is the DATE-RELATED year-gathering code.
echo "On Ubuntu"
date --date="10 day" +"%Y" > year.tmp
date --date="10 day" +"%m" > month.tmp
date --date="10 day" +"%d" > day.tmp
LASTYEAR=$(<year.tmp)
LASTMONTH=$(<month.tmp)
LASTDAY=$(<day.tmp)
rm year.tmp month.tmp day.tmp
FINALDAY=$LASTMONTH"/"$LASTDAY"/"$LASTYEAR # uncomment for debug
echo "The final day is "$FINALDAY
echo "[Diag] The Python path is: $PYTHON"
export MOZ_HEADLESS=1 #Needed to run Firefox Headless
echo "Version "$VERSION" of Scraoer_Twitter.sh" #Clear cron log file
#
#Preparing to run the scraper
#
## source set_json_scraper_symlink.sh # Set environment for json
date
echo "Doing the JSON Scrape"
COMMAND="src-Scraper/run_meeting_json.py --days 7 --output WebPage/website/scraped/TwitterTEMP.json --calendars WebPage/website/calendars/"
echo "Starting the Scrape with the command:" $COMMAND
$PYTHON $COMMAND
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Scraper error. Will ignore"
else
mv WebPage/website/scraped/TwitterTEMP.json WebPage/website/scraped/Twitter.json
echo "Successful scraper file"
fi
date
if [[ $WEBSITEPATH == *"dev"* ]]; then
# if 'dev' version then don't actually tweet
$PYTHON src-Tweeter/Tweeter-new.py FALSE
else
# otherwise, go ahead and tweet
$PYTHON src-Tweeter/Tweeter-new.py TRUE
fi
echo "Scraper_Twitter.sh completed"
#