Exemplo n.º 1
0
def sub_gcm(request):
    try:
        reg_id = request.REQUEST["reg_id"]
        dev_id = request.REQUEST["dev_id"]
    except KeyError:
        return {"success": False, "message": "Invalid Parameters."}

    print "creating device sub"
    try:
        get_device_model().objects.create(name=dev_id, dev_id=dev_id, reg_id=reg_id)
    except:
        return {"success": False, "message": "Registration Failed"}

    return {"success": True, "message": "Device registered", "reg_id": reg_id, "dev_id": dev_id}
Exemplo n.º 2
0
def sendPost(request, SpouseRequest_id, Device_id):
    sReq = SpouseRequest.objects.get(id=SpouseRequest_id)
    phone = get_device_model().objects.get(id=Device_id)
    phone.send_message(sReq.question, collapse_key='somethingfromview')  
    return HttpResponse('%s device. Spouse %s has send following message: %s' % (Device_id, SpouseRequest_id, sReq))
        
        
Exemplo n.º 3
0
  def handle(self, *args, **options):
    while True:
      #self.stdout.write('building device map...')

      devmap = dict()
      devs = get_device_model().objects.all()
      for dev in devs:
        devmap[dev.dev_id] = dev

      routes = BusWroute.objects.all()
      route_pos_map = dict()
      for r in routes:
        loc = RealTimeRoutes.get_pos(r.id, False)
        if loc:
          route_pos_map[r.id] = float(loc['lat']), float(loc['lng'])
        else:
          route_pos_map[r.id] = None


      subs = StopSubscription.objects.all()
      for sub in subs:
        loc = route_pos_map[sub.stop.route.id]
        #self.stdout.write(str(loc))
        if loc:
          sub_pos = float(sub.stop.lat), float(sub.stop.lng)
          lat_dif = sub_pos[0] - loc[0]
          lng_dif = sub_pos[1] - loc[1]
          dist = math.sqrt(lat_dif**2 + lng_dif**2)
          self.stdout.write(str(dist))
          if dist < 0.0005:
            devmap[sub.device].send_message("foobar f**k you")
            self.stdout.write("sending message...")

      time.sleep(3)
Exemplo n.º 4
0
def entrance(request, imei):
    user = User.objects.get(imei=imei)
    admins = User.objects.filter(admin=1).filter(auth=1)
    timestamp = datetime.datetime.today()
    if user.auth:
        entrance_log = EntranceLog(user_id=user.id, time=timestamp)
        entrance_log.save()
        for admin in admins:
            print "IMEI: %s " % admin.imei
            notification = get_device_model().objects.get(dev_id=admin.imei)
            notification.send_message("%s went home." % user.name)
        return HttpResponse("Hello, %s." % user.name)
    else:
        entrance_log = EntranceLog(user_id='1', time=timestamp)
        entrance_log.save()
        for admin in admins:
            notification = get_device_model().objects.get(dev_id=admin.imei)
            notification.send_message("Someone tried to invade your home.")
        return HttpResponse("You are NOT authorized to enter.")
Exemplo n.º 5
0
def entrance(request, imei):
    user = User.objects.get(imei=imei)
    admins = User.objects.filter(admin=1).filter(auth=1)
    timestamp = datetime.datetime.today()
    if user.auth:
        entrance_log = EntranceLog(user_id=user.id, time=timestamp)
        entrance_log.save()
        for admin in admins:
            print "IMEI: %s " % admin.imei
            notification = get_device_model().objects.get(dev_id=admin.imei)
            notification.send_message("%s went home." % user.name)
        return HttpResponse("Hello, %s." % user.name)
    else:
        entrance_log = EntranceLog(user_id='1', time=timestamp)
        entrance_log.save()
        for admin in admins:
            notification = get_device_model().objects.get(dev_id=admin.imei)
            notification.send_message("Someone tried to invade your home.")
        return HttpResponse("You are NOT authorized to enter.")
Exemplo n.º 6
0
def send_push(request):
	now = time.localtime()
	now_time = "%02d:%02d:%02d" % (now.tm_hour, now.tm_min, now.tm_sec)
	message = Push(message_type=request.POST.get('message_type'), message_text=request.POST.get('message_text'), 
		time=now_time)
	message.save()

	# Send GCM
	Device = get_device_model()
	Device.objects.all().send_message({'message':'test message'})
	return redirect('/admin/push/')
Exemplo n.º 7
0
    def create(self, request, *args, **kwargs):
        created_object = super(PollutionMarkViewSet, self).create(request, *args, **kwargs)

        # point = PollutionMark.objects.get(pk=created_object.data['id'])
        # serializer = PollutionMarkSerializer(point)
        # array = [serializer.data]
        # content = JSONRenderer().render(array)

        device = get_device_model()
        device.objects.all().send_message({'NewPoint': created_object.data['id']})

        return created_object
Exemplo n.º 8
0
 def create_by_json(self, post_json):
     try:
         user = User.objects.get(username=post_json.get('username'))
         content = post_json.get('content')
         latitude = post_json.get('latitude')
         longitude = post_json.get('longitude')
         likes = post_json.get('likes')
         dislikes = post_json.get('dislikes')
         feed = Feed.objects.create(
             user = user,
             content = content,
             latitude = latitude,
             longitude = longitude,
             likes = likes,
             dislikes = dislikes,
         )
         from gcm.models import get_device_model
         phones = get_device_model().objects.all()
         for phone in phones:
             phone.send_message('New Feed Available!')
     except Exception as e:
         raise e
Exemplo n.º 9
0
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError

from gcm.models import get_device_model

Device = get_device_model()


class Command(BaseCommand):
    args = '<device_id message>'
    help = 'Send message through gcm api'

    option_list = BaseCommand.option_list + (
        make_option(
            '--devices',
            action='store_true',
            dest='devices',
            default=False,
            help='List of available devices'),
        make_option(
            '--collapse-key',
            dest='collapse_key',
            default='message',
            help='Set value of collapse_key flag, default is "message"'),
        )

    def handle(self, *args, **options):

        if options['devices']:
            devices = Device.objects.filter(is_active=True)
Exemplo n.º 10
0
def send_phone(Device, args):
    phone = get_device_model().objects.get(name='device1')
    phone.send_message(args, collapse_key='something')
Exemplo n.º 11
0
def send_android_push_notification(message):
    Device = get_device_model()
    Device.objects.all().filter(is_active=True).send_message(message)
Exemplo n.º 12
0
    def destroy(self, request, *args, **kwargs):

        device = get_device_model()
        device.objects.all().send_message({'DeletePoint': kwargs['pk']})

        return super(PollutionMarkViewSet, self).destroy(request, *args, **kwargs)