Пример #1
0
def entry(request):
    """ Guestbook API endpoint
        :param request: flask.Request object
        :return: flack.Response object (in JSON), HTTP status code
    """
    model = gbmodel.get_model()

    if request.method == 'POST' and request.headers[
            'content-type'] == 'application/json':
        request_json = request.get_json(silent=True)

        if all(key in request_json for key in ('name', 'email', 'message')):
            model = gbmodel.get_model()
            model.insert(request_json['name'], request_json['email'],
                         request_json['message'])
        else:
            raise ValueError("JSON missing name, email, or message property")

        entries = [
            dict(name=row[0], email=row[1], date=str(row[2]), message=row[3])
            for row in model.select()
        ]
        response = make_response(json.dumps(entries))
        response.headers['Content-Type'] = 'application/json'
        response.headers['Access-Control-Allow-Origin'] = '*'
        return response, 200

    if request.method == 'OPTIONS':
        return handle_cors('GET'), 200

    return abort(403)
    def post(self, id):
        """
        Accepts POST requests, and processes the form;
        Redirect to index when completed.
        id: Tagid of bag sent from sendText button
        It will lookup Client's IP and tracke GeoIP location, send message to registered user with IP GeoLocationa and TagID.
        """
        # Get Client/visitor's IP.
        if request.headers.getlist("X-Forwarded-For"):
            ip = request.headers.getlist("X-Forwarded-For")[0]
        else:
            ip = request.remote_addr

        # if app is running on localhost, it will get 127.0.0.1 which private ip and cannot find IpGeo data. So taking default PublicIP
        if ip == '172.17.0.1' or ip == '127.0.0.1':
            ip = '76.27.220.107'

        #look GeoDat from IP
        response = ipdata.lookup(ip)
        # From response we can get lot more Geo data, for here just taking CIty and Country.
        city = response['city']
        country_name = response['country_name']

        # Preparing text for sending message
        text = "Hello we found you bag with Tag: %s at City: %s, country: %s use by IP:%s !" % (
            str(id), str(city), str(country_name), str(ip))
        model = gbmodel.get_model()

        # sending text to below number for twilio client
        message = Client.messages.create(to="+19716786802",
                                         from_="+12679152751",
                                         body=text)
        return redirect(url_for('index'))
Пример #3
0
 def post(self):
     state_to_remove = request.form['state'].title()
     model = gbmodel.get_model()
     if model.delete(state_to_remove):
         return redirect(url_for('index'))
     else:
         return render_template('error.html')
Пример #4
0
    def post(self):
        """
        Accepts POST requests, and processes the form.
        Redirect to index when completed.
        """
        model = gbmodel.get_model()
        args = request.form
        # Ingredient list stored as a string, change to a list
        ingredients = args['ingredients'].split('\r\n')
        # API endpoint
        url = 'https://trackapi.nutritionix.com/v2/natural/nutrients'
        query = json.dumps({'query': ', '.join(ingredients)})
        headers = {
            'Content-Type': 'application/json',
            'x-app-key': '4a900d29f6416233ec26668100c24dc2',
            'x-app-id': '0f3a292c'
        }
        res = requests.post(url, headers=headers, data=query)
        if res.ok:  # 200 status code
            tooltip = self.get_nutrition(json.loads(res.text)['foods'])
        else:  # All others
            tooltip = 'Error acquiring nutritional information.'

        model.insert(args['title'], args['author'], ingredients,
                     int(args['time']), int(args['skill']),
                     args['description'], tooltip)
        return redirect(url_for('index'))
Пример #5
0
 def get(self):
     """
     Accepts GET request and renders the volunteers.
     """
     model = gbmodel.get_model()
     volunteers = [dict(name=row[0], expertise=row[1], phone_number=row[2], email=row[3], hours_offered=row[4] ) for row in model.select_volunteer()]
     return render_template('volunteer.html', volunteers=volunteers)
Пример #6
0
 def get(self):
     """
     get data from model
     """
     model = gbmodel.get_model()
     students = [dict(name=row[3]) for row in model.selectStudents()]
     return render_template('dashboard.html', students=students)
Пример #7
0
    def get(self):
        model = gbmodel.get_model()
        """dictionary of list and sqlite."""
        lang1 = 'zh'
        lang2 = 'ru'

        recipes = [
            dict(title=row[0],
                 author=row[1],
                 ingredient=row[2],
                 time=row[3],
                 skill=row[4],
                 description=row[5],
                 url=row[6],
                 url_description=self.detect_labels_uri(row[6]),
                 t_title=self.translate(row[0], lang1),
                 t_author=self.translate(row[1], lang1),
                 t_ingredient=self.translate(row[2], lang1),
                 t_time=self.translate(row[3], lang1),
                 t_skill=self.translate(row[4], lang1),
                 t_description=self.translate(row[5], lang1),
                 t2_title=self.translate(row[0], lang2),
                 t2_author=self.translate(row[1], lang2),
                 t2_ingredient=self.translate(row[2], lang2),
                 t2_time=self.translate(row[3], lang2),
                 t2_skill=self.translate(row[4], lang2),
                 t2_description=self.translate(row[5], lang2),
                 nutrition=self.nutritionix(row[2]),
                 yelp=self.yelpSearch(row[0])) for row in model.select()
        ]

        return render_template('index.html', rps=recipes)
	def get(movie):
		model = gbmodel.get_model()
		entries = [dict(title=row[0], year=row[1], genre=row[2], 
			rating=row[3], name=row[4], 
			the_date=row[5], review=row[6])
			for row in model.select()]
		return render_template('index.html', entries=entries)
Пример #9
0
 def get(self):
     model = gbmodel.get_model()
     entries = [
         dict(name=row[0], email=row[1], signed_on=row[2], message=row[3])
         for row in model.select()
     ]
     return render_template('index.html', entries=entries)
Пример #10
0
 def post(self):
     food_to_remove = request.form['food']
     model = gbmodel.get_model()
     if model.food_delete(food_to_remove):
         return redirect(url_for('index'))
     else:
         return render_template('error.html')
Пример #11
0
 def get(self):
     model = gbmodel.get_model()
     entries = [
             dict(name=row[0], street=row[1], city=row[2], state=row[3], \
             zipcode=row[4], hours=row[5], phone=row[6], rating=row[7], review=row[8], \
             foodtype=row[9], posted_on=row[10] ) for row in model.select()]
     return render_template('browse.html', entries=entries)
Пример #12
0
    def get(movie):
        model = gbmodel.get_model()

        #entries = [dict(title=row[0], year=row[1], genre=row[2],
        #rating=row[3], name=row[4],
        #the_date=row[5], review=row[6])
        #for row in model.select()]

        entries = [
            dict(title='Toy Story',
                 year='1995',
                 genre='Animated',
                 rating='5',
                 name='me',
                 the_date='7/18/2018',
                 review='Great Film'),
            dict(title='Avengers',
                 year='2012',
                 genre='Action',
                 rating='5',
                 name='Tom',
                 the_date='7/17/2018',
                 review='Solid Film')
        ]
        return render_template('reviews.html', entries=entries)
Пример #13
0
    def post(self):
        """
        Accepts POST requests, and processes the form;
        Redirect to index when completed.
        """
        model = gbmodel.get_model()
        model.insert(request.form['username'], request.form['bagcolor'], request.form['cellphone'], request.form['description'], tagid, request.form['status'])

        url = "http://api.qrserver.com/v1/create-qr-code/?data=" + "http://ilostmybags.ipq.co/sendtext/" + tagid + "&size=100x100"

        """
        This function takes in the url for the api request. 
        It fist removes all the files in the statisc folder with .jpg extension and then download the new jpg qr code and places it in the statis folder.
        """
        def download_image(url):
            location = os.getcwd() + "/static"
            onlyfiles = [f for f in listdir(location) if isfile(join(location, f))]

            for tryfile in onlyfiles:
                if ".jpg" in tryfile:
                    tryfile = location + "/" + tryfile
                    os.remove(tryfile)

            file = tagid + ".jpg"
            urllib.request.urlretrieve(url, file)
            shutil.move(file, location)

            return file

        image = download_image(url)

        return render_template('qr.html',embed_url=image)
Пример #14
0
 def post(self):
     """
     Accepts POST requests and gets the data from the form
     Redirect to index when completed.
     """
     model = gbmodel.get_model()
     model.removeTeam(request.form['teamID'], request.form['sessionID'])
     return redirect(url_for('removeTeam'))
Пример #15
0
 def post(self):
     """
     Accepts POST requests, and processes the form;
     Redirect to index when completed.
     """
     model = gbmodel.get_model()
     model.remove(request.form['title'])
     return redirect(url_for('index'))
Пример #16
0
 def get(self):
     model = gbmodel.get_model()
     entries = [
         dict(title=row[0], desc=row[1], prio=row[2])
         for row in model.select()
     ]
     offset = random.randint(0, 50)
     return render_template('todo.html', entries=entries)
Пример #17
0
 def get(self):
     """
     GET method for the shops page
     :return: renders the shops.html page on return
     """
     model = gbmodel.get_model()
     shops = [dict(name=row[0], street=row[1], city=row[2], state=row[3], zip=row[4], open_hr=row[5],
                     close_hr=row[6], phone=row[7], drink=row[8], rating=row[9], website=row[10]) for row in model.select()]
     return render_template('shops.html', shops=shops)
Пример #18
0
    def post(self):
        """
        POST method for the shops page. Deletes an entry from the db when called.
        :return: renders the shops.html page on return
        """
        model = gbmodel.get_model()
        model.delete(request.form['name'])

        return redirect(url_for('shops'))
Пример #19
0
 def post(self):
     """
     Accepts POST requests, processes the request,
     and then redirects to the Todo page
     """
     model = gbmodel.get_model()
     model.insert(request.form['title'], request.form['desc'],
                  request.form['prio'])
     return redirect(url_for('todo'))
Пример #20
0
 def post(self):
     """
     Accepts POST requests and gets the data from the form
     Redirect to index when completed.
     """
     model = gbmodel.get_model()
     model.insertStudent(request.form['studentName'], request.form['studentID'], 
     request.form['sessionID'], request.form['teamID'])
     return redirect(url_for('addStudent'))
Пример #21
0
 def post(self):
     """
     Accepts POST requests, and processes the form;
     Redirect to index when completed.
     """
     model = gbmodel.get_model()
     model.insert(request.form['name'], request.form['email'],
                  request.form['message'])
     return redirect(url_for('index'))
Пример #22
0
 def post(self):
     """
     Accepts POST requests, and processes the form;
     Redirect to index when completed.
     """
     model = gbmodel.get_model()
     model.insert(request.form['title'], request.form['author'],
                  request.form['ingredient'], request.form['time'],
                  request.form['skill'], request.form['description'])
     return redirect(url_for('index'))
Пример #23
0
 def post(self):
     """
     Accepts POST requests, and processes the form;
     Redirect to index when completed.
     """
     model = gbmodel.get_model()
     model.insert(request.form['name'], request.form['street'], request.form['city'], request.form['state'],
                  request.form['zip'], request.form['open_hr'], request.form['close_hr'], request.form['phone'],
                  request.form['website'], request.form['drink'], request.form['rating'])
     return redirect(url_for('shops'))
Пример #24
0
 def get(self):
     model = gbmodel.get_model()
     recipes = [
         dict(title=row[0],
              author=row[1],
              ingredients=row[2],
              time=row[3],
              skill=row[4],
              description=row[5]) for row in model.select()
     ]
     return render_template('recipes.html', recipes=recipes)
Пример #25
0
 def get(self):
     model = gbmodel.get_model()
     entries = [
         dict(username=row[0],
              bagcolor=row[1],
              cellphone=row[2],
              description=row[3],
              tagid=row[4],
              status=row[5]) for row in model.select()
     ]
     return render_template('viewtag.html', entries=entries)
Пример #26
0
 def post(self):
     """
     Accepts POST requests, and processes the form.
     Redirect to index when completed.
     """
     model = gbmodel.get_model()
     args = request.form
     model.insert(args['title'], args['author'],
                  args['ingredients'].split('\r\n'), int(args['time']),
                  int(args['skill']), args['description'])
     return redirect(url_for('index'))
Пример #27
0
 def get(self):
     model = gbmodel.get_model()
     favorite = []
     count = 0
     for row in model.select():
         count += 1
         favorite.append(dict(id=row[0], name=row[1], weight=row[2], height=row[3],\
             bred_for=row[4], breed_group=row[5], life_span=row[6], temperament=row[7], \
             origin=row[8], date_submitted=row[9], image=row[10]))
     print(count)
     return render_template('favorite.html', favorite=favorite)
Пример #28
0
 def post(self):
     """
     Accepts POST requests, and processes the form;
     Redirects to form page when completed.
     """
     model = gbmodel.get_model()
     model.insert(request.form['name'], request.form['street'],
                  request.form['city'], request.form['state'],
                  request.form['zipcode'], request.form['hours'],
                  request.form['phone'], request.form['rating'],
                  request.form['review'], request.form['foodtype'])
     return redirect(url_for('form'))
Пример #29
0
 def post(self):
     """
     Accepts POST requests, and processes the form;
     Redirect to index when completed.
     """
     model = gbmodel.get_model()
     model.insert(request.form['name'], request.form['staddr'],
                  request.form['city'], request.form['state'],
                  request.form['zipcode'], request.form['storehours'],
                  request.form['phonenumber'], request.form['rating'],
                  request.form['menu'], request.form['review'])
     return redirect(url_for('index'))
Пример #30
0
 def post(self):
     """
     Accepts POST requests and gets the data from the form
     Redirect to search when completed.
     """
     model = gbmodel.get_model()
     breed_name = request.form.get('selected_breed') 
     breed_image = request.form.get('selected_image') 
     breeds, info, photo = api.info(breed_name)
     db_info = api.db_info(info, photo)
     model.insert(db_info)
     return render_template('result.html', selected_breed=breed_name, breeds=breeds, image=breed_image, selected_info=info)