-
-
Save AlexR1712/2346a8425d295d91f3e84660afed8921 to your computer and use it in GitHub Desktop.
Script to redeem automatically books from `https://www.packtpub.com/packt/offers/free-learning` using bash and cronjob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#==INSTRUCTIONS | |
# - Add EMAIL and PASS infomation | |
# - Replace script path with your path `/home/USER/scripts/` in the script | |
# - Check your machine timezone `date +"%Z %z"` output ex: UTC +0000 | |
# - patckpub.com is UTC +0000, find the best hour for you to use in the crontab | |
# - Execute `crontab -e` | |
# - Add `0 1 * * * /bin/sh /home/USER/scripts/packtpub_redeem.sh > /home/USER/scripts/packtpub_redeem.out` , this mean everyday 1am | |
# - Restart Service `sudo service cron reload` (optional, crontab -e, will reload) | |
# - Add Permission `chmod 755 /home/USER/scripts/packtpub_redeem.sh` | |
#== | |
COOKIE="cookie.txt" | |
EMAIL="" | |
PASS="" | |
#Change dir to script folder | |
mkdir -p /home/${USER}/scripts/ | |
cd /home/${USER}/scripts/ | |
#Login and store Cookie | |
curl --silent -X POST -c ${COOKIE} \ | |
-d "mail=${EMAIL}&password=${PASS}" \ | |
https://www.packtpub.com/api/user/login > login.json | |
#Get Claim URL | |
PACKT_CLAIM_URL=$( | |
curl --silent https://www.packtpub.com/packt/offers/free-learning | \ | |
grep freelearning-claim | \ | |
sed 's/\t//g' | \ | |
awk '{print "https://www.packtpub.com"$2}' | \ | |
sed -e 's/href\=\"//g' -e 's/.$//g' | |
) | |
#Claim book using the Cookies from previous login and the extracted Claim URL | |
#https://www.packtpub.com/freelearning-claim/XXX/YYY | |
curl --silent -L -X GET -b ${COOKIE} ${PACKT_CLAIM_URL} > output.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment