{"id":21420336,"url":"https://github.com/muhammed770/calendar-prayer-time-api-google-script-","last_synced_at":"2025-10-08T16:05:09.410Z","repository":{"id":246094528,"uuid":"820079685","full_name":"Muhammed770/calendar-prayer-time-api-google-script-","owner":"Muhammed770","description":"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.","archived":false,"fork":false,"pushed_at":"2024-06-26T17:58:36.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-08T16:03:14.081Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Muhammed770.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-25T18:53:56.000Z","updated_at":"2024-06-26T17:58:40.000Z","dependencies_parsed_at":"2024-06-25T20:55:31.902Z","dependency_job_id":"1567b6de-4738-4b3e-93c3-5c6f1a2aa485","html_url":"https://github.com/Muhammed770/calendar-prayer-time-api-google-script-","commit_stats":null,"previous_names":["muhammed770/calendarprayertimeupdate-googlescript"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Muhammed770/calendar-prayer-time-api-google-script-","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muhammed770%2Fcalendar-prayer-time-api-google-script-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muhammed770%2Fcalendar-prayer-time-api-google-script-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muhammed770%2Fcalendar-prayer-time-api-google-script-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muhammed770%2Fcalendar-prayer-time-api-google-script-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Muhammed770","download_url":"https://codeload.github.com/Muhammed770/calendar-prayer-time-api-google-script-/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muhammed770%2Fcalendar-prayer-time-api-google-script-/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278972327,"owners_count":26078019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T20:15:08.035Z","updated_at":"2025-10-08T16:05:09.391Z","avatar_url":"https://github.com/Muhammed770.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Calendar Prayer Time Update - Google Script\n\nThis 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.\n\n## Getting Started\n\n### Prerequisites\n\nTo use this script, you'll need:\n\n- **Google Account**: To access Google Calendar and Google Apps Script.\n- **Calendar ID**: Obtain your Google Calendar ID where you want to add the prayer times.\n- **City and Country**: Update the `city` and `country` variables in the script to match your location.\n\n### Setup Instructions\n\n1. **Google Calendar Setup**:\n   - Create a new Google Calendar if you haven't already.\n   - Note down the Calendar ID (`calenderId` in the script) which can be found in Calendar settings.\n\n2. **Google Apps Script Setup**:\n   - Open Google Apps Script ([script.google.com](https://script.google.com)).\n   - Create a new script file and paste the provided `updatePrayerTime` function into it.\n\n3. **Configure Trigger**:\n   - Set up a trigger to execute the `updatePrayerTime` function daily.\n     - In the Google Apps Script editor, go to **Triggers** (clock icon) \u003e **Add Trigger**.\n     - Choose `updatePrayerTime` as the function to run.\n     - Set event source to Time-driven, and select day timer with specific time.\n\n4. **Aladhan API Method**:\n   - The script fetches prayer times from the Aladhan API using the University of Islamic Sciences, Karachi method. You can explore other methods by visiting [Aladhan API Methods](http://api.aladhan.com/v1/methods).\n\n### Function Explanation\n\nThe `updatePrayerTime` function does the following:\n\n- Fetches current prayer times using the Aladhan API based on your location.\n- Calculates the start and end times for each prayer, adjusting them as needed.\n- Deletes existing events for the same prayer on the current day to prevent duplicates.\n- Creates a new recurring event series for each prayer time in your Google Calendar.\n\n```javascript\nfunction updatePrayerTime() {\n  const calenderId = 'mail.muhammed2002@gmail.com';\n  const city = 'Kerala';\n  const country = 'India';\n  const method = 1;\n  const url = `http://api.aladhan.com/v1/timingsByCity?city=${city}\u0026country=${country}\u0026method=${method}`;\n\n  const response = UrlFetchApp.fetch(url);\n  const data = JSON.parse(response.getContentText());\n  console.log(\"data = \",data);\n  const timings = data.data.timings;\n  const calendar = CalendarApp.getCalendarById(calenderId);\n\n  function addOrUpdateEvent(summary,timeStr) {\n    const date = new Date();\n    const [hours,minutes] = timeStr.split(':').map(Number);\n    let startTime;\n    if(summary == 'Fajr prayer') {\n      const sunriseTime = new Date(date.getFullYear(),date.getMonth(),date.getDate(),hours,minutes);\n      startTime = new Date(sunriseTime.getTime() - 50 * 60000);\n    } else if (summary == 'Maghrib prayer'){\n      startTime = new Date(date.getFullYear(),date.getMonth(),date.getDate(),hours,minutes);\n    } else {\n      startTime = new Date(date.getFullYear(),date.getMonth(),date.getDate(),hours,minutes);\n      startTime = new Date(startTime.getTime()+ 10 * 60000);\n    }\n    const endTime = new Date(startTime.getTime()+ 20 * 60000) // 20 * 60 seconds * 1000 milliseconds\n    console.log(summary,hours,minutes);\n\n\n    // Check for existing events with the same summary\n    const events = calendar.getEventsForDay(startTime, { search: summary });\n    if (events.length \u003e 0) {\n      const event = events[0];\n      if (event.isRecurringEvent()) {\n        const series = event.getEventSeries();\n        series.deleteEventSeries();\n      } else {\n        event.deleteEvent();\n      }\n    }\n\n    // Create a new recurring event\n    const recurrence = CalendarApp.newRecurrence().addDailyRule();\n    calendar.createEventSeries(summary, startTime, endTime, recurrence);\n\n  }\n  addOrUpdateEvent('Fajr prayer',timings.Sunrise);\n  addOrUpdateEvent('Dhuhr prayer', timings.Dhuhr);\n  addOrUpdateEvent('Asr prayer', timings.Asr);\n  addOrUpdateEvent('Maghrib prayer', timings.Maghrib);\n  addOrUpdateEvent('Isha prayer', timings.Isha);\n}\n```\n\n### License\n\nThis project is licensed under the MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammed770%2Fcalendar-prayer-time-api-google-script-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuhammed770%2Fcalendar-prayer-time-api-google-script-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammed770%2Fcalendar-prayer-time-api-google-script-/lists"}