Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This repository contains a Google Apps Script that updates prayer times in a Google Calendar based on data fetched from an external API. The script retrieves daily prayer timings for a specified location using the Aladhan API.

NotificationsYou must be signed in to change notification settings

Muhammed770/calendar-prayer-time-api-google-script-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

This Google Apps Script automates the update of prayer times in your Google Calendar using data fetched from the Aladhan API. The script utilizes the University of Islamic Sciences, Karachi method for calculating prayer times.

Getting Started

Prerequisites

To use this script, you'll need:

  • Google Account: To access Google Calendar and Google Apps Script.
  • Calendar ID: Obtain your Google Calendar ID where you want to add the prayer times.
  • City and Country: Update thecity andcountry variables in the script to match your location.

Setup Instructions

  1. Google Calendar Setup:

    • Create a new Google Calendar if you haven't already.
    • Note down the Calendar ID (calenderId in the script) which can be found in Calendar settings.
  2. Google Apps Script Setup:

    • Open Google Apps Script (script.google.com).
    • Create a new script file and paste the providedupdatePrayerTime function into it.
  3. Configure Trigger:

    • Set up a trigger to execute theupdatePrayerTime function daily.
      • In the Google Apps Script editor, go toTriggers (clock icon) >Add Trigger.
      • ChooseupdatePrayerTime as the function to run.
      • Set event source to Time-driven, and select day timer with specific time.
  4. Aladhan API Method:

    • The script fetches prayer times from the Aladhan API using the University of Islamic Sciences, Karachi method. You can explore other methods by visitingAladhan API Methods.

Function Explanation

TheupdatePrayerTime function does the following:

  • Fetches current prayer times using the Aladhan API based on your location.
  • Calculates the start and end times for each prayer, adjusting them as needed.
  • Deletes existing events for the same prayer on the current day to prevent duplicates.
  • Creates a new recurring event series for each prayer time in your Google Calendar.
functionupdatePrayerTime(){constcalenderId='mail.muhammed2002@gmail.com';constcity='Kerala';constcountry='India';constmethod=1;consturl=`http://api.aladhan.com/v1/timingsByCity?city=${city}&country=${country}&method=${method}`;constresponse=UrlFetchApp.fetch(url);constdata=JSON.parse(response.getContentText());console.log("data = ",data);consttimings=data.data.timings;constcalendar=CalendarApp.getCalendarById(calenderId);functionaddOrUpdateEvent(summary,timeStr){constdate=newDate();const[hours,minutes]=timeStr.split(':').map(Number);letstartTime;if(summary=='Fajr prayer'){constsunriseTime=newDate(date.getFullYear(),date.getMonth(),date.getDate(),hours,minutes);startTime=newDate(sunriseTime.getTime()-50*60000);}elseif(summary=='Maghrib prayer'){startTime=newDate(date.getFullYear(),date.getMonth(),date.getDate(),hours,minutes);}else{startTime=newDate(date.getFullYear(),date.getMonth(),date.getDate(),hours,minutes);startTime=newDate(startTime.getTime()+10*60000);}constendTime=newDate(startTime.getTime()+20*60000)// 20 * 60 seconds * 1000 millisecondsconsole.log(summary,hours,minutes);// Check for existing events with the same summaryconstevents=calendar.getEventsForDay(startTime,{search:summary});if(events.length>0){constevent=events[0];if(event.isRecurringEvent()){constseries=event.getEventSeries();series.deleteEventSeries();}else{event.deleteEvent();}}// Create a new recurring eventconstrecurrence=CalendarApp.newRecurrence().addDailyRule();calendar.createEventSeries(summary,startTime,endTime,recurrence);}addOrUpdateEvent('Fajr prayer',timings.Sunrise);addOrUpdateEvent('Dhuhr prayer',timings.Dhuhr);addOrUpdateEvent('Asr prayer',timings.Asr);addOrUpdateEvent('Maghrib prayer',timings.Maghrib);addOrUpdateEvent('Isha prayer',timings.Isha);}

License

This project is licensed under the MIT License

About

This repository contains a Google Apps Script that updates prayer times in a Google Calendar based on data fetched from an external API. The script retrieves daily prayer timings for a specified location using the Aladhan API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp