Giter Site home page Giter Site logo

miracle's Introduction

miracle

miracle

Read Quran and Get Info about Suar and Ajzaa

Build Status

Installation

  • Install the gomodule package with:
go get -u github.com/Omar-Belghaouti/miracle
  • Or import the package in your project:
import "github.com/Omar-Belghaouti/miracle"

And run:

go mod tidy

Quick Start

package main

import (
	"fmt"
	"log"

	"github.com/Omar-Belghaouti/miracle"
	"github.com/Omar-Belghaouti/miracle/ajzaa"
	"github.com/Omar-Belghaouti/miracle/suar"
)

func main() {
	quran := miracle.Book()
	quran.SetLanguage("en")

	surah, err := quran.ReadSurah(suar.AAL_IMRAN)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Println(surah.Name)
	for k, v := range surah.Verse {
		fmt.Printf("%s: %s\n", k, v)
	}

	juz, err := quran.GetJuzInfo(ajzaa.JUZ_19)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Println(juz.Start)

	surahInfo, err := quran.GetSurahInfo(suar.AL_ADIYAT)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Println(surahInfo.Title)
}

Documentation

Check the documentation website for more information.

miracle's People

Contributors

omdxp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

miracle's Issues

Verses are out of order?

  • The verses of Suar are returned as map[string]string so you can access a verse quickly (O(1)).
  • Since the verses are returned as a map they may be returned out of order. Here is a workaround to get them in order:
package main

import (
	"fmt"
	"log"
	"sort"
	"strconv"
	"strings"

	"github.com/Omar-Belghaouti/miracle"
	"github.com/Omar-Belghaouti/miracle/suar"
)

func main() {
	quran := miracle.Book()

	surah, err := quran.ReadSurah(suar.NUH)
	if err != nil {
		log.Fatal(err.Error())
	}

	keys := []struct {
		key   string
		value string
	}{}
	for k, v := range surah.Verse {
		key := strings.Split(k, "verse_")[1]
		keys = append(keys, struct {
			key   string
			value string
		}{
			key:   key,
			value: v,
		})
	}
	sort.Slice(keys, func(i, j int) bool {
		left, _ := strconv.Atoi(keys[i].key)
		right, _ := strconv.Atoi(keys[j].key)
		return left < right
	})

	for _, v := range keys {
		fmt.Printf("%s: %s\n", v.key, v.value)
	}

}

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.