Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 44 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,56 @@
# Module planetrise
Calculates and display the rise and set times of the planets for Magic Mirror 2

This module is powered with Don Cross's javascript library [astronomy.js](http://cosinekitty.com).
## Using the module
Calculates and display the rise and set times of the planets for [MagicMirror²](https://magicmirror.builders/).

This module is powered with Don Cross's javascript library [astronomy.js](https://github.com/cosinekitty/astronomy).

## Screenshot

![Screenshot](screenshot.png)

## Installation

Just clone the module into your modules folder of your MagicMirror²:

```bash
cd ~/MagicMirror/modules
git clone https://github.com/croxis/planetrise
```

## Configuration

To use this module, add it to the modules array in the `config/config.js` file:
````javascript
modules: [
{
module: 'planetrise',
position: 'top_right', // This can be any of the regions.
header: 'PLanet Rise',

```javascript
{
module: "planetrise",
position: "top_right", // This can be any of the regions.
header: "Planet Rise",
config: { // Place the latitude and longitude of your mirror
latitude: 45.5,
longitude: -122.38,
// A dictiory of the bodies and unicode character for the symbol
// This is the default and does not need to be listed.
// A full list of bodies can be seen on line 1359 in astronomy.js
// Note: Trying to find the rise time of Earth will crash the Module
bodies: {'Sun': '☉',
'Moon': '☽',
'Mercury': '☿',
'Venus': '♀',
'Mars': '♂',
'Jupiter': '♃',
'Saturn': '♄',
// Note: Trying to find the rise time of Earth will crash the module
bodies: {
Sun: "☉",
Moon: "☽",
Mercury: "☿",
Venus: "♀",
Mars: "♂",
Jupiter: "♃",
Saturn: "♄"
}
}
}
]
````
},
```

## Update

Go to the module’s folder inside MagicMirror modules folder and pull the latest version from GitHub:

```bash
cd ~/MagicMirror/modules/planetrise
git pull
```
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "planetrise",
"version": "1.0.0",
"description": "A MagicMirror² module to display the rise and set times of the planets.",
"main": "planetrise.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/croxis/planetrise.git"
},
"keywords": [
"astronomy"
],
"author": "croxis",
"license": "MIT",
"bugs": {
"url": "https://github.com/croxis/planetrise/issues"
},
"homepage": "https://github.com/croxis/planetrise#readme"
}
118 changes: 59 additions & 59 deletions planetrise.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
// Helper functions from http://cosinekitty.com/solar_system.html
var BriefDayOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
function BriefTimeString (date)
{
if (date == null) {
return "";
} else {
var h = date.getHours();
h = ((h < 10) ? "0" : "") + h.toString();
var m = date.getMinutes();
m = ((m < 10) ? "0" : "") + m.toString();
var s = date.getSeconds();
s = ((s < 10) ? "0" : "") + s.toString();
return BriefDayOfWeek[date.getDay()] + " " + h + ":" + m + ":" + s;
}
const BriefDayOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];

function BriefTimeString (date) {
if (date == null) {
return "";
}
let h = date.getHours();
h = (h < 10 ? "0" : "") + h.toString();
let m = date.getMinutes();
m = (m < 10 ? "0" : "") + m.toString();
let s = date.getSeconds();
s = (s < 10 ? "0" : "") + s.toString();
return `${BriefDayOfWeek[date.getDay()]} ${h}:${m}:${s}`;
}


function BriefDayValueString (day)
{
if (day == null) {
return "";
} else {
return BriefTimeString (Astronomy.DayValueToDate (day));
}
function BriefDayValueString (day) {
if (day == null) {
return "";
}
return BriefTimeString(Astronomy.DayValueToDate(day));
}

Module.register("planetrise", {
defaults: {
latitude: 34.2,
longitude: -118.1,
//bodies: ['Sun', 'Moon', 'Mercury', 'Venus', 'Mars', 'Jupiter', 'Saturn']
bodies: {'Sun': '☉',
'Moon': '☽',
'Mercury': '☿',
'Venus': '♀',
'Mars': '♂',
'Jupiter': '♃',
'Saturn': '♄',
// bodies: ['Sun', 'Moon', 'Mercury', 'Venus', 'Mars', 'Jupiter', 'Saturn']
bodies: {
Sun: "☉",
Moon: "☽",
Mercury: "☿",
Venus: "♀",
Mars: "♂",
Jupiter: "♃",
Saturn: "♄"
}
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
start () {
Log.info(`Starting module: ${this.name}`);

// Schedule update interval.
var self = this;
setInterval(function() {
self.updateDom();
}, 1000*60);
// Schedule update interval.
const self = this;
setInterval(() => {
self.updateDom();
}, 1000 * 60);
},
// Override dom generator.
getDom: function() {
getDom () {
latitude = this.config.latitude;
longitude = this.config.longitude;

var wrapper = document.createElement("table");
const wrapper = document.createElement("table");
wrapper.className = "small";

var AstroDateTime = new Date();
var day = Astronomy.DayValue (AstroDateTime);
var location = new GeographicCoordinates(longitude, latitude, 0);
const AstroDateTime = new Date();
const day = Astronomy.DayValue(AstroDateTime);
const location = new GeographicCoordinates(longitude, latitude, 0);

for (var i in Astronomy.Body) {
//AddRowForCelestialBody (Astronomy.Body[i], day);
if (Object.keys(this.config.bodies).indexOf(Astronomy.Body[i].Name) >= 0){
var planetWrapper = document.createElement("tr");
for (const i in Astronomy.Body) {
// AddRowForCelestialBody (Astronomy.Body[i], day);
if (Object.keys(this.config.bodies).indexOf(Astronomy.Body[i].Name) >= 0) {
const planetWrapper = document.createElement("tr");
planetWrapper.className = "normal";
var symbolWrapper = document.createElement("td");
const symbolWrapper = document.createElement("td");
symbolWrapper.className = "symbol";
//If fontio ever supports the full set
//var symbol = document.createElement("span");
//symbol.className = "fa fa-" + this.config.bodies[Astronomy.Body[i].Name];
//symbolWrapper.appendChild(symbol);
symbolWrapper.innerHTML = '<center>' + this.config.bodies[Astronomy.Body[i].Name] + '</center>';

// If fontio ever supports the full set
// let symbol = document.createElement("span");
// symbol.className = "fa fa-" + this.config.bodies[Astronomy.Body[i].Name];
// symbolWrapper.appendChild(symbol);

symbolWrapper.innerHTML = `<center>${this.config.bodies[Astronomy.Body[i].Name]}</center>`;
planetWrapper.appendChild(symbolWrapper);
var titleWrapper = document.createElement("td");
const titleWrapper = document.createElement("td");
titleWrapper.innerHTML = Astronomy.Body[i].Name;
titleWrapper.className = "title bright";
planetWrapper.appendChild(titleWrapper);
var riseWrapper = document.createElement("td");
const riseWrapper = document.createElement("td");
riseWrapper.className = "time light";
riseWrapper.innerHTML = BriefDayValueString(Astronomy.NextRiseTime(Astronomy.Body[i], day, location));
planetWrapper.appendChild(riseWrapper);
var setWrapper = document.createElement("td");
const setWrapper = document.createElement("td");
setWrapper.className = "time light";
setWrapper.innerHTML = BriefDayValueString(Astronomy.NextSetTime(Astronomy.Body[i], day, location));
planetWrapper.appendChild(setWrapper);
//planetWrapper.innerHTML = Object.keys(Astronomy.Body[i]).toString();
// planetWrapper.innerHTML = Object.keys(Astronomy.Body[i]).toString();
wrapper.appendChild(planetWrapper);
}
}
//wrapper.innerHTML = make_text(sun_elevation, next, julian_date);
// wrapper.innerHTML = make_text(sun_elevation, next, julian_date);
return wrapper;
},
getScripts: function() {
return['astronomy.js']
getScripts () {
return ["astronomy.js"];
}
});
});
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.