Skip to content

Commit

Permalink
Update RemoteApiUtil (#1445)
Browse files Browse the repository at this point in the history
* Create RemoteApiUtil.py

* Bump cryptography from 42.0.4 to 43.0.1 (#299)

Bumps [cryptography](https://github.com/pyca/cryptography) from 42.0.4 to 43.0.1.
- [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst)
- [Commits](pyca/cryptography@42.0.4...43.0.1)

---
updated-dependencies:
- dependency-name: cryptography
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update RemoteApiUtil.py

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
otseng and dependabot[bot] committed Sep 5, 2024
1 parent d599046 commit 844034b
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions util/RemoteApiUtil.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
import hashlib
import sys
from base64 import b64encode
from datetime import timezone, datetime

import requests
import config

if __name__ == "__main__":
print(f"Username: {config.apiServerClientId}")
# To use:
# Set config.apiServerClientId
# Set config.apiServerClientSecret
# python -m util.RemoteApiUtil password
# python -m util.RemoteApiUtil get https://bible.gospelchurch.uk/api/bible/KJV/43/3/16

def password():
dt = datetime.now(timezone.utc)
secret = config.apiServerClientSecret + str(dt.month)
password = hashlib.md5(secret.encode("utf-8")).hexdigest()
print(f"Password: {password}")
return password

if __name__ == "__main__":

if len(sys.argv) < 2:
print("Usage:")
print(" password - prints api password")
print(" get <url> - makes get call to url")
print(" Example:")
print(" get https://bible.gospelchurch.uk/api/bible/KJV/43/3/16")
else:
method = sys.argv[1].strip()
password = password()
if method == "password":
print(f"Username: {config.apiServerClientId}")
print(f"Password: {password}")
else:
if len(sys.argv) < 3:
print("Missing url")
exit(1)
url = sys.argv[2].strip()
if method == "get":
print("Get: " + url)
decoded_token = config.apiServerClientId + ":" + password
encoded_token = b64encode(decoded_token.encode("utf-8")).decode('utf-8')
try:
response = requests.get(url,
headers={'Authorization': 'Basic ' + encoded_token})
print(response.json())
except Exception as ex:
print(ex)

0 comments on commit 844034b

Please sign in to comment.