Coder Social home page Coder Social 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

Using in AWS Lambda

  1. You need to sign up for an AWS account or use an existing one.
  2. After sign in to the AWS Management Console, select a region and open the AWS Lambda console.
  3. Choose Get Started Now.
  • Note: The console shows the Get Started Now page only if you do not have any Lambda functions created. If you have created functions already, you will see the Lambda > Functions page. On the list page, choose Create a Lambda function to go to the Lambda > New function page.
  1. On the Select blueprint page, choose Skip.
  2. On the Configure triggers page, do the following:
  3. Choose CloudWatch Events - Schedule.
  4. Enter a rule name in Rule name.
  5. Schedule expression select rate(1 day).
  6. Check Enable trigger.
  7. Choose Next.
  8. On the Configure function page, do the following:
  9. Enter a function name in Name.
  10. Runtime is Node.js 4.3 or above.
  11. Code entry type is Upload a .ZIP file.
  12. Zip the source code and Upload. - Please make sure to execute npm install and configure .env before zip the source code.
  13. In the Lambda function handler and role section, do the following: 1. Handler is aws-lambda.handler. 2. In Role, choose Create new role from template(s). 3. In Role name, type a name for the role. 4. In Role templates, you can leave this field blank because your Lambda function already has the basic execution permission it needs.
  14. In the Advanced settings section, do the following: 1. In Memory (MB), choose 128. 2. In Timeout, enter 0 min 30 sec.
  15. Choose Next.
  16. Choose Create Function to create a Lambda function. Imgur
  17. Choose Test.
  18. In the Input test event page, enter {} in the window.
  19. Choose Save and test.
  20. Upon successful execution, view results in the console. Imgur

grab_packt's People

Contributors

betauliansyah avatar coreytrombley avatar draconar avatar johnparn avatar mintbridge avatar taichunmin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grab_packt's Issues

Error: Cannot find module 'request'

You need to run npm install in the directory before running node server.js otherwise you get the following error (on Windows):

module.js:338
    throw err;
          ^
Error: Cannot find module 'request'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (c:\inetpub\wwwroot\grab_packt\server.js:1:77)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)

More Accurate Crontab Hour

I think the correct hour in crontab is 25 0 * * *, if you are using UTC/BST timezone in your server. I have compared date output with countdown clock in packt's website, and conclude this solution.

Here is my crontab settings:
25 0 * * * /usr/bin/nodejs /home/user/grab_packt/server.js >> /tmp/cron_output

node not found

when I

watch -n 5000 --difference node server.js

It says

sh: 1: node: not found

have I done something wrong?

Project just became obsolete

Since yesterday, Packt has stopped offering the free eBook of the day as part of their free learning programme. As of now, the same URL displays a page where you can sign up for the new deal: 10 days of free access to their entire catalog. As such, this software is no longer functional. I guess it would be best to update the README to reflect this.

Thanks for creating this. It was much appreciated.

This doesn't seem to be working

It was working until today and i've started getting this error...

----------- Packt Grab Started -----------
Request Error
----------- Packt Grab Done --------------

Packtpub paused the daily deals

Got this email several hours ago:

Whilst we finish getting ready for the reveal, we've temporarily paused Deal of the Day. Instead, every day we're giving you the chance to claim some free eBooks and today's free titles are all about web development.

And they are adding captcha in unregistered access.

I cant find the list of download links in this new free download program. I think it can only available from email they send.

watch command throws error

From Step 3 Using Node:

watch -n 5000 --differences node server.js

Msg:

> Watching /Users/name/scripts/grab_packt
sh: server.js: command not found

Are you using this package?
https://github.com/mikeal/watch

If so I cannot find a reference to -n or --differences in the README.

Cannot find module 'dotenv'

When I runned the "run.bat" file to test if this thing it's working I got this error:

`
C:\Users\Administrator\Documents\GitHub\grab_packt>run.bat
module.js:327
throw err;
^

Error: Cannot find module 'dotenv'
at Function.Module._resolveFilename module.js:325:15
at Function.Module._load module.js:276:25
at Module.require module.js:353:17
at require <internal/module.js:12:17>
at Object. <C:\Users\Administrator\Documents\GitHub\gran_pack\Server.js:1:63>
at Module._compile module.js:409:26
at Object.Module._extensions..js module.js:416:10
at Module.load module.js:343:32
at Function.Module._load module.js:441:10

C:\Users\Administrator\Documents\GitHub\grab_packt>
`
And that's all, output.txt it's also empty.

OS Information: Windows Server 2008 R2 Datacenter, Build 7601, x64, SP1
Node.js Information: MSI Installer, Current version: v4.4.7 (includes npm 2.15.8), nothing special done to it, just next, next, next, finish.

Any help?

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.