Skip to content
[deprecated, line api has been changed] Line Bot + Automation Bot for Grabbing Apple Product Info. on server side. It uses PostgreSQL and Heroku. Complement: Execute "psql [database] [dbuser] table.sql" before coding. If you are using "postgresapp" on macOS, there is some default db/user setting, https://postgresapp.com/.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.env
.eslintrc.json
.gitignore
.travis.yml
Procfile
README.md
index.js
newrelic.js
package.json
table.sql

README.md

appleCrawler

Build Status

Use "request" + "cheerio" to grab the content of http://www.apple.com/tw/shop/browse/home/specialdeals/mac, then use Line to broadcast the information. Actually this project is more like a scraper but not change the repo name to keep the consistence.

Steps for development:

  1. (Optional) Install the latest version of Node.js from https://nodejs.org/en/
  2. Go to the project root folder.
  3. Type npm install to install npm dependencies.
  4. (Optional) Change the enviornment PORT to what you want. This is the server's port and default is 5000.
  5. Setup credentials for Line Bot. Also you need to fill your server's Domain name to Line Developer Center so that your Line BOT can receive messages. Otherwise this Line bot only can send. It means your Local server/developement always can send messanges only. (Line server can not reach localhost)
  6. (Optional) Setup credentials forTwilio.
  7. Setup Postgresql database. If you use Heroku on production, you can follow https://devcenter.heroku.com/articles/getting-started-with-nodejs#provision-a-database. Once you have setup, setup the enviorment DATABASE_URL to yours. E.g., postgres://yourPostgresURL. If you do not specify DATABASE_URL, it will look for the DB on the same machine and use login user account, since "start": "DATABASE_URL=postgres:///$(whoami) node index.js".
  8. Run npm start to launch the application.

How to setup enviornment variable in Node.js, there are several ways.

  1. Unix/Linux way: use Export.
  2. Package.json way: "start": "PORT=1234 node server.js",
  3. Heroku way (need to use heroku local): https://devcenter.heroku.com/articles/getting-started-with-nodejs#define-config-vars

Fill the credentials of Line Bot API

const client = LineBot.client({
  channelID: '<your channel ID>',
  channelSecret: '<your channel secret>',
  channelMID: '<your channel MID>'
});

(Optional) Fill the credentials of Twilio API (when reaching the maximal number of the friends of Line Bot, send the alarm)

const accountSid = 'Twilio Account SID';
const authToken = 'Twilio API Token';
const twilioClient = require('twilio')(accountSid, authToken);

twilioClient.messages.create({
    to: 'your phone number',
    from: 'your Twilio number',
    body: 'Line bot has problems !!',
  }, function (err, message) {
    console.log(message.sid);
  });

License

appleCrawler-node is released under the Apache 2.0 license.

You can’t perform that action at this time.