Skip to content

Instantly share code, notes, and snippets.

@mostafaasadi
Created January 27, 2019 20:42
Show Gist options
  • Save mostafaasadi/f59db378955e35932b39564fc90f81e1 to your computer and use it in GitHub Desktop.
Save mostafaasadi/f59db378955e35932b39564fc90f81e1 to your computer and use it in GitHub Desktop.
A python script for najva.com api
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import json
import pytz
import requests
import datetime
# dely time
delay = datetime.timedelta(seconds=10)
time = datetime.datetime.now(pytz.timezone('Asia/Tehran')) + delay
data = {
"api_key": '<YOUR_API_KEY>',
"title": "عنوان آگاه‌سازی",
"body": 'بدنه آگاه‌سازی',
"url": "http://example.com",
"icon": "http://example.com/static/icon.png",
"image": "http://example.com/static/img.png",
"sent_time": time.strftime('%Y-%m-%d{}%H:%M:%S').format('T'),
"segments_include": [1, 22],
"segments_exclude": [12],
"one_signal_accounts": [21, 102],
"one_signal_enabled": False
}
try:
header = {
'Content-Type': 'application/json',
'Authorization': 'Token <YOUR_TOKEN>'}
request = requests.post(
'https://app.najva.com/api/v1/notifications/',
data=json.dumps(data),
headers=header)
request_json = request.json()
print(request_json)
except Exception as err:
print(err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment