mawaqit 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mawaqit-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 MAWAQIT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
mawaqit-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.1
2
+ Name: mawaqit
3
+ Version: 0.0.1
4
+ Summary: The official MAWAQIT Python wrapper.
5
+ Home-page: https://github.com/mawaqit/mawaqit-py
6
+ Author: MAWAQIT
7
+ Author-email: support@mawaqit.net
8
+ License: MIT
9
+ Project-URL: Bug Tracker, https://github.com/mawaqit/mawaqit-py/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # MAWAQIT Python Library
18
+
19
+ ‏السلام عليكم ورحمة الله وبركاته
20
+
21
+ This is the official Python library to access the [MAWAQIT](https://mawaqit.net) API.
22
+
23
+ ## Installation
24
+
25
+ To use this Python library, you can install it via pip:
26
+
27
+ ```bash
28
+ pip install mawaqit
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Synchroneous version
34
+
35
+ `TODO : Not made yet.`
36
+
37
+ ### Asynchroneous version
38
+
39
+ Here's a simple example (with asyncio) on how to use this library.
40
+ You can check the [async_example.py](examples/async_example.py) file to copy this code.
41
+
42
+ ```python
43
+ import asyncio
44
+ from mawaqit import AsyncMawaqitClient
45
+
46
+
47
+ async def main():
48
+ # Initialize the Mawaqit client:
49
+ # You can pass the username and password as parameters,
50
+ # or directly your valid MAWAQIT API token
51
+ # You can also pass your location (latitude and longitude) as parameters to get the nearest mosques
52
+ client = AsyncMawaqitClient(username=USERNAME,
53
+ password=PASSWORD,
54
+ longitude=LONGITUDE,
55
+ latitude=LATITUDE)
56
+
57
+ # Get your API token
58
+ api_token = await client.get_api_token()
59
+
60
+ # Get information of the 5 nearest mosques around the given position (long, lat)
61
+ mosques = await client.all_mosques_neighborhood()
62
+
63
+ # Set the mosque to use
64
+ client.mosque = mosques[0]['uuid']
65
+
66
+ # Fetch the prayer times from client.mosque
67
+ print(client.fetch_prayer_times())
68
+
69
+ await client.close()
70
+
71
+ if __name__ == "__main__":
72
+ asyncio.run(main())
73
+ ```
74
+
75
+ ## Exceptions
76
+
77
+ - `NotAuthenticatedException`: Raised when authentication fails.
78
+ - `BadCredentialsException`: Raised when login credentials are incorrect.
79
+ - `NoMosqueAround`: Raised when no mosques are found around the specified location.
80
+ - `MissingCredentials`: Raised when required credentials are not provided.
81
+
82
+
83
+ ## License
84
+
85
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
86
+
87
+
88
+ ## Contributing
89
+
90
+ If you want to contribute to this project, feel free to [fork](https://github.com/mawaqit/mawaqit-py/fork) it and submit a pull request.
91
+
92
+ You can also open an [issue](https://github.com/mawaqit/mawaqit-py/issues/new) if you find any bug or have any suggestion.
93
+
94
+
95
+ ## Questions
96
+
97
+ If you have any question, feel free to contact us at [support@mawaqit.net](mailto:support@mawaqit.net).
98
+
99
+
100
+ ## May Allah reward you!
101
+
102
+
103
+
104
+
105
+
@@ -0,0 +1,89 @@
1
+ # MAWAQIT Python Library
2
+
3
+ ‏السلام عليكم ورحمة الله وبركاته
4
+
5
+ This is the official Python library to access the [MAWAQIT](https://mawaqit.net) API.
6
+
7
+ ## Installation
8
+
9
+ To use this Python library, you can install it via pip:
10
+
11
+ ```bash
12
+ pip install mawaqit
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Synchroneous version
18
+
19
+ `TODO : Not made yet.`
20
+
21
+ ### Asynchroneous version
22
+
23
+ Here's a simple example (with asyncio) on how to use this library.
24
+ You can check the [async_example.py](examples/async_example.py) file to copy this code.
25
+
26
+ ```python
27
+ import asyncio
28
+ from mawaqit import AsyncMawaqitClient
29
+
30
+
31
+ async def main():
32
+ # Initialize the Mawaqit client:
33
+ # You can pass the username and password as parameters,
34
+ # or directly your valid MAWAQIT API token
35
+ # You can also pass your location (latitude and longitude) as parameters to get the nearest mosques
36
+ client = AsyncMawaqitClient(username=USERNAME,
37
+ password=PASSWORD,
38
+ longitude=LONGITUDE,
39
+ latitude=LATITUDE)
40
+
41
+ # Get your API token
42
+ api_token = await client.get_api_token()
43
+
44
+ # Get information of the 5 nearest mosques around the given position (long, lat)
45
+ mosques = await client.all_mosques_neighborhood()
46
+
47
+ # Set the mosque to use
48
+ client.mosque = mosques[0]['uuid']
49
+
50
+ # Fetch the prayer times from client.mosque
51
+ print(client.fetch_prayer_times())
52
+
53
+ await client.close()
54
+
55
+ if __name__ == "__main__":
56
+ asyncio.run(main())
57
+ ```
58
+
59
+ ## Exceptions
60
+
61
+ - `NotAuthenticatedException`: Raised when authentication fails.
62
+ - `BadCredentialsException`: Raised when login credentials are incorrect.
63
+ - `NoMosqueAround`: Raised when no mosques are found around the specified location.
64
+ - `MissingCredentials`: Raised when required credentials are not provided.
65
+
66
+
67
+ ## License
68
+
69
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
70
+
71
+
72
+ ## Contributing
73
+
74
+ If you want to contribute to this project, feel free to [fork](https://github.com/mawaqit/mawaqit-py/fork) it and submit a pull request.
75
+
76
+ You can also open an [issue](https://github.com/mawaqit/mawaqit-py/issues/new) if you find any bug or have any suggestion.
77
+
78
+
79
+ ## Questions
80
+
81
+ If you have any question, feel free to contact us at [support@mawaqit.net](mailto:support@mawaqit.net).
82
+
83
+
84
+ ## May Allah reward you!
85
+
86
+
87
+
88
+
89
+
@@ -0,0 +1,3 @@
1
+ # Welcome to the MAWAQIT official API.
2
+
3
+ from .mawaqit_async import AsyncMawaqitClient
@@ -0,0 +1,26 @@
1
+ API_URL_BASE = "https://mawaqit.net/api/2.0"
2
+ LOGIN_URL = f"{API_URL_BASE}/me"
3
+ SEARCH_MOSQUES_URL = f"{API_URL_BASE}/mosque/search"
4
+
5
+
6
+ def prayer_times_url(mosque_id: int) -> str:
7
+ return f"{API_URL_BASE}/mosque/{mosque_id}/prayer-times"
8
+
9
+
10
+ MAX_LOGIN_RETRIES = 20
11
+
12
+
13
+ class NotAuthenticatedException(Exception):
14
+ pass
15
+
16
+
17
+ class BadCredentialsException(Exception):
18
+ pass
19
+
20
+
21
+ class NoMosqueAround(Exception):
22
+ pass
23
+
24
+
25
+ class MissingCredentials(Exception):
26
+ pass
@@ -0,0 +1,5 @@
1
+ # Synchronous version of the library.
2
+ # Not finished yet.
3
+ # Please, use the asynchronous version in the meantime.
4
+ # You can also use the unofficial py-mawaqit library.
5
+
@@ -0,0 +1,141 @@
1
+ """Python wrapper to access the MAWAQIT API."""
2
+
3
+ from __future__ import annotations
4
+ import json
5
+ from datetime import date, datetime, timedelta
6
+ from types import TracebackType
7
+ from typing import Any, Dict, List, Union
8
+ import backoff
9
+ import aiohttp
10
+ from aiohttp import ClientSession
11
+
12
+ from .consts import *
13
+
14
+ JSON = Union[Dict[str, Any], List[Dict[str, Any]]]
15
+
16
+
17
+ async def relogin(invocation: dict[str, Any]) -> None:
18
+ await invocation["args"][0].login()
19
+
20
+
21
+ class AsyncMawaqitClient:
22
+ """Interface async class for the MAWAQIT official API."""
23
+
24
+ def __init__(
25
+ self,
26
+ latitude: float = None,
27
+ longitude: float = None,
28
+ mosque: str = None,
29
+ username: str = None,
30
+ password: str = None,
31
+ token: str = None,
32
+ session: ClientSession = None,
33
+ ) -> None:
34
+
35
+ self.username = username
36
+ self.password = password
37
+ self.latitude = latitude
38
+ self.longitude = longitude
39
+ self.mosque = mosque
40
+ self.token = token
41
+ self.session = session if session else ClientSession()
42
+
43
+ async def __aenter__(self) -> AsyncMawaqitClient:
44
+ return self
45
+
46
+ async def __aexit__(
47
+ self,
48
+ exc_type: type[BaseException] | None,
49
+ exc_value: BaseException | None,
50
+ traceback: TracebackType | None,
51
+ ) -> None:
52
+ await self.close()
53
+
54
+ async def close(self) -> None:
55
+ """Close the session."""
56
+ await self.session.close()
57
+
58
+ @backoff.on_exception(
59
+ backoff.expo,
60
+ NotAuthenticatedException,
61
+ max_tries=MAX_LOGIN_RETRIES,
62
+ on_backoff=relogin
63
+ )
64
+ async def get_api_token(self) -> str:
65
+ """Get the MAWAQIT API token."""
66
+
67
+ if self.token is None:
68
+ await self.login()
69
+
70
+ return self.token
71
+
72
+ async def all_mosques_neighborhood(self):
73
+ """Get the five nearest mosques from the Client coordinates.
74
+ Returns a list of dicts with info on the mosques."""
75
+
76
+ if (self.latitude is None) or (self.longitude is None):
77
+ raise MissingCredentials("Please provide a latitude and a longitude in your MawaqitClient object.")
78
+
79
+ payload = {
80
+ "lat": self.latitude,
81
+ "lon": self.longitude
82
+ }
83
+ headers = {
84
+ 'Authorization': self.token,
85
+ 'Content-Type': 'application/json',
86
+ }
87
+
88
+ endpoint_url = SEARCH_MOSQUES_URL
89
+
90
+ async with self.session.get(endpoint_url, params=payload, data=None, headers=headers) as response:
91
+ if response.status != 200:
92
+ raise NotAuthenticatedException("Authentication failed. Please check your MAWAQIT credentials.")
93
+ data = await response.json()
94
+
95
+ if len(data) == 0:
96
+ raise NoMosqueAround("No mosque found around your location. Please check your coordinates.")
97
+
98
+ return data
99
+
100
+ async def fetch_prayer_times(self) -> dict:
101
+ """Fetch the prayer times calendar for self.mosque,
102
+ Returns a dict with info on the mosque and the year-calendar prayer times."""
103
+
104
+ if self.mosque is None:
105
+ mosque_id = await self.all_mosques_neighborhood()
106
+ mosque_id = mosque_id[0]["uuid"]
107
+ else:
108
+ mosque_id = self.mosque
109
+
110
+ headers = {'Content-Type': 'application/json',
111
+ 'Api-Access-Token': format(self.token)}
112
+
113
+ endpoint_url = prayer_times_url(mosque_id)
114
+
115
+ async with self.session.get(endpoint_url, data=None, headers=headers) as response:
116
+ if response.status != 200:
117
+ raise NotAuthenticatedException(
118
+ "Authentication failed. Please retry. Response.status : " + str(response.status))
119
+ data = await response.json()
120
+
121
+ return data
122
+
123
+ async def login(self) -> None:
124
+ """Log into the MAWAQIT website."""
125
+
126
+ if (self.username is None) or (self.password is None):
127
+ raise MissingCredentials("Please provide a MAWAQIT login and password.")
128
+
129
+ auth = aiohttp.BasicAuth(self.username, self.password)
130
+
131
+ endpoint_url = LOGIN_URL
132
+
133
+ async with await self.session.post(endpoint_url, auth=auth) as response:
134
+ if response.status == 401:
135
+ raise BadCredentialsException("Authentication failed. Please check your MAWAQIT credentials.")
136
+ elif response.status != 200:
137
+ raise NotAuthenticatedException("Authentication failed. Please retry.")
138
+
139
+ data = await response.text()
140
+
141
+ self.token = json.loads(data)["apiAccessToken"]
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.1
2
+ Name: mawaqit
3
+ Version: 0.0.1
4
+ Summary: The official MAWAQIT Python wrapper.
5
+ Home-page: https://github.com/mawaqit/mawaqit-py
6
+ Author: MAWAQIT
7
+ Author-email: support@mawaqit.net
8
+ License: MIT
9
+ Project-URL: Bug Tracker, https://github.com/mawaqit/mawaqit-py/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # MAWAQIT Python Library
18
+
19
+ ‏السلام عليكم ورحمة الله وبركاته
20
+
21
+ This is the official Python library to access the [MAWAQIT](https://mawaqit.net) API.
22
+
23
+ ## Installation
24
+
25
+ To use this Python library, you can install it via pip:
26
+
27
+ ```bash
28
+ pip install mawaqit
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Synchroneous version
34
+
35
+ `TODO : Not made yet.`
36
+
37
+ ### Asynchroneous version
38
+
39
+ Here's a simple example (with asyncio) on how to use this library.
40
+ You can check the [async_example.py](examples/async_example.py) file to copy this code.
41
+
42
+ ```python
43
+ import asyncio
44
+ from mawaqit import AsyncMawaqitClient
45
+
46
+
47
+ async def main():
48
+ # Initialize the Mawaqit client:
49
+ # You can pass the username and password as parameters,
50
+ # or directly your valid MAWAQIT API token
51
+ # You can also pass your location (latitude and longitude) as parameters to get the nearest mosques
52
+ client = AsyncMawaqitClient(username=USERNAME,
53
+ password=PASSWORD,
54
+ longitude=LONGITUDE,
55
+ latitude=LATITUDE)
56
+
57
+ # Get your API token
58
+ api_token = await client.get_api_token()
59
+
60
+ # Get information of the 5 nearest mosques around the given position (long, lat)
61
+ mosques = await client.all_mosques_neighborhood()
62
+
63
+ # Set the mosque to use
64
+ client.mosque = mosques[0]['uuid']
65
+
66
+ # Fetch the prayer times from client.mosque
67
+ print(client.fetch_prayer_times())
68
+
69
+ await client.close()
70
+
71
+ if __name__ == "__main__":
72
+ asyncio.run(main())
73
+ ```
74
+
75
+ ## Exceptions
76
+
77
+ - `NotAuthenticatedException`: Raised when authentication fails.
78
+ - `BadCredentialsException`: Raised when login credentials are incorrect.
79
+ - `NoMosqueAround`: Raised when no mosques are found around the specified location.
80
+ - `MissingCredentials`: Raised when required credentials are not provided.
81
+
82
+
83
+ ## License
84
+
85
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
86
+
87
+
88
+ ## Contributing
89
+
90
+ If you want to contribute to this project, feel free to [fork](https://github.com/mawaqit/mawaqit-py/fork) it and submit a pull request.
91
+
92
+ You can also open an [issue](https://github.com/mawaqit/mawaqit-py/issues/new) if you find any bug or have any suggestion.
93
+
94
+
95
+ ## Questions
96
+
97
+ If you have any question, feel free to contact us at [support@mawaqit.net](mailto:support@mawaqit.net).
98
+
99
+
100
+ ## May Allah reward you!
101
+
102
+
103
+
104
+
105
+
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ mawaqit/__init__.py
5
+ mawaqit/consts.py
6
+ mawaqit/mawaqit.py
7
+ mawaqit/mawaqit_async.py
8
+ mawaqit.egg-info/PKG-INFO
9
+ mawaqit.egg-info/SOURCES.txt
10
+ mawaqit.egg-info/dependency_links.txt
11
+ mawaqit.egg-info/requires.txt
12
+ mawaqit.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ aiohttp>=3.8.0
2
+ backoff>=2.0.0
@@ -0,0 +1 @@
1
+ mawaqit
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
mawaqit-0.0.1/setup.py ADDED
@@ -0,0 +1,29 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as readme:
4
+ long_description = readme.read()
5
+
6
+ setup(
7
+ name="mawaqit",
8
+ version="0.0.1",
9
+ author="MAWAQIT",
10
+ author_email="support@mawaqit.net",
11
+ description="The official MAWAQIT Python wrapper.\n"
12
+ "Get the data of your mosque (such as name, location, prayer times) from the MAWAQIT API.",
13
+ long_description=long_description,
14
+ long_description_content_type="text/markdown",
15
+ url="https://github.com/mawaqit/mawaqit-py",
16
+ project_urls={
17
+ "Bug Tracker": "https://github.com/mawaqit/mawaqit-py/issues",
18
+ },
19
+ license="MIT",
20
+ classifiers=[
21
+ "Programming Language :: Python :: 3",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Operating System :: OS Independent",
24
+ ],
25
+ packages=find_packages(include=["mawaqit", "mawaqit.*"]),
26
+ install_requires=['aiohttp>=3.8.0',
27
+ 'backoff>=2.0.0'],
28
+ python_requires=">=3.7"
29
+ )