Esempio n. 1
0
    async def get_prayertimes_local(self, location, calculation_method):
        async def get_information(location):
            url = "http://api.aladhan.com/v1/hijriCalendarByAddress"
            params = {"address": location}
            async with self.session.get(url, headers=headers,
                                        params=params) as resp:
                data = await resp.json()
                meta = data['data'][0]['meta']
                coordinates = (meta['latitude'], meta['longitude'])
                timezone_name = meta['timezone']
            time = dt.datetime.now(gettz(timezone_name))
            timezone_offset = time.utcoffset() / timedelta(hours=1)
            return coordinates, time, timezone_offset

        def get_method_name(method_id):
            id_to_name = {
                3: 'MWL',
                2: 'ISNA',
                5: 'Egypt',
                4: 'Makkah',
                1: 'Karachi',
                7: 'Tehran',
                0: 'Jafari',
                8: 'Gulf',  #TODO add this method to praytimes.py
                9: 'Kuwait',  #TODO add this method to praytimes.py
                10: 'Qatar',  #TODO add this method to praytimes.py
                11: 'Singapore',  #TODO add this method to praytimes.py
                12: 'France',  #TODO add this method to praytimes.py
                13: 'Turkey',  #TODO add this method to praytimes.py
                14: 'Russia',  #TODO add this method to praytimes.py

                # didn't include method 'MOONSIGHTING' because it uses 'shafaq' parameter,
                # which isn't used in praytimes.py
            }
            return id_to_name[method_id]

        coordinates, time, time_offset = await get_information(location)
        date = (time.year, time.month, time.day)
        method_name = get_method_name(calculation_method)
        prayTimes = PrayTimes()
        prayTimes.setMethod(method_name)
        prayTimes.adjust({"highLats": "AngleBased"})
        prayTimes.adjust({"asr": "Standard"})
        times = prayTimes.getTimes(date, coordinates, time_offset)
        prayTimes.adjust({"asr": "Hanafi"})
        timesWithHanafiAsr = prayTimes.getTimes(date, coordinates, time_offset)

        fajr = times['fajr']
        sunrise = times['sunrise']
        dhuhr = times['dhuhr']
        asr = times['asr']
        hanafi_asr = timesWithHanafiAsr['asr']
        maghrib = times['maghrib']
        isha = times['isha']
        imsak = times['imsak']
        midnight = times['midnight']
        sunrise = times['sunrise']
        readable_date = time.strftime('%d %B, %Y')

        return fajr, sunrise, dhuhr, asr, hanafi_asr, maghrib, isha, imsak, midnight, readable_date
Esempio n. 2
0
 def Resolve(cls, method, config, location, date):
     def buildCacheKey(loc, date):
         return "%s:%s:%s" % (method, resolver.CacheKey(loc, date), date.strftime("%Y-%m-%d"))
     if method in TimetableResolver._resolvers:
         # Dedicated resolver, vs. calculation.
         # We assume this lookup is costly (calling a remote API, and cache it).
         resolver = TimetableResolver._resolvers[method]
         query_cache_key = buildCacheKey(location, date)
         if query_cache_key in TimetableResolver._cache:
             return TimetableResolver._cache[query_cache_key]
         try:
             cache_obj = TimetableCachedTimes.objects.get(key=query_cache_key)
             TimetableResolver._cache[query_cache_key] = (cache_obj.location_geoname, cache_obj.times)
         except TimetableCachedTimes.DoesNotExist:
             multi_day_times = resolver.Times(location, date)
             # The resolver returns a list of (location, date, timedict) tuples.
             # Obviously the location shouldn't ever change over a range, but oh well, we're storing it discretely anyway.
             for location_geoname, date, times in multi_day_times:
                 day_cache_key = buildCacheKey(location, date)
                 TimetableResolver._cache[day_cache_key] = (location_geoname, times)
                 TimetableCachedTimes.objects(key=day_cache_key).update(key=day_cache_key, location_geoname=location_geoname, times=times, upsert=True)
         return TimetableResolver._cache[query_cache_key]
     else:
         pt = PrayTimes()
         pt.setMethod(method)
         pt.adjust({"asr": config["asr"]})
         return None, pt.getTimes(date, location, 0, format="Float")
Esempio n. 3
0
def getTimes(for_date):
    prayTimes = PrayTimes()
    prayTimes.setMethod('test')
    new_settings = {
        "imsak": '10 min',
        "dhuhr": '0 min',
        "asr": 'Standard',
        "highLats": 'AngleBased',
        "maghrib": '-6 min'
    }

    offset = {
        "fajr": -2,
        "dhuhr": +5,
        "asr": +5,
        "maghrib": 0,
        "isha": -3
    }

    prayTimes.adjust(new_settings)
    prayTimes.tune(offset)
    isSummerTime = 1
    times = prayTimes.getTimes(for_date, places['berlin'], 1, dst=isSummerTime)

    return times
Esempio n. 4
0
    def Resolve(cls, method, config, location, date):
        def buildCacheKey(loc, date):
            return "%s:%s:%s" % (method, resolver.CacheKey(
                loc, date), date.strftime("%Y-%m-%d"))

        if method in TimetableResolver._resolvers:
            # Dedicated resolver, vs. calculation.
            # We assume this lookup is costly (calling a remote API, and cache it).
            resolver = TimetableResolver._resolvers[method]
            query_cache_key = buildCacheKey(location, date)
            if query_cache_key in TimetableResolver._cache:
                return TimetableResolver._cache[query_cache_key]
            try:
                cache_obj = TimetableCachedTimes.objects.get(
                    key=query_cache_key)
                TimetableResolver._cache[query_cache_key] = (
                    cache_obj.location_geoname, cache_obj.times)
            except TimetableCachedTimes.DoesNotExist:
                multi_day_times = resolver.Times(location, date)
                # The resolver returns a list of (location, date, timedict) tuples.
                # Obviously the location shouldn't ever change over a range, but oh well, we're storing it discretely anyway.
                for location_geoname, date, times in multi_day_times:
                    day_cache_key = buildCacheKey(location, date)
                    TimetableResolver._cache[day_cache_key] = (
                        location_geoname, times)
                    TimetableCachedTimes.objects(key=day_cache_key).update(
                        key=day_cache_key,
                        location_geoname=location_geoname,
                        times=times,
                        upsert=True)
            return TimetableResolver._cache[query_cache_key]
        else:
            pt = PrayTimes()
            pt.setMethod(method)
            pt.adjust({"asr": config["asr"]})
            return None, pt.getTimes(date, location, 0, format="Float")
Esempio n. 5
0
from praytimes import PrayTimes
from datetime import date, timedelta
from math import floor
from lxml import objectify
from lxml import etree

import os
import os.path
import requests
import simplejson

DEFAULT_METHOD = 'Karachi'
DEFAULT_ASR = 'Hanafi'

p = PrayTimes(DEFAULT_METHOD)
p.setMethod(DEFAULT_METHOD)
p.adjust({'asr':DEFAULT_ASR})

def timezone(lat, lng):
	r = requests.get("http://api.geonames.org/timezoneJSON?lat=%s&lng=%s&username=usmanghani" % (lat, lng))
	json = simplejson.loads(r.text)

	rawOffset = json['rawOffset']
	dstOffset = json['dstOffset']
	dst = rawOffset != dstOffset

	# r = requests.get("http://www.earthtools.org/timezone/%s/%s" % (lat, lng))
	# root = objectify.fromstring(r.text.encode('ascii'))
	
	# dst = False
	# if root.dst == 'Unknown':
Esempio n. 6
0
now = datetime.datetime.now()
strPlayFajrAzaanMP3Command = 'omxplayer -o local /home/pi/adhan/Adhan-fajr.mp3 > /dev/null 2>&1'
strPlayAzaanMP3Command = 'omxplayer -o local /home/pi/adhan/Adhan-Makkah.mp3 > /dev/null 2>&1'
strUpdateCommand = 'python /home/pi/adhan/updateAzaanTimers.py >> /home/pi/adhan/adhan.log 2>&1'
strClearLogsCommand = 'truncate -s 0 /home/pi/adhan/adhan.log 2>&1'
strJobComment = 'rpiAdhanClockJob'

#Set latitude and longitude here
#--------------------
lat = 42.288788
long = -71.551678

#Set calculation method, utcOffset and dst here
#By default system timezone will be used
#--------------------
PT.setMethod('ISNA')
utcOffset = -(time.timezone / 3600)
isDst = time.localtime().tm_isdst


#HELPER FUNCTIONS
#---------------------------------
#---------------------------------
#Function to add azaan time to cron
def addAzaanTime(strPrayerName, strPrayerTime, objCronTab, strCommand):
    job = objCronTab.new(command=strCommand, comment=strPrayerName)
    timeArr = strPrayerTime.split(':')
    hour = timeArr[0]
    min = timeArr[1]
    job.minute.on(int(min))
    job.hour.on(int(hour))
Esempio n. 7
0
now = datetime.datetime.now()
strPlayFajrAzaanMP3Command = 'omxplayer -o local /home/pi/adhan/Adhan-fajr.mp3 > /dev/null 2>&1'
strPlayAzaanMP3Command = 'omxplayer -o local /home/pi/adhan/Adhan-Makkah.mp3 > /dev/null 2>&1'
strUpdateCommand = 'python /home/pi/adhan/updateAzaanTimers.py >> /home/pi/adhan/adhan.log 2>&1'
strClearLogsCommand = 'truncate -s 0 /home/pi/adhan/adhan.log 2>&1'
strJobComment = 'rpiAdhanClockJob'

#Set latitude and longitude here
#--------------------
lat = 42.288788
long = -71.551678

#Set calculation method, utcOffset and dst here
#By default system timezone will be used
#--------------------
PT.setMethod('ISNA')
utcOffset = -(time.timezone/3600)
isDst = time.localtime().tm_isdst


#HELPER FUNCTIONS
#---------------------------------
#---------------------------------
#Function to add azaan time to cron
def addAzaanTime (strPrayerName, strPrayerTime, objCronTab, strCommand):
  job = objCronTab.new(command=strCommand,comment=strPrayerName)  
  timeArr = strPrayerTime.split(':')
  hour = timeArr[0]
  min = timeArr[1]
  job.minute.on(int(min))
  job.hour.on(int(hour))
Esempio n. 8
0
class prayerindicator:
    
    def __init__(self, timeout):
        self.load_configuration_on_start()
        self.ind = AppIndicator.Indicator.new("salatuk-indicator",
                                           get_resource_path('img/icon.svg'),
                                           AppIndicator.IndicatorCategory.APPLICATION_STATUS)
        self.ind.set_status (AppIndicator.IndicatorStatus.ACTIVE)
        self.ind.set_attention_icon("new-messages-red") #change it to uclean icon with red color

        self.win = SalatukWindow(self) #preferences window
        
        # self.audio = Audio()
        # self.audio.play_athan()
        self.menu_setup()
        self.ind.set_menu(self.menu)
        check_prayer(self, self.check_time)

        # register a periodic timer
        GLib.timeout_add_seconds(timeout, self.callback)
        
    def load_configuration_on_start(self):
        # create configparser object
        config = ConfigParser.RawConfigParser()
        cfile = get_resource_path('preferences/preferences.conf')
    
        # add your config items - see the ConfigParser docs for how to do this
        if os.path.exists(cfile):
            config.read (cfile)
            # add the settings to the structure of the file, and lets write it out...
            self.Method = config.get('preferences','method')
            self.timezone = config.get('preferences','timezone')
            self.latitude = config.get('preferences','latitude')
            self.longitude = config.get('preferences','longitude')
            self.dstValue = config.get('preferences','dstValue')
            self.athanToggle = config.get('preferences','athanToggle')
            self.set_prayer_time()

    def set_prayer_time(self):
        self.today = datetime.datetime.now()
        self.PT = PrayTimes()
        self.PT.setMethod(self.Method)
        self.check_time = self.PT.getTimes(date.today(), (float(self.latitude) , float(self.longitude)),float(self.timezone), int(self.dstValue))
        self.times = self.PT.getTimes(date.today(), (float(self.latitude) , float(self.longitude)),float(self.timezone), int(self.dstValue), '12h')

    def menu_setup(self):
        self.menu = Gtk.Menu()
        cal = calverter()
        jd = cal.gregorian_to_jd(self.today.year, self.today.month, self.today.day)
        self.date = add2menu(self.menu,text =(self.today.strftime("%A, ") + str(cal.string_jd_to_islamic(jd))))
        self.date.show()

        add2menu(self.menu)

        self.Fajr = Gtk.MenuItem("Fajr\t\t\t" + self.times['fajr'])
        self.Fajr.set_sensitive(False) #use this to enable only one prayer
        self.Fajr.show()
        self.menu.append(self.Fajr)

        self.Sunrise = Gtk.MenuItem("Sunrise\t\t" + self.times['sunrise'])
        self.Sunrise.set_sensitive(False)
        self.Sunrise.show()
        self.menu.append(self.Sunrise)

        self.Dhuhr = Gtk.MenuItem("Dhuhr\t\t\t" + self.times['dhuhr'])
        self.Dhuhr.set_sensitive(False)
        self.Dhuhr.show()
        self.menu.append(self.Dhuhr)

        self.Asr = Gtk.MenuItem("Asr\t\t\t" + self.times['asr'])
        self.Asr.set_sensitive(False)
        self.Asr.show()
        self.menu.append(self.Asr)

        self.Maghrib = Gtk.MenuItem("Maghrib\t\t" + self.times['maghrib'])
        self.Maghrib.set_sensitive(False)
        self.Maghrib.show()
        self.menu.append(self.Maghrib)

        self.Isha = Gtk.MenuItem("Isha\t\t\t" + self.times['isha'])
        self.Isha.set_sensitive(False)
        self.Isha.show()
        self.menu.append(self.Isha)

        add2menu(self.menu)

        self.preferences = add2menu(self.menu,text=('Preferences'))
        self.preferences.connect("activate", self.show_preferences) # write a uclean def
        self.preferences.show()

        self.help_menu = add2menu(self.menu,text =('Help'))
        self.help_menu.set_submenu(self.get_help_menu())
        self.help_menu.show()
	
        self.quit_item = Gtk.MenuItem("Quit Salatuk")
        self.quit_item.connect("activate", self.quit)
        self.quit_item.show()
        self.menu.append(self.quit_item)
    
    def show_preferences(self, widget):
        self.win.load_at_startup()
        self.win.show_all()

    def main(self):
        Gtk.main()

    def quit(self, widget):
        exit(0)

    def update_prayers(self):
        self.load_configuration_on_start()
        self.Fajr.set_label("Fajr\t\t\t" + self.times['fajr'])
        self.Sunrise.set_label("Sunrise\t\t" + self.times['sunrise'])
        self.Dhuhr.set_label("Dhuhr\t\t\t" + self.times['dhuhr'])
        self.Asr.set_label("Asr\t\t\t" + self.times['asr'])
        self.Maghrib.set_label("Maghrib\t\t" + self.times['maghrib'])
        self.Isha.set_label("Isha\t\t\t" + self.times['isha'])

    def update_hijri_date(self):
        cal = calverter()
        jd = cal.gregorian_to_jd(self.today.year, self.today.month, self.today.day)
        self.date.set_label(self.today.strftime("%A, ") + str(cal.string_jd_to_islamic(jd)))

    def get_help_menu(self):
    # This function was written by Lorenzo Carbonell for My_Weather_Indicator. I modified this copy to work with uClean under the terms of the GNU General Public License as published by the Free Software Foundation.
        help_menu = Gtk.Menu()
    #		
        add2menu(help_menu,text = ('In Github'),conector_event = 'activate',conector_action = lambda x: webbrowser.open('https://github.com/fo2adzz/Salatuk'))
        add2menu(help_menu,text = ('Report a bug...'),conector_event = 'activate',conector_action = lambda x: webbrowser.open('https://github.com/fo2adzz/Salatuk/issues'))
        add2menu(help_menu)
        web = add2menu(help_menu,text = ('Homepage'),conector_event = 'activate',conector_action = lambda x: webbrowser.open('http://www.fo2adzz.com'))
        twitter = add2menu(help_menu,text = ('Follow us in Twitter'),conector_event = 'activate',conector_action = lambda x: webbrowser.open('https://twitter.com/fo2adzz'))
        googleplus = add2menu(help_menu,text = ('Follow us in Google+'),conector_event = 'activate',conector_action = lambda x: webbrowser.open('https://plus.google.com/u/0/112984301584620244860/posts'))
        facebook = add2menu(help_menu,text = ('Follow us in Facebook'),conector_event = 'activate',conector_action = lambda x: webbrowser.open('https://www.facebook.com/fouad.hassouneh'))	
#		add2menu(help_menu,text = _('About'),conector_event = 'activate',conector_action = self.menu_about_response)	
        web.set_image(Gtk.Image.new_from_file(get_resource_path('img/social/fo2adzz.png')))
        web.set_always_show_image(True)
        twitter.set_image(Gtk.Image.new_from_file(get_resource_path('img/social/twitter.png')))
        twitter.set_always_show_image(True)
        googleplus.set_image(Gtk.Image.new_from_file(get_resource_path('img/social/googleplus.png')))
        googleplus.set_always_show_image(True)
        facebook.set_image(Gtk.Image.new_from_file(get_resource_path('img/social/facebook.png')))
        facebook.set_always_show_image(True)
    #
        help_menu.show()
        return help_menu
    #

    # update all the labels every timeout seconds
    def callback(self):
        self.update_hijri_date()
        self.update_prayers()
        check_prayer(self, self.check_time)
        return True
Esempio n. 9
0
from praytimes import PrayTimes

p = PrayTimes("Karachi")
p.setMethod("Karachi")
p.adjust({"asr": "Hanafi"})

import datetime

times = p.getTimes(datetime.date.today(), (47.6097, -122.3331), -8, True)

from pprint import pprint

pprint(times)

from lxml import objectify
from lxml import etree
from requests import get


r = get("http://www.earthtools.org/timezone/47.6097/-122.3331")

root = objectify.fromstring(r.text.encode("ascii"))

# root = objectify.fromstring(
# '''<?xml version="1.0" encoding="ISO-8859-1" ?>
# <timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone-1.1.xsd">
# <version>1.1</version>
# <location>
# <latitude>47.6097</latitude>
# <longitude>-122.3331</longitude>
# </location>
Esempio n. 10
0
assetSholat = "curl 'http://localhost/api/v1/assets/control/asset&1740a9e1daf24a2cb58f9e08a9546703'"
strPlayFajrAzaanMP3Command = assetSholat + '&& omxplayer -o local /home/pi/adhan/Adhan-fajr.mp3 > /dev/null 2>&1'
strPlayAzaanMP3Command = assetSholat + '&& omxplayer -o local /home/pi/adhan/Adhan-Makkah.mp3 > /dev/null 2>&1'
strUpdateCommand = 'python /home/pi/adhan/updateAzaanTimers.py >> /home/pi/adhan/adhan.log 2>&1'
strClearLogsCommand = 'truncate -s 0 /home/pi/adhan/adhan.log 2>&1'
strJobComment = 'rpiAdhanClockJob'

#Set latitude and longitude here
#--------------------
lat = -6.21462
long = 106.84513

#Set calculation method, utcOffset and dst here
#By default system timezone will be used
#--------------------
PT.setMethod('Makkah')
utcOffset = -(time.timezone / 3600)
isDst = time.localtime().tm_isdst


#HELPER FUNCTIONS
#---------------------------------
#---------------------------------
#Function to add azaan time to cron
def addAzaanTime(strPrayerName, strPrayerTime, objCronTab, strCommand):
    job = objCronTab.new(command=strCommand, comment=strPrayerName)
    timeArr = strPrayerTime.split(':')
    hour = timeArr[0]
    min = timeArr[1]
    job.minute.on(int(min))
    job.hour.on(int(hour))
Esempio n. 11
0
from praytimes import PrayTimes

p = PrayTimes('Karachi')
p.setMethod('Karachi')
p.adjust({'asr':'Hanafi'})

import datetime
times = p.getTimes(datetime.date.today(), (47.6097, -122.3331), -8, True)

from pprint import pprint

pprint(times)
Esempio n. 12
0
strPlayFajrAzaanMP3Command = 'curl --data "p0=play&p1=mixer&p2=volume&p3=30&p4=playlist&p5=play&p6=/home/pi/adhan/mp3/Adhan-fajr.mp3&player=00:00:00:18:70:c8&start=0" http://localhost:9002/status.html'
strPlayAzaanMP3Command = 'curl --data "p0=play&p1=mixer&p2=volume&p3=30&p4=playlist&p5=play&p6=/home/pi/adhan/mp3/Adhan-Makkah.mp3&player=00:00:00:18:70:c8&start=0" http://localhost:9002/status.html'

strUpdateCommand = 'python /home/pi/adhan/updateAzaanTimers.py >> /home/pi/adhan/adhan.log 2>&1'
strClearLogsCommand = 'truncate -s 0 /home/pi/adhan/adhan.log 2>&1'
strJobComment = 'rpiAdhanClockJob'

# Set latitude and longitude here
#--------------------
lat = 42.288788
long = -71.551678

# Set calculation method, utcOffset and dst here
# By default system timezone will be used
#--------------------
PT.setMethod('Diyanet')
utcOffset = -(time.timezone / 3600)
isDst = time.localtime().tm_isdst


# HELPER FUNCTIONS
# ---------------------------------
# ---------------------------------
# Function to add azaan time to cron
def addAzaanTime(strPrayerName, strPrayerTime, objCronTab, strCommand):
    job = objCronTab.new(command=strCommand, comment=strPrayerName)
    timeArr = strPrayerTime.split(':')
    hour = timeArr[0]
    min = timeArr[1]
    job.minute.on(int(min))
    job.hour.on(int(hour))
Esempio n. 13
0
now = datetime.datetime.now()
strPlayFajrAzaanMP3Command = 'omxplayer -o local /home/pi/vesselazan/audio/Adhan-fajr.mp3 > /dev/null 2>&1'
strPlayAzaanMP3Command = 'sudo python /home/pi/vesselazan/play/azan.py'
strUpdateCommand = 'python /home/pi/vesselazan/updateAzaanTimers.py >> /home/pi/vesselazan/adhan.log 2>&1'
strClearLogsCommand = 'truncate -s 0 /home/pi/vesselazan/adhan.log 2>&1'
strJobComment = 'VesselAzanClockJob'

#Set latitude and longitude here
#--------------------
lat = 31.261531
long = 32.305913

#Set calculation method, utcOffset and dst here
#By default system timezone will be used
#--------------------
PT.setMethod('Egypt')
utcOffset = -(time.timezone / 3600)
isDst = time.localtime().tm_isdst


#HELPER FUNCTIONS
#---------------------------------
#---------------------------------
#Function to add azaan time to cron
def addAzaanTime(strPrayerName, strPrayerTime, objCronTab, strCommand):
    job = objCronTab.new(command=strCommand, comment=strPrayerName)
    timeArr = strPrayerTime.split(':')
    hour = timeArr[0]
    min = timeArr[1]
    job.minute.on(int(min))
    job.hour.on(int(hour))
Esempio n. 14
0
#Parse arguments
parser = parseArgs()
args = parser.parse_args()
#Merge args with saved values if any
lat, lng, method, fajr_azaan_vol, azaan_vol = mergeArgs(args)
print(lat, lng, method, fajr_azaan_vol, azaan_vol)
#Complain if any mandatory value is missing
if not lat or not lng or not method:
    parser.print_usage()
    sys.exit(1)

#Set calculation method, utcOffset and dst here
#By default system timezone will be used
#--------------------
PT.setMethod(method)
utcOffset = -(time.timezone/3600)
isDst = time.localtime().tm_isdst

now = datetime.datetime.now()
strPlayFajrAzaanMP3Command = 'omxplayer --vol {} -o local {}/Adhan-fajr.mp3 > /dev/null 2>&1'.format(fajr_azaan_vol, root_dir)
strPlayAzaanMP3Command = 'omxplayer --vol {} -o local {}/Adhan-Madinah.mp3 > /dev/null 2>&1'.format(azaan_vol, root_dir)
strUpdateCommand = 'python {}/updateAzaanTimers.py >> {}/adhan.log 2>&1'.format(root_dir, root_dir)
strClearLogsCommand = 'truncate -s 0 {}/adhan.log 2>&1'.format(root_dir)
strJobComment = 'rpiAdhanClockJob'

# Remove existing jobs created by this script
system_cron.remove_all(comment=strJobComment)

# Calculate prayer times
times = PT.getTimes((now.year,now.month,now.day), (lat, lng), utcOffset, isDst)