Ejemplo n.º 1
0
def getAppURLs(serverName):
    """
    :: Str -> []

    Given a domain like foo.webappworkshop.com,
    this builds a map of the urls.

    :param serverName: the SERVER_NAME from wsgi
    :return: the imported root module, or None
    """
    universal_api = REST.urlMap(
    [
        (r"/api/g/?$",
        {
            REST.get: CRUD.list_grids,
            REST.post: CRUD.create_grid
        }),
        (r"/api/g/(?P<table>\w+)/?$",
        {
            REST.get: CRUD.get_grid_meta,
            #put: CRUD.put_grid_meta,
            REST.post: CRUD.create_grid_row,
            #delete: CRUD.delete_grid
        }),
        (r"/api/g/(?P<table>\w+)/data/?$",
        {
            REST.get: CRUD.get_grid_data
        }),
        (r"/api/g/(?P<table>\w+)/(?P<id>\d+)/?$",
        {
            REST.get: CRUD.get_grid_row,
            REST.put: CRUD.put_grid_row,
            REST.delete: CRUD.delete_grid_row
        }),
    ])

    if serverName.startswith("localhost"):
        res = []
    else:
        res = universal_api
        cut = -1 if serverName.endswith("localhost") else -2

        appName = '.'.join(serverName.split('.')[:cut])
        logging.debug("appName is %r" % appName)

        if os.path.exists("app/%s/%s.py" % (appName, appName)):
            modname = 'app.%s.%s' % (appName, appName)
            exec 'import %s' % modname
            extras = getattr(eval(modname), 'urls', [])
            res.extend(extras)
        else:
            logging.debug("%s is not a valid app" % serverName)
    return res
Ejemplo n.º 2
0
 def getSoup(self, business):
     db_yelps = db.GqlQuery("SELECT * "
                                 "FROM Yelp "
                                 "WHERE venue_id = :1", business['id'])
     if db_yelps.count() == 0:
         url = business['url']
         if (url == None):
             logging.error(business['name'] + " No URL!")
             return 0
         html = REST.get(url)
         soup = BeautifulSoup(''.join(html))
         
         # db_yelp = Yelp(venue_id = business['id'],
         #                url = business['url'])
         # db_yelp.html = ''.join(''.join(html).splitlines())
         # db_yelp.put()
     else:
         db_yelp = db_yelps.get()
         soup = BeautifulSoup(db_yelp.html)
     return soup
Ejemplo n.º 3
0
    def render(self):
        self.req = {}
        self.req['lat'] = self.request.get("lat", default_value='40.73')
        self.req['lng'] = self.request.get("lng", default_value='-73.99')
        self.req['where'] = self.request.get("where") # do not provide a default value
        self.req['when'] = self.request.get("when", default_value=strftime('%m/%d/%Y'))
        self.req['local_meter'] = self.request.get("local", default_value='3')
        self.req['friend_print'] = self.request.get("social", default_value='3')
        self.req['popularity'] = self.request.get("popularity", default_value='3')
        self.req['price'] = self.request.get("price", default_value='3')
        self.req['time_of_day'] = self.request.get("timeofday", default_value='3')

        #req_lat = self.request.get("lat", default_value='40.73')
        #req_lng = self.request.get("lng", default_value='-73.99')
        #req_where = self.request.get("where")
        #req_when = self.request.get("when", default_value=strftime('%m/%d/%Y'))
        #req_local_meter = self.request.get("local", default_value='3')
        #req_friend_print = self.request.get("social", default_value='3')
        #req_popularity = self.request.get("popularity", default_value='3')
        #req_price = self.request.get("price", default_value='3')
        #req_time_of_day = self.request.get("timeofday", default_value='3')
        
        self.req['where'] = urllib.unquote(self.req['where']);
        self.req['when'] = urllib.unquote(self.req['when']);
        self.req['local_meter'] = urllib.unquote(self.req['local_meter']);
        self.req['friend_print'] = urllib.unquote(self.req['friend_print']);
        self.req['popularity'] = urllib.unquote(self.req['popularity']);
        self.req['price'] = urllib.unquote(self.req['price']);
        self.req['time_of_day'] = urllib.unquote(self.req['time_of_day']);
        
        #logging.error('req_lat: ' + str(req['lat']))
        #logging.error('req_lng: ' + str(req['lng']))
        #logging.error('req_where: ' + str(req['where']))
        #logging.error('req_when: ' + str(req_when))
        #logging.error('req_local_meter: ' + str(req_local_meter))
        #logging.error('req_friend_print: ' + str(req_friend_print))
        #logging.error('req_popularity: ' + str(req_popularity))
        #logging.error('req_price: ' + str(req_price))
        #logging.error('req_time_of_day: ' + str(req_time_of_day))

        #data = REST.getYelpVenues(self.req['lat'], self.req['lng'])
        
        logging.debug('QUERYING THE DATABASE FOR VENUES USING: ' + self.req['where'])
        db_venues = db.GqlQuery("SELECT * "
                                    "FROM Venue "
                                    "WHERE location_name = :1", self.req['where'])
        if db_venues.count() == 0:
            logging.debug('DID NOT FIND ANY VENUES WHILE QUERYING THE DATABASE FOR VENUES USING: ' + self.req['where'])
            data = REST.getYelpVenues(self.req['lat'], self.req['lng'], self.req['where'])
            #data = REST.getYelpVenues(req_lat, req_lng, req_where)
            jsonData = simplejson.loads(data)
            venues = self.prepYelpData(jsonData, False)
        else:
            logging.debug('FOUND SOME VENUES WHILE QUERYING THE DATABASE FOR VENUES USING: ' + self.req['where'])
            jsonData = {}
            businesses = []
            for db_venue in db_venues:
                business = {}
                business['name'] = db_venue.name
                business['id'] = db_venue.venue_id
                business['latitude'] = db_venue.lat
                business['longitude'] = db_venue.lng
                business['address1'] = db_venue.address_1
                business['address2'] = db_venue.address_2
                business['address3'] = db_venue.address_3
                business['photo_url'] = db_venue.image_url
                business['local'] = db_venue.local
                business['price'] = db_venue.price
                businesses.append(business)
            jsonData['businesses'] = businesses
            venues = self.prepYelpData(jsonData, True)

        json_result = {}
        json_result['venues'] = venues
        my_response = simplejson.dumps(json_result)
        self.response.out.write(my_response)
Ejemplo n.º 4
0
import threading

import allegro
import REST

thread = threading.Thread(target=allegro.allegro_service)
thread.start()

REST.run_app()
Ejemplo n.º 5
0
"""
URL map for tangentcode.
"""
from app.tangentcode import editor
import REST

urls = REST.urlMap([
    (r"/$", {
        REST.get: editor.showEditor }),
])
Ejemplo n.º 6
0
import time
import REST
import subprocess

# Run a constant cycle of checking for new recipets to process
while True:
    # Ping webserver for new reciept
    request = REST.checkTranmission()
    if request.status_code == 200:
        # A new reciept has been found!
        print("Reciept Found!")
        data = request.json()
        recipetID = data['recieptID']

        # Scan NFC for connection
        # Declare Var
        userID = ""

        # Run a sub program to access the NFC inteface and enable
        # Emulator mode
        print("starting subprocess")
        process = subprocess.Popen(['./nfc-emulate'],
                                   stdout=subprocess.PIPE,
                                   universal_newlines=True)

        # Get current subprocess status - Make sure it has not finished yet
        status = process.poll()

        while status is None:
            # Check the subprocess current runnning status
            status = process.poll()
Ejemplo n.º 7
0
class OutVar: value = None

def main(req, res):
    """
    :param weblib.Request req
    :param weblib.Response res
    """
    out = OutVar()
    if LOGIN.check(req, res, out):
        res.write(
            """
            <!doctype html>
            <html>
            <head>
              <title>webAppWorkshop</title>
            </head>
            <body>
              <h1>Hello, %s</h1>
              <p>Greetings from <strong>%s</strong>!</p>
            </body>
            </html>
            """
            % ( out.value.nickname(), req.host ))


urls = REST.urlMap([
    (r"/$", {
        REST.get: main }),
    ])