I want to convert Python code into Apps script (API)

241 views
Skip to first unread message

어썸포유_Awesome4U

unread,
Mar 8, 2023, 1:36:48 AM3/8/23
to Google Apps Script Community
I want to convert Python code into Apps script and use it, but I can't. Help me. Don't convert it to GPT. Let me know.

import json
import time
import datetime
import uuid
import hmac
import hashlib
import requests
# apiKey, apiSecret input
apiKey = 'xxx'
apiSecret = 'xxxx'

protocol = 'https'
domain = 'api.solapi.com'
prefix = ''
def unique_id():
    return str(uuid.uuid1().hex)
def get_iso_datetime():
    utc_offset_sec = time.altzone if time.localtime().tm_isdst else time.timezone
    utc_offset = datetime.timedelta(seconds=-utc_offset_sec)
    return datetime.datetime.now().replace(tzinfo=datetime.timezone(offset=utc_offset)).isoformat()
def get_signature(key, msg):
    return hmac.new(key.encode(), msg.encode(), hashlib.sha256).hexdigest()
def get_headers(apiKey, apiSecret):
    date = get_iso_datetime()
    salt = unique_id()
    data = date + salt
    return {
      'Authorization': 'HMAC-SHA256 ApiKey=' + apiKey + ', Date=' + date + ', salt=' + salt + ', signature=' +
                             get_signature(apiSecret, data),
      'Content-Type': 'application/json; charset=utf-8'
    }
def getUrl(path):
  url = '%s://%s' % (protocol, domain)
  if prefix != '':
    url = url + prefix
  url = url + path
  return url
def sendMany(data):
  return requests.post(getUrl('/messages/v4/send-many'), headers=get_headers(apiKey, apiSecret), json=data)
# sms send
if __name__ == '__main__':
  data = {
    'messages': [
      {
        'to': '01000000000',
        'from': '01000000001',
        'text': '2차 Test solapi'
      }
          ]
        }

  res = sendMany(data)
  print(json.dumps(res.json(), indent=2, ensure_ascii=False))
Reply all
Reply to author
Forward
0 new messages