Git Product home page Git Product logo

grab_packt's Introduction

Grab a book a day for free from Packt Pub, https://www.packtpub.com/packt/offers/free-learning.

1. Install prerequisites

Install this script in the cloned directory using the following command:

npm install

2. Add credentials

Copy the .env file into place with

cp .env.example .env

Or on Windows:

copy .env.example .env

And set your packt email and password.

3. Grab on recurrent basis

Using Node

After that run the script with the following command:

watch -n 5000 --differences node server.js

Using Crontab

Or add it to your crontable:

crontab -e

For the crontab all paths in MUST be absolute.

Within the open cron editor window

0 14 * * * /usr/local/bin/node /Users/<USER_NAME>/<PATH_TO>/grab_packt/server.js >> /tmp/cron_output

If you are using UTC/BST timezone in your server, you might want to set the crontab as follow:

25 0 * * * /usr/bin/nodejs /home/user/grab_packt/server.js >> /tmp/cron_output

Using Task Scheduler in Windows

Check the run.bat file in the repo. Correct any path if necessary according to your needs. Try running the script manually to verify that it works as expected.

Then add a scheduled task to execute run.bat every day by running.

add_scheduled_task.bat

OSX Error

If you get the message: crontab: temp file must be edited in place

On a related issue, if you get the message: crontab: temp file must be edited in place

Try:

  1. Add to .bash_profile
alias crontab="VIM_CRONTAB=true crontab"
  1. Add to .vimrc
if $VIM_CRONTAB == "true"
    set nobackup
    set nowritebackup
endif

note: .bash_profile might be called .profile
note: .vimrc and .bash_profile are located in the home directory: ~/
Reference: http://superuser.com/a/750528

Using Launchd (OSX)

launchd is recommended over cron for the OSX system.

This runs on load and from then on every 24 hours (86400 seconds).
Just substitute <username> for your own.

by daemon I am referring to the .plist file

Navigate to directory:

cd $HOME/Library/LaunchAgents

Create file:

touch com.<username>.grab_pkt.plist

Edit file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.<username>.grab_pkt</string>

  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/bin/node</string>
    <string>/Users/<username>/development/misc/grab_packt/server.js</string>
  </array>

  <key>Nice</key>
  <integer>1</integer>

  <key>StartInterval</key>
  <integer>86400</integer>

  <key>RunAtLoad</key>
  <true/>

  <key>StandardErrorPath</key>
  <string>/tmp/GrabPkt.err</string>

  <key>StandardOutPath</key>
  <string>/tmp/GrabPkt.out</string>
</dict>
</plist>

Load this daemon into the system:

launchctl load com.<username>.grab_pkt.plist

to unload just change load to unload

Check output of script:

/tmp/GrabPkt.out

It should be similar to:

----------- Packt Grab Started -----------
Book Title: Learning Libgdx Game Development
Claim URL: https://www.packtpub.com/freelearning-claim/13277/21478
----------- Packt Grab Done --------------

Check for errors:

/tmp/GrabPkt.err

Mine is empty due to having no errors.

In order to test I would:

  • remove the GrabPkt.out file
  • unload daemon
  • load daemon
  • check output of GrabPkt.out file

reference: http://alvinalexander.com/mac-os-x/mac-osx-startup-crontab-launchd-jobs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.