Пример #1
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")
Пример #2
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
Пример #3
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
Пример #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")
Пример #5
0
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':
	# 	dst = False
Пример #6
0
#!/usr/bin/env python

from praytimes import PrayTimes
from gi.repository import Notify
from datetime import date
import time

praytime = PrayTimes()

# tune and adjustment based on shalat.landak.com
praytime.adjust({
  'fajr': 20,
  'dhuhr': '2 min',
  'maghrib': 1,
  'isha': 18
})

praytime.tune({
  'fajr': 2,
  'sunrise': -2,
  'asr': 2,
  'maghrib': 2,
  'isha': 2
})

translasi = {
    'imsak': 'Imsak',
    'fajr': 'Subuh',
    'dhuhr': 'Duhur',
    'asr': 'Ashar',
    'maghrib': 'Maghrib',
Пример #7
0
def generate(lat, lon, startdate, days, method, option):
    PT = PrayTimes(method)
    if option == '+8':
        PT.adjust({
            'imsak': '10 min',
            'fajr': 17.8,
            'dhuhr': '2 min',
            'asr': '1.03',
            'maghrib': 1.5,
            'isha': 18.7
        })
    else:
        PT.adjust({
            'imsak': '10 min',
            'fajr': 19.4,
            'dhuhr': '2 min',
            'asr': '1.03',
            'maghrib': 1.8,
            'isha': 18.7
        })
    #result = []

    c = Calendar()

    formatDate = '%Y-%m-%d'
    formatDatetime = '%Y-%m-%d %H:%M:%S'
    hourDelta = 7
    secondDelta = 5

    mapTime = {
        'Imsak': 'imsak',
        'Subuh': 'fajr',
        'Dzuhur': 'dhuhr',
        'Asar': 'asr',
        'Maghrib': 'maghrib',
        'Isya': 'isha',
    }

    dte = datetime.strptime(startdate, formatDate)
    for i in range(days):
        today = dte + timedelta(days=i)
        times = PT.getTimes(today.date(), [float(lat), float(lon)], +7)
        '''
        result.append({
            'imsak': times['imsak'],
            'subuh': times['fajr'],
            'dzuhur': times['dhuhr'],
            'asar': times['asr'],
            'maghrib': times['maghrib'],
            'isya': times['isha']
        })
        '''

        todayTimeStr = today.strftime(formatDate)

        for name, key in mapTime.items():
            e = setEvent(times, name, key, todayTimeStr, hourDelta,
                         secondDelta, formatDatetime)
            c.events.add(e)

    with open('jadwal_imsakiyah_%s_%s.ics' % (lat, lon), 'w') as f:
        f.write(str(c))
Пример #8
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>
Пример #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)
Пример #10
0
def generate(lat, lon, startdate, days):
    PT = PrayTimes('Makkah')
    PT.adjust({'wkt':'10 min', 'fajr':17.8, 'dhuhr':'2 min', 'asr':'1.03', 'maghrib':1.5,'isha':18.7})
    #result = []

    c = Calendar() 
    
    dte = datetime.strptime(startdate, '%Y-%m-%d')    
    for i in range(days):
        today = dte + timedelta(days=i)
        times = PT.getTimes(today.date(), [float(lat),float(lon)],+7)
        '''
        result.append({
            'imsak': times['imsak'],
            'subuh': times['fajr'],
            'dzuhur': times['dhuhr'],
            'asar': times['asr'],
            'maghrib': times['maghrib'],
            'isya': times['isha']
        })
        '''
        
        e = Event()
        e.name = 'Imsak'
        wkt = datetime.strptime(today.strftime('%Y-%m-%d')+' '+times['imsak']+':00', '%Y-%m-%d %H:%M:%S')
        wkt = wkt - timedelta(hours=7)
        e.begin = wkt.strftime('%Y-%m-%d %H:%M:%S')
        e.end = (wkt+timedelta(seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
        c.events.add(e)
        
        e = Event()
        e.name = 'Subuh'
        wkt = datetime.strptime(today.strftime('%Y-%m-%d')+' '+times['fajr']+':00', '%Y-%m-%d %H:%M:%S')
        wkt = wkt - timedelta(hours=7)
        e.begin = wkt.strftime('%Y-%m-%d %H:%M:%S')
        e.end = (wkt+timedelta(seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
        c.events.add(e)
        
        e = Event()
        e.name = 'Dzuhur'
        wkt = datetime.strptime(today.strftime('%Y-%m-%d')+' '+times['dhuhr']+':00', '%Y-%m-%d %H:%M:%S')
        wkt = wkt - timedelta(hours=7)
        e.begin = wkt.strftime('%Y-%m-%d %H:%M:%S')
        e.end = (wkt+timedelta(seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
        c.events.add(e)
        
        e = Event()
        e.name = 'Asar'
        wkt = datetime.strptime(today.strftime('%Y-%m-%d')+' '+times['asr']+':00', '%Y-%m-%d %H:%M:%S')
        wkt = wkt - timedelta(hours=7)
        e.begin = wkt.strftime('%Y-%m-%d %H:%M:%S')
        e.end = (wkt+timedelta(seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
        c.events.add(e)
        
        e = Event()
        e.name = 'Maghrib'
        wkt = datetime.strptime(today.strftime('%Y-%m-%d')+' '+times['maghrib']+':00', '%Y-%m-%d %H:%M:%S')
        wkt = wkt - timedelta(hours=7)
        e.begin = wkt.strftime('%Y-%m-%d %H:%M:%S')
        e.end = (wkt+timedelta(seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
        c.events.add(e)
        
        e = Event()
        e.name = 'Isya'
        wkt = datetime.strptime(today.strftime('%Y-%m-%d')+' '+times['isha']+':00', '%Y-%m-%d %H:%M:%S')
        wkt = wkt - timedelta(hours=7)
        e.begin = wkt.strftime('%Y-%m-%d %H:%M:%S')
        e.end = (wkt+timedelta(seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
        c.events.add(e)
        


    with open('jadwal_imsakiyah_%s_%s.ics' % (lat, lon), 'w') as f:
        f.write(str(c))