salat 0.2.9 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -79
- package/_config.yml +1 -1
- package/{index.js → app.js} +57 -57
- package/constants.js +19 -32
- package/data/cities.json +766 -466
- package/data/prayers.json +20 -20
- package/images/screenShot1.png +0 -0
- package/images/screenShot2.png +0 -0
- package/images/screenShot3.png +0 -0
- package/package.json +33 -33
- package/utils.js +79 -61
- package/images/logo.png +0 -0
package/README.md
CHANGED
|
@@ -1,79 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
$
|
|
22
|
-
|
|
23
|
-
# Run with
|
|
24
|
-
|
|
25
|
-
$ salat
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
- [
|
|
47
|
-
- [
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
- [x]
|
|
66
|
-
- [
|
|
67
|
-
- [
|
|
68
|
-
- [ ]
|
|
69
|
-
- [ ]
|
|
70
|
-
- [ ]
|
|
71
|
-
- [ ] Command to
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
### Built With :heart: in Ramadan
|
|
1
|
+
# Salat [](https://badge.fury.io/js/salat)
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
> Daily prayer time in all the cities in [Morocco](https://www.google.com/search?q=morocco) :morocco:, directly in your terminal, at the tip of your fingers
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
**A stupid simple Command line utility to get the daily prayers time for all the citiy in Morocco**
|
|
9
|
+
|
|
10
|
+
The source of the data is [the Moroccan Ministery Website](http://www.habous.gov.ma)
|
|
11
|
+
|
|
12
|
+
## Getting started
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Install
|
|
16
|
+
|
|
17
|
+
$ npm i -g salat
|
|
18
|
+
|
|
19
|
+
# Run with default city
|
|
20
|
+
|
|
21
|
+
$ salat
|
|
22
|
+
|
|
23
|
+
# Run with custom city
|
|
24
|
+
|
|
25
|
+
$ salat [cityName]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`City name should be provided the same way it's written in the cities.json`
|
|
29
|
+
|
|
30
|
+
## Output
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# The programs prints to the console the prayers' time for the current day in the default city as shown bellow:
|
|
34
|
+
```
|
|
35
|
+

|
|
36
|
+

|
|
37
|
+

|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Dependecies
|
|
41
|
+
|
|
42
|
+
The code behind depends on :
|
|
43
|
+
|
|
44
|
+
- [axios](https://github.com/axios/axios) to make an http request ( fetch the data).
|
|
45
|
+
- [jsdom](https://github.com/jsdom/jsdom) to parse the html result.
|
|
46
|
+
- [chalk](https://github.com/chalk/chalk) to avoid boring styles and colors.
|
|
47
|
+
- [node-localstorage](https://github.com/lmaccherone/node-localstorage) to read and write from localstorage.
|
|
48
|
+
|
|
49
|
+
## Change the default city
|
|
50
|
+
|
|
51
|
+
- The default city is :heart: [Marrakech](https://www.google.com/search?q=marrakech) :heart:, set as a value for the `DEFAULT_CITY` variable in `./constants.js`
|
|
52
|
+
|
|
53
|
+
- You can change it by replacing `Marrakech` by your city name according to the values from `./data/cities.json`
|
|
54
|
+
|
|
55
|
+
## Help
|
|
56
|
+
|
|
57
|
+
- Please keep in mind that this is a work in progress in a very early stages, any help is appreciated and more than welcome.
|
|
58
|
+
|
|
59
|
+
- If you think this piece of code is anyhow useful, please feel free to `contribute`, `star` :star::star: and `share` 🙏 🙏
|
|
60
|
+
|
|
61
|
+
## Todo
|
|
62
|
+
|
|
63
|
+
- [x] Use a default city
|
|
64
|
+
- [x] Use localstorage-like api for caching purposes
|
|
65
|
+
- [x] Display execution time
|
|
66
|
+
- [ ] Improve performance
|
|
67
|
+
- [ ] Add unit tests
|
|
68
|
+
- [ ] Add a documentation site
|
|
69
|
+
- [ ] Command to set the default city
|
|
70
|
+
- [ ] Command to display the list of available cities
|
|
71
|
+
- [ ] Command to display the time table for the whole month
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
This project is under the MIT license.
|
|
76
|
+
|
|
77
|
+
### Built With :heart: in Ramadan
|
package/_config.yml
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
theme: jekyll-theme-
|
|
1
|
+
theme: jekyll-theme-cayman
|
package/{index.js → app.js}
RENAMED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// Project's dependencies
|
|
4
|
-
const chalk = require("chalk");
|
|
5
|
-
const args = process.argv;
|
|
6
|
-
const {
|
|
7
|
-
getCityId,
|
|
8
|
-
getCityName,
|
|
9
|
-
displayResult,
|
|
10
|
-
getData,
|
|
11
|
-
parsePrayerTimesFromResponse
|
|
12
|
-
} = require("./utils.js");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
})();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Project's dependencies
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const args = process.argv;
|
|
6
|
+
const {
|
|
7
|
+
getCityId,
|
|
8
|
+
getCityName,
|
|
9
|
+
displayResult,
|
|
10
|
+
getData,
|
|
11
|
+
parsePrayerTimesFromResponse
|
|
12
|
+
} = require("./utils.js");
|
|
13
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED="0"
|
|
14
|
+
|
|
15
|
+
// Logging functioin
|
|
16
|
+
const green = msg => console.log(chalk.green(msg));
|
|
17
|
+
|
|
18
|
+
// Project's data
|
|
19
|
+
const { BANNER, LOCAL_STORAGE_PATH } = require("./constants");
|
|
20
|
+
const cities = require("./data/cities.json");
|
|
21
|
+
|
|
22
|
+
// Setting up localStorage
|
|
23
|
+
const { LocalStorage } = require("node-localstorage");
|
|
24
|
+
localStorage = new LocalStorage(LOCAL_STORAGE_PATH);
|
|
25
|
+
|
|
26
|
+
const cityName = getCityName(args[2], cities);
|
|
27
|
+
const cityId = getCityId(cityName, cities);
|
|
28
|
+
|
|
29
|
+
const main = async () => {
|
|
30
|
+
// Prinitng a banner ('cause I'm cool and I can do it XD)
|
|
31
|
+
green(BANNER);
|
|
32
|
+
|
|
33
|
+
const storageKey = `${cityName.toLowerCase()}_${new Date().toLocaleDateString()}`;
|
|
34
|
+
const item = localStorage.getItem(storageKey);
|
|
35
|
+
let prayers;
|
|
36
|
+
|
|
37
|
+
if (item) {
|
|
38
|
+
prayers = JSON.parse(item);
|
|
39
|
+
} else {
|
|
40
|
+
try {
|
|
41
|
+
prayers = parsePrayerTimesFromResponse(await getData(cityId));
|
|
42
|
+
localStorage.setItem(storageKey, JSON.stringify(prayers));
|
|
43
|
+
} catch (ex) {
|
|
44
|
+
//TODO: Use a more descriptif error message
|
|
45
|
+
console.error("Something went wrong!");
|
|
46
|
+
console.log(ex)
|
|
47
|
+
// console.log(ex);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
displayResult(prayers, cityName);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
(async () => {
|
|
56
|
+
await main();
|
|
57
|
+
})();
|
package/constants.js
CHANGED
|
@@ -1,32 +1,19 @@
|
|
|
1
|
-
const API_URL =
|
|
2
|
-
"http://www.habous.gov.ma/
|
|
3
|
-
|
|
4
|
-
const BANNER =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Your city was not found in the list
|
|
21
|
-
Using the default city
|
|
22
|
-
----------------------
|
|
23
|
-
You may need to check the spelling
|
|
24
|
-
`;
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
27
|
-
API_URL,
|
|
28
|
-
BANNER,
|
|
29
|
-
NOT_FOUND_ERROR,
|
|
30
|
-
DEFAULT_CITY: "Marrakech",
|
|
31
|
-
LOCAL_STORAGE_PATH: "./storage"
|
|
32
|
-
};
|
|
1
|
+
const API_URL =
|
|
2
|
+
"http://www.habous.gov.ma/prieres/horaire-api.php";
|
|
3
|
+
|
|
4
|
+
const BANNER = ``;
|
|
5
|
+
|
|
6
|
+
const NOT_FOUND_ERROR = `
|
|
7
|
+
Your city was not found in the list
|
|
8
|
+
Using the default city
|
|
9
|
+
----------------------
|
|
10
|
+
You may need to check the spelling
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
API_URL,
|
|
15
|
+
BANNER,
|
|
16
|
+
NOT_FOUND_ERROR,
|
|
17
|
+
DEFAULT_CITY: "Marrakech",
|
|
18
|
+
LOCAL_STORAGE_PATH: "./storage"
|
|
19
|
+
};
|