Exemple #1
0
    def sms_command(self, message=None):
        """Subscribe the user to a offline SMS"""

        plist = message.body.split(' ')
	if len(plist)==3:
	        user = message.sender.split('/')[0]
	 	service_name = plist[1]
	 	number = plist[2]
	
	        service = Service.all().filter('name = ', service_name).get()
	
	        if service:
		 	subscription = Subscription.all().filter('address =', user).filter('service = ', service).get()
		
		        if subscription:
		            mobile = Mobile.all().filter('number =', number).get()
		            if mobile:
		                message.reply("user %s is already registered backup mobile %s for service %s" % (user, mobile.number,service_name))
		            else:
		                mobile = Mobile(number=number, subscription = subscription)
		                mobile.put()
		                message.reply("Subscribed user %s to backup mobile %s for service %s" % (user, number,service_name))
		        else:
		            message.reply("Sorry, I couldn't find a subscription on %s for %s" % (service_name,user))
	        else:
	            message.reply("Sorry, I couldn't find a service called "
	                          "%s" % service_name)
	else:
		message.reply("Usage: sms SERVICE +61412345678")
Exemple #2
0
    def unsub_command(self, message=None):
        """Unsubscribe the user from a service"""
        user = message.sender.split('/')[0]

        plist = message.body.split(' ' )
        service_name = plist[1]

	if len(plist)>2:
	    type = "sms"
            user = plist[2]
	else:
	    type = "xmpp"
		
        service = Service.all().filter('name = ', service_name).get()

        if service:
            subscription = Subscription.all().filter('address =', user).filter('service = ', service).filter('type =', type).get()
            if subscription:
                subscription.delete()
		if type == "xmpp":
	            	mobile = Mobile.all().filter('subscription = ', subscription).get()
			if mobile:
				mobile.delete()
                message.reply("Unsubscribed %s from service %s" % (user, service.name))
            else:
                message.reply("user %s is not subscribed to service %s" % (user, service.name))
        else:
            message.reply("Sorry, I couldn't find a service called "
                          "%s" % service_name)
Exemple #3
0
    def unsms_command(self, message=None):
        """Unsubscribe the user from a service"""
	plist = message.body.split(' ')
	if len(plist)==2:
	        user = message.sender.split('/')[0]
	
	        service_name = plist[1]
	
	        service = Service.all().filter('name = ', service_name).get()
	
	        if service:
		    subscription = Subscription.all().filter('address =', user).filter('service = ', service).get()
		
		    if subscription:
	            	mobile = Mobile.all().filter('subscription = ', subscription).get()
	            	if mobile:
		    	    message.reply("Unsubscribed user %s from backup mobile %s for service %s" % (user, mobile.number,service_name))
	            	    mobile.delete()
			else:
			    message.reply("No backup mobile for user %s on %s service" % (user,service_name))
	 	    else:
	            	message.reply("User %s is not subscribed to service %s" % (user, service.name))
	        else:
	            message.reply("Sorry, I couldn't find a service called "
                          "%s" % service_name)
	else:
		 message.reply("Usege: unsms SERVICE +6112345678")
def mobiles(request):
    #connect to our local mongodb
    client = MongoClient('localhost',27017)
    #get a connection to our database
    db = client['gsmarena']
    mobileCollection = db['phones_test']

    if request.method == 'GET':
        #get our collection
        mobiles = []
        camera = int(request.query_params['camera'])
        ram = int(request.query_params['ram'])
        storage = int(request.query_params['storage'])
        battery = int(request.query_params['battery'])
        list1 = mobileCollection.find()
        newlist = sorted(list1, key=lambda k: ((camera * int(k['camera']))/8) + ((battery * int(k['battery']))/2100) +
                                              ((ram * int(k['ram']))/2) + ((storage * int(k['storage']))/8),
                         reverse=True)
        for r in newlist:
            mobile = Mobile(r["url"],r["name"],r["camera"],r["ram"],r["storage"],r["battery"])
            mobiles.append(mobile)
        serializedList = mobileSerializer(mobiles, many=True)
        # print serializedList
        return Response(serializedList.data)
    elif request.method == 'POST':
        pass
    def restore_object(self, attrs, instance=None):
        if instance:
            instance.url = attrs.get('url', instance.url)
            instance.name = attrs.get('name', instance.name)
            instance.camera = attrs.get('camera', instance.camera)
            instance.ram = attrs.get('ram', instance.ram)
            instance.storage = attrs.get('storage', instance.storage)
            instance.battery = attrs.get('battery', instance.battery)
            return instance

        return Mobile(attrs.get('url'), attrs.get('name'), attrs.get('camera'), attrs.get('ram'), attrs.get('storage'),
                      attrs.get('battery'))
Exemple #6
0
 def test_mobile(self):
     """Test the mobile model."""
     mobile = Mobile()
     mobile.make = 'Make'
     mobile.model = 'Model'
     mobile.year = 1999
     mobile.save()
Exemple #7
0
 def test_delete(self):
     """Test sending an delete request method."""
     mobile = Mobile()
     mobile.make = 'Make'
     mobile.model = 'Model'
     mobile.year = 2016
     mobile.save()
     obj = {'id': 1}
     request = mock.Mock(
         method='DELETE',
         body=json.dumps(obj)
     )
     response = MobileView.as_view()(request)
     self.assertEquals(response.status_code, 200)
Exemple #8
0
    def post(self, version, service_slug):
        if not self.valid_version(version):
            self.error(404, "API Version %s not supported" % version)
            return

        status_slug = self.request.get("status", default_value=None)
        message = self.request.get("message", default_value=None)
        informational = self.request.get("informational", default_value=None)

        if not message:
            self.error(400, "Event message is required")
            return

        service = Service.get_by_slug(service_slug)

        if not service:
            self.error(404, "Service %s not found" % service_slug)
            return

        last_event = service.current_event()
        if last_event:
            old_status = last_event.status

        if not status_slug:
            if last_event:
                status = old_status
            else:
                status = Status.get_default()
        else:
            status = Status.get_by_slug(status_slug)

        if not status:
            self.error(404, "Status %s not found" % status_slug)
            return

        e = Event(status=status, service=service, message=message)
        e.informational = informational and informational == "true"
        e.put()

        # Queue up a task that calls the Twitter API to make a tweet.
        if self.request.get('tweet'):
            logging.info('Attempting to post a tweet for the latest event via async GAE task queue.')
            taskqueue.add(url='/admin/tweet', params={'service_name': service.name, 'status_name': status.name, 'message': message})
        # Queue up tasks for notifing subscribers via XMPP
        if service.subscriptions:
	    for subscription in service.subscriptions.filter("type =","xmpp"):
	        mobile = Mobile.all().filter('subscription = ', subscription).get()
		if mobile:
			mobile_number = mobile.number
		else:
			mobile_number = False
                params={'address': subscription.address, 'service':
                        service.key(), 'oldstatus': old_status.key(), 'number': mobile_number}
                logging.info("Adding deferred task: %s %s" % (
                    subscription.type, params))
                taskqueue.add(url='/notify/' + subscription.type, params=params)
        else:
            logging.info("No subscriptions for %s" % service.name)

        invalidate_cache()
        self.json(e.rest(self.base_url(version)))