Download your daily free Packt Publishing eBook https://www.packtpub.com/packt/offers/free-learning
Download your daily free Packt Publishing eBook https://www.packtpub.com/packt/offers/free-learning
This crawler automates the following step:
# upload pdf to googledrive, store data and notify via email
python script/spider.py -c config/prod.cfg -u googledrive -s firebase -n gmail…Before you start you should
python --versiongit clone https://github.com/niqdev/packtpub-crawler.gitpip install -r requirements.txt (see also virtualenv)cp config/prod_example.cfg config/prod.cfg[credential]
credential.email=PACKTPUB_EMAIL
credential.password=PACKTPUB_PASSWORDNow you should be able to claim and download your first eBook
python script/spider.py --config config/prod.cfgFrom the documentation, Google Drive API requires OAuth2.0 for authentication, so to upload files you should:
config/client_secrets.json[googledrive]
...
googledrive.client_secrets=config/client_secrets.json
[email protected]Now you should be able to upload your eBook to Google Drive
python script/spider.py --config config/prod.cfg --upload googledriveOnly the first time you will be prompted to login in a browser which has javascript enabled (no text-based browser) to generate config/auth_token.json.
You should also copy and paste in the config the FOLDER_ID, otherwise every time a new folder with the same name will be created.
[googledrive]
...
googledrive.default_folder=packtpub
googledrive.upload_folder=FOLDER_IDDocumentation: OAuth, Quickstart, example and permissions
From the documentation, OneDrive API requires OAuth2.0 for authentication, so to upload files you should:
[onedrive]
...
onedrive.client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
onedrive.client_secret=XxXxXxXxXxXxXxXxXxXxXxXNow you should be able to upload your eBook to OneDrive
python script/spider.py --config config/prod.cfg --upload onedriveOnly the first time you will be prompted to login in a browser which has javascript enabled (no text-based browser) to generate config/session.onedrive.pickle.
[onedrive]
...
onedrive.folder=packtpubDocumentation: Registration, Python API
To upload your eBook via scp on a remote server update the configs
[scp]
scp.host=SCP_HOST
scp.user=SCP_USER
scp.password=SCP_PASSWORD
scp.path=SCP_UPLOAD_PATHNow you should be able to upload your eBook
python script/spider.py --config config/prod.cfg --upload scpNote:
scp.path on the remote server must exists in advance--upload scp is incompatible with --store and --notifyCreate a new Firebase project, copy the database secret from your settings
https://console.firebase.google.com/project/PROJECT_NAME/settings/databaseand update the configs
[firebase]
firebase.database_secret=DATABASE_SECRET
firebase.url=https://PROJECT_NAME.firebaseio.comNow you should be able to store your eBook details on Firebase
python script/spider.py --config config/prod.cfg --upload googledrive --store firebaseTo send a notification via email using Gmail you should:
[gmail]
...
[email protected]
gmail.password=EMAIL_PASSWORD
[email protected]
[email protected],[email protected]Now you should be able to notify your accounts
python script/spider.py --config config/prod.cfg --notify gmail[ifttt]
ifttt.event_name=packtpub-crawler
ifttt.key=IFTTT_MAKER_KEYNow you should be able to trigger the applet
python script/spider.py --config config/prod.cfg --notify iftttValue mappings:
[join]
join.device_ids=DEVICE_IDS_COMMA_SEPARATED_OR_GROUP_NAME
join.api_key=API_KEYNow you should be able to trigger the event
python script/spider.py --config config/prod.cfg --notify join[pushover]
pushover.user_key=PUSHOVER_USER_KEY
pushover.api_key=PUSHOVER_API_KEYCreate a new branch
git checkout -b heroku-schedulerUpdate the .gitignore and commit your changes
# remove
config/prod.cfg
config/client_secrets.json
config/auth_token.json
# add
dev/
config/dev.cfg
config/prod_example.cfgCreate, config and deploy the scheduler
heroku login
# create a new app
heroku create APP_NAME --region eu
# or if you already have an existing app
heroku git:remote -a APP_NAME
# deploy your app
git push -u heroku heroku-scheduler:master
heroku ps:scale clock=1
# useful commands
heroku ps
heroku logs --ps clock.1
heroku logs --tail
heroku run bashUpdate script/scheduler.py with your own preferences.
More info about Heroku Scheduler, Clock Processes, Add-on and APScheduler
Build your image
docker build -t niqdev/packtpub-crawler:2.4.0 .Run manually
docker run \
--rm \
--name my-packtpub-crawler \
niqdev/packtpub-crawler:2.4.0 \
python script/spider.py --config config/prod.cfgRun scheduled crawler in background
docker run \
--detach \
--name my-packtpub-crawler \
niqdev/packtpub-crawler:2.4.0
# useful commands
docker exec -i -t my-packtpub-crawler bash
docker logs -f my-packtpub-crawlerAlternatively you can pull from Docker Hub this fork
docker pull kuchy/packtpub-crawlerAdd this to your crontab to run the job daily at 9 AM:
crontab -e
00 09 * * * cd PATH_TO_PROJECT/packtpub-crawler && /usr/bin/python script/spider.py --config config/prod.cfg >> /tmp/packtpub.log 2>&1Create two files in /etc/systemd/system:
[Unit]
Description=run packtpub-crawler
[Service]
User=USER_THAT_SHOULD_RUN_THE_SCRIPT
ExecStart=/usr/bin/python2.7 PATH_TO_PROJECT/packtpub-crawler/script/spider.py -c config/prod.cfg
[Install]
WantedBy=multi-user.target[Unit]
Description=Runs packtpub-crawler every day at 7
[Timer]
OnBootSec=10min
OnActiveSec=1s
OnCalendar=*-*-* 07:00:00
Unit=packtpub_crawler.service
Persistent=true
[Install]
WantedBy=multi-user.targetEnable the script with sudo systemctl enable packtpub_crawler.timer.
You can test the service with sudo systemctl start packtpub_crawler.timer and see the output with sudo journalctl -u packtpub_crawler.service -f.
The script downloads also the free ebooks from the weekly packtpub newsletter.
The URL is generated by a Google Apps Script which parses all the mails.
You can get the code here, if you want to see the actual script, please clone the spreadsheet and go to Tools > Script editor....
To use your own source, modify in the config
url.bookFromNewsletter=https://goo.gl/kUciutThe URL should point to a file containing only the URL (no semicolons, HTML, JSON, etc).
You can also clone the spreadsheet to use your own Gmail account. Subscribe to the newsletter (on the bottom of the page)
No open issues yet, or sync has not completed.