Пример #1
0
def update() -> Response:

    try:
        print(request.json)

        ownerId = request.json["owner_id"]
        athlete = AthleteNotifications.query.filter_by(id=ownerId).first()

        if athlete is None:
            # Strava's API expects a 200
            return Response('User not found', 200)

        client = APNsClient(team_id=os.environ['TEAM_ID'],
                            bundle_id=os.environ['BUNDLE_ID'],
                            auth_key_id=os.environ['APNS_KEY_ID'],
                            auth_key=os.environ['APNS_TOKEN'],
                            use_sandbox=configuration.SANDOX)

        client.send_message(athlete.token,
                            "Dash Notification",
                            content_available=True,
                            extra=request.json,
                            sound='default',
                            priority=5,
                            topic=os.environ['BUNDLE_ID'])

        print('Sent...')
        return Response('Success sending Push', 200)

    except Exception as error:
        # Strava's API expects a 200
        return Response('Bad request: {0}'.format(error), 200)
Пример #2
0
def send_push_apns(token_hex, content, IS_LOCAL):
    client = APNsClient(team_id=TEAM_ID,
                        bundle_id=BUNDLE_ID,
                        auth_key_id=APNS_KEY_ID,
                        auth_key_filepath=APNS_AUTH_KEY,
                        use_sandbox=IS_LOCAL,
                        force_proto='h2')

    try:
        client.send_message(token_hex, content, sound="default")
    except:
        PushNotification.objects.filter(token=token_hex).delete()
        pass
Пример #3
0
def apns(msg, identifier=None, priority=10, users=['sebastien.lepoder']):
    client = APNsClient(
        team_id='72D72PGS3Z',
        bundle_id='d3-connect',
        auth_key_id='GQUF76FL7C',
        auth_key_filepath='/home/pi/RFID/appKeys/AuthKey_GQUF76FL7C.p8',
        use_sandbox=False,
        force_proto='h2')

    client.send_bulk_message(phoneIDs(users),
                             alert={
                                 "body": msg,
                                 "title": 'Doors'
                             },
                             badge=0,
                             sound='default',
                             category='',
                             content_available=False,
                             extra={},
                             priority=priority,
                             expiration=int(time.time()) + 60)
Пример #4
0
from gobiko.apns import APNsClient
from gobiko.apns.exceptions import BadDeviceToken

from pushjack import APNSClient

from botmarket.settings import TEAM_ID, BUNDLE_ID, APNS_KEY_ID, APNS_AUTH_KEY

CLIENT_ISO_PUSH = APNsClient(team_id=TEAM_ID,
                             bundle_id=BUNDLE_ID,
                             auth_key_id=APNS_KEY_ID,
                             auth_key_filepath=APNS_AUTH_KEY)

# CLIENT_ISO_PUSH = APNSClient(
#     certificate=APNS_AUTH_KEY,
#     default_error_timeout=10,
#     default_expiration_offset=2592000,
#     default_batch_size=100,
#     default_retries=5)

text = {
    "en": "You are the owner of the bot: ",
    "ru": "Вам добавлены права на бота: "
}


def get_text_change_user(language):
    try:
        message = text.get(language)
        if message is None:
            return text.get("en")
        return message
Пример #5
0
if __name__ == "__main__":
    # programm parameters
    radar_files = sys.argv[1]
    browser_notify_url = sys.argv[2]

    # Apple Push setup
    apns_config_file = '/etc/apns.json'
    apns = None
    if os.path.isfile(apns_config_file):
        config = None
        with open(apns_config_file) as conf_file:
            config = json.load(conf_file)
        apns = APNsClient(
            team_id=config["team_id"],
            bundle_id=config["bundle_id"],
            auth_key_id=config["auth_key_id"],
            auth_key_filepath=config["auth_key_filepath"],
            use_sandbox=config["use_sandbox"]
        )

    # Android push setup. The API key comes from the environment.
    fcm = None
    if os.getenv('FCM_API_KEY', None):
        fcm = FCMNotification()

    # mongodb setup
    db_client = MongoClient("mongodb://mongo:27017/")
    # both will be created automatically when the first document is inserted
    db = db_client["meteocool"]
    collection = db["collection"]