Giter VIP home page Giter VIP logo

mmm-lice's Introduction

MMM-LICE

Live International Currency Exchange

Well, almost live. It's more like hourly with the free API Access Key, but MMM-LICE sounded like such a cool name that I couldn't resist.

What you get

  • Real-time exchange rate for 168 World Currencies & PRECIOUS METALS

  • Exact date and time (UNIX) the exchange rates were collected.

  • 1000 free calls per month with free plan

  • Annotated .css file included for coloring text and header.

Examples

Many or few. You choose!

Installation

  • git clone https://github.com/mykle1/MMM-LICE into the ~/MagicMirror/modules directory.

  • Get your free API Access Key from https://currencylayer.com/ (Free plan)

  • No dependencies needed! No kidding!

Config.js entry and options

{
    module: 'MMM-LICE',
    position: 'top_left',                 // Best in left, center, or right regions
    config: { 
		accessKey: "Your API Access Key", // Free account & API Access Key at currencylayer.com
		source: "USD",                    // USD unless you upgrade from free account
		symbols: "AUD,CHF,EUR,GBP",       // Currency symbols
		useHeader: false,                 
		header: "Show me the money",
		maxWidth: "300px",
    }
},

SpaceCowboysDude is outta round but he always fixes my mistakes

mmm-lice's People

Contributors

mykle1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mmm-lice's Issues

Wont initiate

{
module: 'MMM-LICE',
position: 'bottom_center',                   // Best in left, center, or right regions
config: { 
	accessKey: "KEY", // Free account & API Access Key at currencylayer.com
	source: "SEK",       // The source currency
	x1: "USD",
	x2: "EUR",
	x3: "GBP",
	x4: "DKK",
	useHeader: false,                 
	header: "Show me the money",
	maxWidth: "400px",
}

},

This Leaves me with this on my magicmirror:
Source Currency = USD
USD = undefined
EUR = undefined
GBP = unfefined
DKK = undefined

Don't reload every 45min.

My config file:

		{
		module: 'MMM-LICE',
		position: 'top_center',                 // Best in left, center, or right regions
		config: { 
			accessKey: "SuperSecret", // Free account & API Access Key at currencylayer.com
			source: "USD",                    // USD unless you upgrade from free account
			symbols: "TRY,EUR,XAU,XAG",       // Currency symbols
			useHeader: false,                 
			header: "Döviz Kurları",
			maxWidth: "300px",
			animationSpeed: 3000,
			initialLoadDelay: 4250,
			retryDelay: 2500,
			updateInterval: 45 * 60* 1000, // 45 min = 992 in a 31 day month (1000 free per month)
		  }
		},

My mmm-lice.js file

`/* Magic Mirror
 * Module: MMM-LICE
 *
 * By Mykle1
 *
 */
Module.register("MMM-LICE", {

    // Module config defaults.
    defaults: {
		accessKey: "",       // Free account & API Access Key at currencylayer.com
	    source: "USD",       // USD unless you upgrade from free plan
		symbols: "",         // Add in config file
        useHeader: false,    // true if you want a header      
        header: "",          // Any text you want. useHeader must be true
        maxWidth: "300px",
        animationSpeed: 3000,
        initialLoadDelay: 4250,
        retryDelay: 2500,
        updateInterval: 45 * 60* 1000, // 45 min = 992 in a 31 day month (1000 free per month)

    },

    getStyles: function() {
        return ["MMM-LICE.css"];
    },

    getScripts: function() {
        return ["moment.js"];
    },

		
	start: function() {
        Log.info("Starting module: " + this.name);


        //  Set locale.
        this.url = "http://apilayer.net/api/live?access_key=" + this.config.accessKey + "&currencies=" + this.config.symbols + "&source=" + this.config.source + "&format=1";
        this.LICE = {};
        this.scheduleUpdate();
    },
	

    getDom: function() {

        var wrapper = document.createElement("div");
        wrapper.className = "wrapper";
        wrapper.style.maxWidth = this.config.maxWidth;

        if (!this.loaded) {
            wrapper.innerHTML = this.translate("Bana Lanet Parayı Göster!");
            wrapper.classList.add("bright", "light", "small");
            return wrapper;
        }

        if (this.config.useHeader != false) {
            var header = document.createElement("header");
            header.classList.add("small", "bright", "light", "header");
            header.innerHTML = this.config.header;
            wrapper.appendChild(header);
        }

        var LICE = this.LICE;
		

        var top = document.createElement("div");
        top.classList.add("list-row");


        // timestamp
        var timestamp = document.createElement("div");
        timestamp.classList.add("small", "bright", "timestamp");
        timestamp.innerHTML = "Oran " + moment.unix(LICE.timestamp).format('h:mm a') + " saatinde güncellendi.";
        wrapper.appendChild(timestamp);


        // source currency
        var source = document.createElement("div");
        source.classList.add("small", "bright", "source");
        source.innerHTML = "Ana Birim = TRY";
        wrapper.appendChild(source);
        
        
        // create table
         var Table = document.createElement("table");
            
        // create row and column for Currency
        var Row = document.createElement("tr");
        var Column = document.createElement("th");
        Column.classList.add("align-left", "small", "bright", "Currency");
        Column.innerHTML = "Birimler";
        Row.appendChild(Column);

        // create row and column for Rate
        var Rate = document.createElement("th");
        Rate.classList.add("align-left", "small", "bright", "Rate");
        Rate.innerHTML = "Miktar";
        Row.appendChild(Rate);
            

        Table.appendChild(Row);
        wrapper.appendChild(Table);
        
		
		
		// this gets the key from the key/pair of the element (hasOwnProperty)
		for (var Key in LICE.quotes) {
			
		if (LICE.quotes.hasOwnProperty(Key)) {
		Brm = Key.slice(3);
		
		if(Key == "USDTRY"){
			var TRY = LICE.quotes[Key];
		}
		if(Key == "USDEUR") {
			var EUR = LICE.quotes[Key];
		}
		if(Key == "USDXAU") {
			var XAU = LICE.quotes[Key];
		}
		if(Key == "USDXAG") {
			var XAG = LICE.quotes[Key];
		}
		
	//// Learned this on jsfiddle. HOORAY!
	//// This dynamically creates the div/tags for each element of LICE.quotes
		var symbols = LICE.quotes;
		for (var c in symbols) {
		
			var newElement = document.createElement("div");
			newElement.classList.add("align-left", "xsmall", "bright", "symbol");
			if(Brm == "EUR"){
				var val = (TRY/EUR).toString().slice(0,4);
				newElement.innerHTML += Brm + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + val; // + " = " + symbols[c];
			}
			if(Brm == "XAU"){
				var val = (1/(XAU)).toString().slice(0,7);
				newElement.innerHTML += Brm + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + val + '&nbsp $'; // + " = " + symbols[c];
			}
			if(Brm == "XAG"){
				var val = (TRY/XAG).toString().slice(0,7);
				newElement.innerHTML += Brm + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + val; // + " = " + symbols[c];
			}
			if(Brm == "TRY"){
				var val = LICE.quotes[Key].toString().slice(0,4);
				newElement.innerHTML += "USD" + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + val;  // + " = " + symbols[c];
			}

		}
	}
            
		wrapper.appendChild(newElement);

	} // <-- closes key/pair loop
	
        return wrapper;
		
}, // closes getDom
    
    
    
    
    /////  Add this function to the modules you want to control with voice //////

    notificationReceived: function(notification, payload) {
        if (notification === 'HIDE_LICE') {
            this.hide();
        }  else if (notification === 'SHOW_LICE') {
            this.show(1000);
        }
            
    },


    processLICE: function(data) {
        this.LICE = data;
	//	console.log(this.LICE);
        this.loaded = true;
    },

    scheduleUpdate: function() {
        setInterval(() => {
            this.getLICE();
        }, this.config.updateInterval);
        this.getLICE(this.config.initialLoadDelay);
    },

    getLICE: function() {
        this.sendSocketNotification('GET_LICE', this.url);
    },

    socketNotificationReceived: function(notification, payload) {
        if (notification === "LICE_RESULT") {
            this.processLICE(payload);

            this.updateDom(this.config.animationSpeed);
        }
        this.updateDom(this.config.initialLoadDelay);
    },
});
`

Error message.....

Module mmm-LICE starting but only displayind 'Rate as of Invalid date today'........ any solution to fix please ?

24h Clock format?

Hi there! Not really an issue, but mostly an ask for a feature - as opposed to an AM/PM calendar, would it be possible to add a 24h feature? Thanks!

Gold price

Hi can you please add the current gold price

i really love your module thinking about purchasing a plan

at the moment it is USDXAU meaning how much gold can you get for 1 USD dollar =0.000something79
when it should be XAUUSD how much USD will you get for 1 gold (default is ounce) = 1,275.55

Thank you once again for this awesome module,

do you know any other free api to get live/current gold price upto 15 minutes delay is fine

Two sources

I want my country's currency interms of USD and EUR. what should i do.
Output should be like
USDNPR - 113.23232
EURNPR - 128.32323

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.