Skip to content

Instantly share code, notes, and snippets.

@byStrange
Created May 20, 2024 12:15
Show Gist options
  • Save byStrange/812f07e4359362c3cce0c2f0f8e0db46 to your computer and use it in GitHub Desktop.
Save byStrange/812f07e4359362c3cce0c2f0f8e0db46 to your computer and use it in GitHub Desktop.
import requests
import json
import os
import random
import string
from django.conf import settings
import re
if os.environ.get("FIXIE_URL", ""):
os.environ["http_proxy"] = os.environ.get("FIXIE_URL")
os.environ["https_proxy"] = os.environ.get("FIXIE_URL")
LOGIN = "rahmatulo"
API_TOKEN = "10V7H1p704Ap5J4ggb0d"
SMS_GATEWAY = "http://185.8.212.184/smsgateway/"
def make_template(template: str, *arguments: int or str):
# Convert arguments to a list if they were passed as separate arguments
if len(arguments) == 1 and isinstance(arguments[0], (list, tuple)):
arguments = arguments[0]
pattern = r"##VAR(\d+)##"
# Replace the placeholders with argument values
def replace_match(match):
index = int(match.group(1))
return str(arguments[index - 1]) if 1 <= index <= len(arguments) else ""
template = re.sub(pattern, replace_match, template)
# Replace any remaining placeholders with an empty string
return template
def generate_otp(length : int = 5) -> str:
length = length or 5
otp = ''.join(random.choices(string.digits, k=length))
return otp
def send_otp(phone_number: str, otp: str) -> bool:
p = [
{
"phone": phone_number,
"text": make_template(settings.SMS_TEMPLATE_TEXT, otp)
}
]
p = json.dumps(p)
data = {
"login": LOGIN,
"password": API_TOKEN,
"data": p
}
print(data)
req = requests.get(SMS_GATEWAY, json=data)
print(req)
print(req.content)
return req.ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment