Skip to content

Commit

Permalink
Deploy all code. Bump version to 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nmfzone committed Jun 7, 2016
0 parents commit b7fef40
Show file tree
Hide file tree
Showing 6 changed files with 521 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Nabil Muhammad Firdaus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Jadwal Sholat
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/nmfzone/jadwal-sholat/issues)
[![Release](https://img.shields.io/badge/release-v1.0.0-orange.svg)](https://github.com/nmfzone/jadwal-sholat/releases)
[![Node](https://img.shields.io/badge/node-v5.8.x-blue.svg)]()
[![npm](https://img.shields.io/npm/v/npm.svg?maxAge=2592000)]()
[![GitHub license](https://img.shields.io/badge/license-MIT-red.svg)](https://raw.githubusercontent.com/nmfzone/jadwal-sholat/master/LICENSE)

Check Sholat Time Schedule with your beloved Command Line <3

## How to use
```
$ jadwalsholat "CITY_NAME"
```

## How to install
```
npm install -g phantomjs-prebuilt jadwalsholat
```
Note : jadwalsholat require phantomjs

## Available City
Open `city.js` to check the available city.

## Source
All the results are fetched from http://jadwalsholat.pkpu.or.id

## License
The MIT License (MIT)
128 changes: 128 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env node

'use strict'

const VERSION = 'v1.0.0'
var colors = require('colors')

if (process.argv.length <= 2) {
print('\nUsage: jadwalsholat "CITY_NAME"')
displayFooter()
exit()
}

var param = process.argv[2]
if (param == '--version' || param == '-v') {
print(VERSION.green)
exit()
}
else if (!param.match(/^[a-zA-Z\s]+$/i)) {
print('\nInvalid city name!'.yellow)
displayFooter()
exit()
}

// Check is city available
var city = require('./city')
var cityId = checkCity(param)

var Horseman = require('node-horseman')
var cheerio = require('cheerio')
var tabletojson = require('tabletojson')
var Table = require('cli-table')
var Spinner = require('cli-spinner').Spinner
var spinner = new Spinner('Collecting information... %s ')

spinner.setSpinnerString(7)
spinner.start()

var horseman = new Horseman()
horseman
.userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/50.0.2661.102 Chrome/50.0.2661.102 Safari/537.36")
.on('error', function(message, trace) {
print(message)
})
.on('timeout', function(message) {
print('Timeout\n')
})
.open('http://jadwalsholat.pkpu.or.id/monthly.php?id='+cityId)
.evaluate(function() {
return document.querySelector('.table_adzan tbody').innerHTML
})
.then(function(result) {
jadwalsholat.load(result).parse()
})
.finally(function() {
horseman.close()
spinner.stop()
return
})

var jadwalsholat = {
result: null,
tables: null,
checkResult() {
return (this.result != '' ? true:false)
},
load(res) {
this.parseHTML(res)
this.result = res
return this
},
parseHTML(html) {
var table = cheerio.load(html)
this.tables = table('tr.table_header').nextAll()
},
getThisDayTimeScheduleTable() {
let header = ["Shubuh", "Terbit", "Dzuhur", "Ashar", "Maghrib", "Isya"]
let body = []
var tbl = new Table(),
date = new Date().getDate(),
table = this.tables[date-1].children

let row = []
for (let i=1; i<table.length; i++) {
row.push(table[i].children[0].data)
}
body.push(row)

var thisDayTable = new Table({head: header})
for(let item in body) {
thisDayTable.push(body[item])
}

print(thisDayTable.toString())
},
parse() {
if (this.checkResult()) {
print("\n\n")
this.getThisDayTimeScheduleTable()
}
else {
print("\nSorry, we can't process your request right now :(".yellow)
}
displayFooter()
}
}

function checkCity(name) {
for (let i=0; i < city.length; i++) {
if (city[i].name.toLowerCase() == name.toLowerCase()) return city[i].id
}
print("\nSorry, we can't process your request, city not found.".yellow)
displayFooter()
exit()
}

function displayFooter() {
print('\n\nJadwal Sholat © 2016'.blue)
print('Visit https://github.com/nmfzone/jadwal-sholat for more information.')
}

function print(msg = '') {
console.log(msg)
}

function exit() {
process.exit(-1)
}

0 comments on commit b7fef40

Please sign in to comment.