Reference - Mawaqit Python Wrapper

Skip to content

# Reference

## `Mawaqit`

Source code in `MawaqitAPI\mawaqit.py`

      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    class Mawaqit():
        def __init__(self, mosque_id, new_data=True, **kwargs):

            """
            Args:
                mosque_id (str): The mosque id of the mosque you want to get the data from. example: "mosque_id" in https://www.mawaqit.net/en/mosque_id
                new_data (bool): *OPTIONAL* If set to True, the data will be scraped from the website. If set to False, the data will be loaded from the file (default data.json).
                file_name (str): *OPTIONAL* The name of the file to save the data in. Defaults to data.json.
            """
            self.mosque_id = mosque_id
            self.crawler = Crawler(mosque_id)
            self.new_data = new_data
            self.file_name = kwargs.get("file_name", "data.json")
            if self.new_data:
                self.local_mawaqit = LocalMawaqit(None)
            else:
                self.local_mawaqit = LocalMawaqit(self.file_name)

            self.helper = Helper()

        # create prayers list so user can use it to get prayer times
        def get_prayer_times(self):
            """
            Returns:
                dict: A dictionary with the prayer times. Fajr, Dhuhr, Asr, Maghrib, Isha
            """
            if self.new_data:
                return self.crawler.get_prayer_times()
            else:
                return self.local_mawaqit.get_prayer_times()

        def get_prayer_time(self, prayer):

            """
            Args:
                prayer (str): The prayer you want to get the time of. Can be fajr, dhuhr, asr, maghrib or isha.

            Returns:
                str: The time of the prayer.
            """

            if self.new_data:
                return self.crawler.get_prayer_time(prayer)
            else:
                return self.local_mawaqit.get_prayer_time(prayer)

        def get_shurooq(self):

            """
            Returns:
                str: The time of shurooq.
            """

            if self.new_data:
                return self.crawler.get_shurooq()
            else:
                return self.local_mawaqit.get_shurooq()

        def get_jumua(self):

            """
            Returns:
                str: The time of jumua.
            """

            if self.new_data:
                return self.crawler.get_jumua()
            else:
                return self.local_mawaqit.get_jumua()

        def get_data(self):

            """
            Returns:
                json: The data of the mosque in json format, all available data from the mawaqit website.
            """

            if self.new_data:
                return self.crawler.get_data()
            else:
                return self.local_mawaqit.get_data()

        def to_timestamp(self, date_string):

            """
            Args:
                date_string (str): The date you want to convert to a timestamp.

            Returns:
                int: The timestamp of the date.
            """

            return self.helper.get_timestamp(date_string)

        def get_prayer_times_by_date(self, date_string):

            """
            Args:
                date_string (str): The date you want to get the prayer times of, format: dd-mm-yyyy.

            Returns:
                dict: The prayer times of the date. Fajr, Shurooq, Dhuhr, Asr, Maghrib, Isha.
            """

            if self.new_data:
                return self.crawler.get_prayer_times_by_date(date_string)
            else:
                return self.local_mawaqit.get_prayer_times_by_date(date_string)

        def time_left(self, prayer):

            """
            Args:
                prayer (str): The prayer you want to get the time left of. Can be fajr, dhuhr, asr, maghrib or isha. In the same day.

            Returns:
                int: The time left until the prayer in seconds.
            """

            if self.new_data:
                data = self.crawler.get_prayer_times()
                return self.helper.time_left(data[prayer])
            else:
                data = self.local_mawaqit.get_prayer_times()
                return self.helper.time_left(data[prayer])

        def save_data_to_file(self, data):

            """
            Args:
                data (str): The data you want to save to a file.
            """

            self.helper.save_data_to_file(data, self.file_name)

        def get_next_prayer(self):

            """
            Returns:
                str: The next prayer.
            """

            if self.new_data:
                return self.helper.get_next_prayer(self.crawler.get_prayer_times())
            else:
                return self.helper.get_next_prayer(self.local_mawaqit.get_prayer_times())

### `__init__(mosque_id, new_data=True, **kwargs)`

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`mosque_id` | `str` | The mosque id of the mosque you want to get the data from. example: "mosque_id" in https://www.mawaqit.net/en/mosque_id | required
`new_data` | `bool` | OPTIONAL If set to True, the data will be scraped from the website. If set to False, the data will be loaded from the file (default data.json). | `True`
`file_name` | `str` | OPTIONAL The name of the file to save the data in. Defaults to data.json. | required

Source code in `MawaqitAPI\mawaqit.py`

     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    def __init__(self, mosque_id, new_data=True, **kwargs):

        """
        Args:
            mosque_id (str): The mosque id of the mosque you want to get the data from. example: "mosque_id" in https://www.mawaqit.net/en/mosque_id
            new_data (bool): *OPTIONAL* If set to True, the data will be scraped from the website. If set to False, the data will be loaded from the file (default data.json).
            file_name (str): *OPTIONAL* The name of the file to save the data in. Defaults to data.json.
        """
        self.mosque_id = mosque_id
        self.crawler = Crawler(mosque_id)
        self.new_data = new_data
        self.file_name = kwargs.get("file_name", "data.json")
        if self.new_data:
            self.local_mawaqit = LocalMawaqit(None)
        else:
            self.local_mawaqit = LocalMawaqit(self.file_name)

        self.helper = Helper()

### `get_data()`

Returns:

Name | Type | Description
--- | --- | ---
`json` |  | The data of the mosque in json format, all available data from the mawaqit website.

Source code in `MawaqitAPI\mawaqit.py`

    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    def get_data(self):

        """
        Returns:
            json: The data of the mosque in json format, all available data from the mawaqit website.
        """

        if self.new_data:
            return self.crawler.get_data()
        else:
            return self.local_mawaqit.get_data()

### `get_jumua()`

Returns:

Name | Type | Description
--- | --- | ---
`str` |  | The time of jumua.

Source code in `MawaqitAPI\mawaqit.py`

    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    def get_jumua(self):

        """
        Returns:
            str: The time of jumua.
        """

        if self.new_data:
            return self.crawler.get_jumua()
        else:
            return self.local_mawaqit.get_jumua()

### `get_next_prayer()`

Returns:

Name | Type | Description
--- | --- | ---
`str` |  | The next prayer.

Source code in `MawaqitAPI\mawaqit.py`

    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    def get_next_prayer(self):

        """
        Returns:
            str: The next prayer.
        """

        if self.new_data:
            return self.helper.get_next_prayer(self.crawler.get_prayer_times())
        else:
            return self.helper.get_next_prayer(self.local_mawaqit.get_prayer_times())

### `get_prayer_time(prayer)`

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`prayer` | `str` | The prayer you want to get the time of. Can be fajr, dhuhr, asr, maghrib or isha. | required

Returns:

Name | Type | Description
--- | --- | ---
`str` |  | The time of the prayer.

Source code in `MawaqitAPI\mawaqit.py`

    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    def get_prayer_time(self, prayer):

        """
        Args:
            prayer (str): The prayer you want to get the time of. Can be fajr, dhuhr, asr, maghrib or isha.

        Returns:
            str: The time of the prayer.
        """

        if self.new_data:
            return self.crawler.get_prayer_time(prayer)
        else:
            return self.local_mawaqit.get_prayer_time(prayer)

### `get_prayer_times()`

Returns:

Name | Type | Description
--- | --- | ---
`dict` |  | A dictionary with the prayer times. Fajr, Dhuhr, Asr, Maghrib, Isha

Source code in `MawaqitAPI\mawaqit.py`

    26
    27
    28
    29
    30
    31
    32
    33
    34
    def get_prayer_times(self):
        """
        Returns:
            dict: A dictionary with the prayer times. Fajr, Dhuhr, Asr, Maghrib, Isha
        """
        if self.new_data:
            return self.crawler.get_prayer_times()
        else:
            return self.local_mawaqit.get_prayer_times()

### `get_prayer_times_by_date(date_string)`

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`date_string` | `str` | The date you want to get the prayer times of, format: dd-mm-yyyy. | required

Returns:

Name | Type | Description
--- | --- | ---
`dict` |  | The prayer times of the date. Fajr, Shurooq, Dhuhr, Asr, Maghrib, Isha.

Source code in `MawaqitAPI\mawaqit.py`

     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    def get_prayer_times_by_date(self, date_string):

        """
        Args:
            date_string (str): The date you want to get the prayer times of, format: dd-mm-yyyy.

        Returns:
            dict: The prayer times of the date. Fajr, Shurooq, Dhuhr, Asr, Maghrib, Isha.
        """

        if self.new_data:
            return self.crawler.get_prayer_times_by_date(date_string)
        else:
            return self.local_mawaqit.get_prayer_times_by_date(date_string)

### `get_shurooq()`

Returns:

Name | Type | Description
--- | --- | ---
`str` |  | The time of shurooq.

Source code in `MawaqitAPI\mawaqit.py`

    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    def get_shurooq(self):

        """
        Returns:
            str: The time of shurooq.
        """

        if self.new_data:
            return self.crawler.get_shurooq()
        else:
            return self.local_mawaqit.get_shurooq()

### `save_data_to_file(data)`

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`data` | `str` | The data you want to save to a file. | required

Source code in `MawaqitAPI\mawaqit.py`

    131
    132
    133
    134
    135
    136
    137
    138
    def save_data_to_file(self, data):

        """
        Args:
            data (str): The data you want to save to a file.
        """

        self.helper.save_data_to_file(data, self.file_name)

### `time_left(prayer)`

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`prayer` | `str` | The prayer you want to get the time left of. Can be fajr, dhuhr, asr, maghrib or isha. In the same day. | required

Returns:

Name | Type | Description
--- | --- | ---
`int` |  | The time left until the prayer in seconds.

Source code in `MawaqitAPI\mawaqit.py`

    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    def time_left(self, prayer):

        """
        Args:
            prayer (str): The prayer you want to get the time left of. Can be fajr, dhuhr, asr, maghrib or isha. In the same day.

        Returns:
            int: The time left until the prayer in seconds.
        """

        if self.new_data:
            data = self.crawler.get_prayer_times()
            return self.helper.time_left(data[prayer])
        else:
            data = self.local_mawaqit.get_prayer_times()
            return self.helper.time_left(data[prayer])

### `to_timestamp(date_string)`

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`date_string` | `str` | The date you want to convert to a timestamp. | required

Returns:

Name | Type | Description
--- | --- | ---
`int` |  | The timestamp of the date.

Source code in `MawaqitAPI\mawaqit.py`

    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    def to_timestamp(self, date_string):

        """
        Args:
            date_string (str): The date you want to convert to a timestamp.

        Returns:
            int: The timestamp of the date.
        """

        return self.helper.get_timestamp(date_string)

## `LocalMawaqit`

Source code in `MawaqitAPI\localMawaqit.py`

     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    class LocalMawaqit():
        def __init__(self, fileName):
            """
            Class to interact with the loaded data, without having to scrape the website.
            Args:
                fileName (str): The name of the file that contains the data.

            """
            if fileName == None:
                #ignore this class

                return

            self.fileName = fileName
            self.helper = Helper()
            self.data = self.helper.load_data_from_file(self.fileName)
            self.day, self.month, self.year = self.helper.date_to_dd_mm_yyyy(self.helper.current_date())
            self.day = int(self.day)
            self.month = int(self.month)

        def get_prayer_times(self):
            """
            Returns:
                dict: A dictionary with the prayer times.
            """
            return self.helper.format_prayer_log(self.data["calendar"][self.month-1][str(self.day)])

        def get_prayer_time(self, prayer):
            """
            Args:
                prayer (str): The prayer you want to get the time of. Can be fajr, dhuhr, asr, maghrib or isha.

            Returns:
                str: The time of the prayer.
            """

            if prayer == "fajr":
                return self.data["calendar"][self.month-1][str(self.day)][0]
            elif prayer == "shurooq":
                return self.data["calendar"][self.month-1][str(self.day)][1]
            elif prayer == "dhuhr":
                return self.data["calendar"][self.month-1][str(self.day)][2]
            elif prayer == "asr":
                return self.data["calendar"][self.month-1][str(self.day)][3]
            elif prayer == "maghrib":
                return self.data["calendar"][self.month-1][str(self.day)][4]
            elif prayer == "isha":
                return self.data["calendar"][self.month-1][str(self.day)][5]
            else:
                return "Invalid prayer"

        def get_shurooq(self):
            """
            Returns:
                str: The time of shurooq.
            """
            return self.data["calendar"][self.month-1][str(self.day)][1]

        def get_jumua(self):
            """
            Returns:
                str: The time of jumua.
            """
            return self.data["calendar"][self.month-1][str(self.day)][2]

        def get_prayer_times_by_date(self, date_string):
            """
            Args:
                date_string (str): The date you want to get the prayer times of, format: dd-mm-yyyy.

            Returns:
                dict: The prayer times of the date.
            """
            day, month, year = self.helper.date_to_dd_mm_yyyy(date_string)
            day = int(day)
            month = int(month)
            return self.helper.format_prayer_log(self.data["calendar"][month-1][str(day)])

        def get_data(self):
            return self.data

### `__init__(fileName)`

Class to interact with the loaded data, without having to scrape the website.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`fileName` | `str` | The name of the file that contains the data. | required

Source code in `MawaqitAPI\localMawaqit.py`

     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    def __init__(self, fileName):
        """
        Class to interact with the loaded data, without having to scrape the website.
        Args:
            fileName (str): The name of the file that contains the data.

        """
        if fileName == None:
            #ignore this class

            return

        self.fileName = fileName
        self.helper = Helper()
        self.data = self.helper.load_data_from_file(self.fileName)
        self.day, self.month, self.year = self.helper.date_to_dd_mm_yyyy(self.helper.current_date())
        self.day = int(self.day)
        self.month = int(self.month)

### `get_jumua()`

Returns:

Name | Type | Description
--- | --- | ---
`str` |  | The time of jumua.

Source code in `MawaqitAPI\localMawaqit.py`

    68
    69
    70
    71
    72
    73
    def get_jumua(self):
        """
        Returns:
            str: The time of jumua.
        """
        return self.data["calendar"][self.month-1][str(self.day)][2]

### `get_prayer_time(prayer)`

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`prayer` | `str` | The prayer you want to get the time of. Can be fajr, dhuhr, asr, maghrib or isha. | required

Returns:

Name | Type | Description
--- | --- | ---
`str` |  | The time of the prayer.

Source code in `MawaqitAPI\localMawaqit.py`

    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    def get_prayer_time(self, prayer):
        """
        Args:
            prayer (str): The prayer you want to get the time of. Can be fajr, dhuhr, asr, maghrib or isha.

        Returns:
            str: The time of the prayer.
        """

        if prayer == "fajr":
            return self.data["calendar"][self.month-1][str(self.day)][0]
        elif prayer == "shurooq":
            return self.data["calendar"][self.month-1][str(self.day)][1]
        elif prayer == "dhuhr":
            return self.data["calendar"][self.month-1][str(self.day)][2]
        elif prayer == "asr":
            return self.data["calendar"][self.month-1][str(self.day)][3]
        elif prayer == "maghrib":
            return self.data["calendar"][self.month-1][str(self.day)][4]
        elif prayer == "isha":
            return self.data["calendar"][self.month-1][str(self.day)][5]
        else:
            return "Invalid prayer"

### `get_prayer_times()`

Returns:

Name | Type | Description
--- | --- | ---
`dict` |  | A dictionary with the prayer times.

Source code in `MawaqitAPI\localMawaqit.py`

    28
    29
    30
    31
    32
    33
    def get_prayer_times(self):
        """
        Returns:
            dict: A dictionary with the prayer times.
        """
        return self.helper.format_prayer_log(self.data["calendar"][self.month-1][str(self.day)])

### `get_prayer_times_by_date(date_string)`

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`date_string` | `str` | The date you want to get the prayer times of, format: dd-mm-yyyy. | required

Returns:

Name | Type | Description
--- | --- | ---
`dict` |  | The prayer times of the date.

Source code in `MawaqitAPI\localMawaqit.py`

    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    def get_prayer_times_by_date(self, date_string):
        """
        Args:
            date_string (str): The date you want to get the prayer times of, format: dd-mm-yyyy.

        Returns:
            dict: The prayer times of the date.
        """
        day, month, year = self.helper.date_to_dd_mm_yyyy(date_string)
        day = int(day)
        month = int(month)
        return self.helper.format_prayer_log(self.data["calendar"][month-1][str(day)])

### `get_shurooq()`

Returns:

Name | Type | Description
--- | --- | ---
`str` |  | The time of shurooq.

Source code in `MawaqitAPI\localMawaqit.py`

    60
    61
    62
    63
    64
    65
    def get_shurooq(self):
        """
        Returns:
            str: The time of shurooq.
        """
        return self.data["calendar"][self.month-1][str(self.day)][1]

## `Crawler`

Crawler class that gets the data from the website.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`mosque_id` | `str` | The id of the mosque you want to get the data from. Can be found in the url of the mosque. | required

Source code in `MawaqitAPI\scraper.py`

     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    class Crawler():
        """
        Crawler class that gets the data from the website.

        Args:
            mosque_id (str): The id of the mosque you want to get the data from. Can be found in the url of the mosque.
        """
        def __init__(self, mosque_id) -> None:

            self.url = "https://www.mawaqit.net/en/" + mosque_id
            self.elements = {
                "fajr": "/html/body/div[9]/div/div[3]/div[1]/div[2]/div",
                "dhuhr": "/html/body/div[9]/div/div[3]/div[2]/div[2]/div",
                "asr": "/html/body/div[9]/div/div[3]/div[3]/div[2]/div",
                "maghrib": "/html/body/div[9]/div/div[3]/div[4]/div[2]/div",
                "isha": "/html/body/div[9]/div/div[3]/div[5]/div[2]/div",
                "shurooq": "/html/body/div[9]/div/div[2]/div[7]/div[1]/div[2]/div[2]/div",
                "jumua": "/html/body/div[9]/div/div[2]/div[7]/div[3]/div/div[2]/div/div",
                "script_data": "/html/body/script[1]/text()"
            }
            self.mosque_id = mosque_id
            self.session = requests_html.HTMLSession()
            self.website_data = self.session.get(self.url)
            self.website_data.html.render()
            self.helper = Helper()

        # get prayer times from html elements
        def get_prayer_times(self) -> dict:
            fajr = self.website_data.html.xpath(self.elements["fajr"])[0].text
            dhuhr = self.website_data.html.xpath(self.elements["dhuhr"])[0].text
            asr = self.website_data.html.xpath(self.elements["asr"])[0].text
            maghrib = self.website_data.html.xpath(self.elements["maghrib"])[0].text
            isha = self.website_data.html.xpath(self.elements["isha"])[0].text
            return {
                "fajr": fajr,
                "dhuhr": dhuhr,
                "asr": asr,
                "maghrib": maghrib,
                "isha": isha
            }

        def get_prayer_time(self, prayer) -> str:
            if prayer in self.elements:
                return self.website_data.html.xpath(self.elements[prayer])[0].text

        def get_shurooq(self) -> str:
            return self.website_data.html.xpath(self.elements["shurooq"])[0].text

        def get_jumua(self) -> str:
            return self.website_data.html.xpath(self.elements["jumua"])[0].text

        def get_data(self) -> json:
            """
            Get the data from the website.

            Returns:
                json: The data from the website.

            """
            start_string = "var confData = "
            end_string = "]}]};"

            script_data = self.website_data.html.xpath(self.elements["script_data"])[0]
            start_index = script_data.find(start_string)
            end_index = script_data.find(end_string)
            data = script_data[start_index:end_index+4]
            data = data.replace(start_string, "")

            return json.loads(data)

        def get_prayer_times_by_date(self, date) -> dict:
            """
            Get the prayer times for a specific date.

            Args:
                date (str): The date you want to get the prayer times for. Format: DD-MM-YYYY

            Returns:
                dict: A dictionary with the prayer times.

            """

            day, month, year = date.split("-")
            day = int(day)
            month = int(month)

            #get data
            data = self.get_data()
            #get prayer times
            prayers = data["calendar"][month-1][str(day)]
            #remove second element

            return self.helper.format_prayer_log(prayers)

### `get_data()`

Get the data from the website.

Returns:

Name | Type | Description
--- | --- | ---
`json` | `json` | The data from the website.

Source code in `MawaqitAPI\scraper.py`

    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    def get_data(self) -> json:
        """
        Get the data from the website.

        Returns:
            json: The data from the website.

        """
        start_string = "var confData = "
        end_string = "]}]};"

        script_data = self.website_data.html.xpath(self.elements["script_data"])[0]
        start_index = script_data.find(start_string)
        end_index = script_data.find(end_string)
        data = script_data[start_index:end_index+4]
        data = data.replace(start_string, "")

        return json.loads(data)

### `get_prayer_times_by_date(date)`

Get the prayer times for a specific date.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`date` | `str` | The date you want to get the prayer times for. Format: DD-MM-YYYY | required

Returns:

Name | Type | Description
--- | --- | ---
`dict` | `dict` | A dictionary with the prayer times.

Source code in `MawaqitAPI\scraper.py`

    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    def get_prayer_times_by_date(self, date) -> dict:
        """
        Get the prayer times for a specific date.

        Args:
            date (str): The date you want to get the prayer times for. Format: DD-MM-YYYY

        Returns:
            dict: A dictionary with the prayer times.

        """

        day, month, year = date.split("-")
        day = int(day)
        month = int(month)

        #get data
        data = self.get_data()
        #get prayer times
        prayers = data["calendar"][month-1][str(day)]
        #remove second element

        return self.helper.format_prayer_log(prayers)

## `Helper`

Source code in `MawaqitAPI\helper.py`

     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    class Helper():

        def __init__(self):
            """
            Helper class that contains helper functions. Useful , repetitive functions that are used in multiple places.
            """
            pass

        def get_date_from_string(self, date_string):
            """
            Get the date from a string.

            Args:
                date_string (str): The date string.

            Returns:
                str: The date in the format DD-MM-YYYY.

            """
            return int(parser.parse(date_string).timestamp())

        def save_data_to_file(self, data, file_name):

            with open(file_name, "w") as f:
                #dump dict to file
                json.dump(data, f)

        def load_data_from_file(self, file_name):
            with open(file_name, "r") as f:
                #load dict from file
                return json.load(f)

        def date_to_dd_mm_yyyy(self, date_string):
            #return [day, month, year]
            day , month, year = date_string.split("-")
            return [day, month, year]

        def current_date(self):
            return datetime.now().strftime("%d-%m-%Y")

        def format_prayer_log(self, prayers):
            return {"fajr": prayers[0], "shurooq": prayers[1], "dhuhr": prayers[2], "asr": prayers[3], "maghrib": prayers[4], "isha": prayers[5]}

        def get_current_timestamp(self):
            return int(datetime.now().timestamp())

        def get_timestamp(self, date_string):
            return int(parser.parse(date_string).timestamp())

        def time_left(self, date_string):
            return self.get_timestamp(date_string) - self.get_current_timestamp()

        def get_next_prayer(self, prayers):
            for prayer in prayers:
                if self.time_left(prayers[prayer]) > 0:
                    return prayer

### `__init__()`

Helper class that contains helper functions. Useful , repetitive functions that are used in multiple places.

Source code in `MawaqitAPI\helper.py`

     7
     8
     9
    10
    11
    def __init__(self):
        """
        Helper class that contains helper functions. Useful , repetitive functions that are used in multiple places.
        """
        pass

### `get_date_from_string(date_string)`

Get the date from a string.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`date_string` | `str` | The date string. | required

Returns:

Name | Type | Description
--- | --- | ---
`str` |  | The date in the format DD-MM-YYYY.

Source code in `MawaqitAPI\helper.py`

    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    def get_date_from_string(self, date_string):
        """
        Get the date from a string.

        Args:
            date_string (str): The date string.

        Returns:
            str: The date in the format DD-MM-YYYY.

        """
        return int(parser.parse(date_string).timestamp())

## `ChromeCast`

A class to control a Google Chromecast device. To play the adhan

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`friendly_name` | `str` | The name of the device you want to control. | required

Source code in `MawaqitAPI\google.py`

     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    class ChromeCast():
        """
        A class to control a Google Chromecast device. To play the adhan
        Args:
            friendly_name (str): The name of the device you want to control.

        """
        def __init__(self, friendly_name):
            chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[friendly_name])
            print(chromecasts)
            self.cast = chromecasts[0]
            self.cast.wait()
            self.mc = self.cast.media_controller

            """
            Args:
            volume (float): The volume to set the device to. Must be between 0 and 1.
            """
        def set_volume(self, volume):
            self.cast.set_volume(volume)

        """
        Args:
            url (str): The url of the media you want to play.
            media_type (str): The type of the media you want to play. example: "audio/mp3"
        """
        def play(self, url, media_type):
            self.mc.play_media(url, media_type)
            self.mc.block_until_active()

            """
            Pauses the media playing on the device.
            """
        def pause(self):
            self.mc.pause()

            """
            gets the status of the device.
            """
        def get_status(self):
            return self.mc.status

### `mc = self.cast.media_controller` `instance-attribute`

volume (float): The volume to set the device to. Must be between 0 and 1.

This file contains all the constants used in the project Adhan url is the url of the adhan audio file , mp3 format