Exemple #1
0
def create_venue(request):
    if request.method == 'POST':
        f = VenueForm(request.POST)
        if f.is_valid():
            logging.info("Form valid")
            (start_date, end_date) = f.cleaned_data['valid_dates'].split(" - ")

            venue = Venue(
                name=f.cleaned_data['name'],
                address=db.PostalAddress(
                    '%s, %s, %s %s' %
                    (f.cleaned_data['street'], f.cleaned_data['city'],
                     f.cleaned_data['state'], f.cleaned_data['zip'])),
                location=db.GeoPt(f.cleaned_data['latitude'],
                                  f.cleaned_data['longitude']),
                start_date=datetime.datetime.strptime(start_date,
                                                      "%m/%d/%Y").date(),
                end_date=datetime.datetime.strptime(end_date,
                                                    "%m/%d/%Y").date())
            venue.update_location()
            venue.put()

            return redirect(venues)
    else:
        f = VenueForm()

    context = {
        'title': 'Fanmento Administration - Create Venue',
        'name': request.user.email,
        'form': f,
        'active': 'venues',
    }
    context.update(csrf(request))

    return render_to_response('venues_new.html', context)
Exemple #2
0
 def harvest_yelp_friends(self, social_account):
     """ Harvest friend data from Twitter """
     
     # Build connector
     yelp_connector = connectors.yelp.YelpConnector()           
     
     # Lets try this...build list of all friend ids
     friend_id_list = []
     q = db.GqlQuery("SELECT __key__ FROM SocialFriend WHERE social_account = :1", social_account)
     for friend_key in q:
         friend_id_list.append(datamodel.SocialFriend.get(friend_key).social_account_item_id)
                
     # Get friends
     friend_list = yelp_connector.get_friends(social_account.user_id)
     
     # Iterate through friends
     for friend in friend_list:
          
         if (friend.user_id not in friend_id_list):
             social_friend = datamodel.SocialFriend(user=social_account.user,
                                                    social_account=social_account,
                                                    social_account_item_id=friend.user_id,
                                                    display_name=friend.display_name,
                                                    location = db.PostalAddress(friend.location))
             social_friend.put()  
     pass
Exemple #3
0
    def test_entity_to_dict(self):
        """Converts a datastore.Entity instance to a JSON encodable dict."""

        from datetime import datetime
        from gaesynkit import handlers
        from google.appengine.api import datastore
        from google.appengine.api import datastore_types
        from google.appengine.api import users
        from google.appengine.ext import db

        entity = datastore.Entity("Test")
        entity.update({
            "string": "A string.",
            "byte_string": datastore_types.ByteString("Byte String"),
            "boolean": True,
            "int": 42,
            "float": 1.82,
            "date": datetime(2011, 01, 06),
            "list": [1, 2, 3, 4],
            "key": db.Key.from_path("Kind", "name"),
            "user": users.User("*****@*****.**"),
            "email": db.Email("*****@*****.**"),
            "location": db.GeoPt(52.500556, 13.398889),
            "category": db.Category("coding"),
            "link": db.Link("http://www.google.com"),
            "im": db.IM("sip", "foobar"),
            "phone": db.PhoneNumber("1 (206) 555-1212"),
            "address": db.PostalAddress("Address"),
            "rating": db.Rating(99)
        })
def get(requestHandler):
    request = requestHandler.request
    kind = request.get("kind")
    if not kind:
        print "false"
    query = datastore.Query(kind)
    order = None
    order_type = None
    if order and order_type:
        order_type = DataType.get_by_name(order_type).python_type()
        if order.startswith('-'):
            direction = datastore.Query.DESCENDING
            order = order[1:]
        else:
            direction = datastore.Query.ASCENDING
        try:
            query.Order((order, order_type, direction))
        except datastore_errors.BadArgumentError:
            pass

    start = 0
    num = 1
    total = query.Count()
    logging.info(total)

    entities = query.Get(start + total)[start:]
    logging.info("****************")
    for entity in entities:
        counter = 0
        requestHandler.response.out.write("insert into " + kind.lower() + " (")
        for key, value in entity.items():
            logging.info(type(db.PostalAddress()))
            if type(value) != type(db.Key()) and value:
                #keep out heading comma
                if counter > 0:
                    requestHandler.response.out.write(", ")

                requestHandler.response.out.write(key)
                counter = counter + 1
        requestHandler.response.out.write(") values (")
        counter = 0
        for key, value in entity.items():
            if type(value) != type(db.Key()) and value:

                #keep out heading comma
                if counter > 0:
                    requestHandler.response.out.write(", ")

                if type(value) == type(u'') or type(value) == type(""):
                    requestHandler.response.out.write("'")
                    requestHandler.response.out.write(value.replace(
                        "'", "\\'"))
                    requestHandler.response.out.write("'")
                else:
                    requestHandler.response.out.write(value)

                counter = counter + 1
        requestHandler.response.out.write(");")
        requestHandler.response.out.write("<br><br>")
Exemple #5
0
	def createEventsFromJSON(self, eventsFullJSON):
		eventsList = []
		eventsJSON = eventsFullJSON['events']['event']
		
		for eventJSON in eventsJSON:
			event = Event()
			event.eventID = int(eventJSON['id'])
			event.eventTitle = eventJSON['title']
			
			artistsJSON = eventJSON['artists']
			event.artists = self.createStrList(artistsJSON['artist'])
			event.headliner = artistsJSON['headliner']
			
			venueJSON = eventJSON['venue']
			event.venueID = int(venueJSON['id'])
			event.venueName = venueJSON['name']
			
			locJSON = venueJSON['location']
			geoJSON = locJSON['geo:point']
			address, geoPt = self.parseAddress(locJSON['street'], locJSON['city'], locJSON['country'], locJSON['postalcode'])
			if geoPt == None:
				geoPt = db.GeoPt(geoJSON['geo:lat'], geoJSON['geo:long'])
			event.geoPt = geoPt
			event.venueAddress = db.PostalAddress(address)
			
			event.venueURL = self.createLink(venueJSON['url'])
			event.venueWebsite = self.createLink(venueJSON['website'])
			event.venuePhoneNumber = self.createPhoneNumber(venueJSON['phonenumber'])
			event.venueImageURLs = self.getImageURLs(venueJSON['image'])
			
			# Sample date string: "Mon, 02 May 2011 22:00:00"
			formatStr = '%a, %d %b %Y %H:%M:%S'
			event.date = datetime.strptime(eventJSON['startDate'], formatStr)
			event.eventDescription = eventJSON['description']
			event.eventImageURLs = self.getImageURLs(eventJSON['image'])
			event.eventAttendance = int(eventJSON['attendance'])
			event.eventReviews = int(eventJSON['reviews'])
			event.eventTag = eventJSON['tag']
			event.eventURL = self.createLink(eventJSON['url'])
			event.eventWebsite = self.createLink(eventJSON['website'])
			event.eventTickets = str(eventJSON['tickets'])
			event.eventCancelled = bool(int(eventJSON['cancelled']))
			
			try:
				event.tags = self.createStrList(eventJSON['tags']['tag'])
			except KeyError:
				pass
			
			eventsList.append(event)
		
		return eventsList
Exemple #6
0
 def harvest_yelp_reviews(self, social_account):
     """ Harvest yelp reviews and put into data model """
     
     # Build connector
     yelp_connector = connectors.yelp.YelpConnector()        
     
     last_review_date = None
     review_id_list = []
     
     # Get most recent review date
     q = datamodel.SocialReview.gql('WHERE social_account = :1 ORDER BY review_date DESC LIMIT 1', social_account)
     
     
     last_social_review = q.get()
     
     # Do we have data... then pull from last post
     if last_social_review:
         last_review_date = last_social_review.review_date
         
         # Load reviews on that review_date so we can check to see if we reloaded them in this last harvest
         q = db.GqlQuery("SELECT __key__ FROM SocialReview WHERE social_account = :1 AND review_date = :2", social_account, last_review_date)
         for review_key in q:
             review_id_list.append(datamodel.SocialReview.get(review_key).social_account_item_id)
         
         
     # Call Yelp
     review_list = yelp_connector.get_reviews(social_account.user_id, last_review_date)
     
     # Iterate through and store in db... lets check against 
     for review in review_list:
     
         if (review.review_id not in review_id_list):
             
             social_review = datamodel.SocialReview(user = social_account.user,
                                                    social_account = social_account,
                                                    social_account_item_id = review.review_id,
                                                    full_business_name = review.business_name,
                                                    business_address = db.PostalAddress(review.business_address),
                                                    social_account_business_id = review.business_id,
                                                    review_rating = db.Rating(review.rating*4),
                                                    review_date = review.review_date,
                                                    review_text = review.review)
             
             # Build category list
             for c in review.category_list:
                 social_review.business_category_list.append(c)
             
             social_review.put()
    def post(self):
        self.log.info(self.request.POST)
        if self.request.get('winery_submit'):
            m = self.toTime(self.request.get('monday'))
            t = self.toTime(self.request.get('tuesday'))
            w = self.toTime(self.request.get('wednesday'))
            th = self.toTime(self.request.get('thursday'))
            f = self.toTime(self.request.get('friday'))
            s = self.toTime(self.request.get('saturday'))
            su = self.toTime(self.request.get('sunday'))
            h = WeeklyHours(monday=m,
                            tuesday=t,
                            wednesday=w,
                            thursday=th,
                            friday=f,
                            saturday=s,
                            sunday=su).put()

            lat_long = self.request.get('location').split(',')
            loc = db.GeoPt(float(lat_long[0].strip()),
                           float(lat_long[1].strip()))

            blb = db.Blob(self.request.get('picture').encode('base64'))

            Winery(name=self.request.get('name'),
                   description=self.request.get('description'),
                   email=self.request.get('email'),
                   phone=self.request.get('phone'),
                   location=loc,
                   hours=h,
                   image=blb,
                   address=db.PostalAddress(self.request.get('address')),
                   rating=db.Rating(int(self.request.get('rating')))).put()
        else:
            wineryKey = db.Key.from_path('Winery',
                                         int(self.request.get("winery_id")))
            sdate = datetime.datetime.strptime(self.request.get("start_date"),
                                               '%Y/%m/%d')
            edate = datetime.datetime.strptime(self.request.get("end_date"),
                                               '%Y/%m/%d')
            Event(name=self.request.get("name"),
                  description=self.request.get("description"),
                  winery=wineryKey,
                  startDate=sdate,
                  startTime=self.request.get("start_time").strip(),
                  endDate=edate,
                  endTime=self.request.get("end_time").strip()).put()
        self.redirect('/')
Exemple #8
0
    def harvest_facebook_events(self, social_account):
        """ Harvest the event from facebook and put into SocialEvent object """
        
        # Connect to facebook
        fb_connector = connectors.facebook.FacebookConnector(app_id = config.FACEBOOK_API_APP_ID,
                                                             app_secret = config.FACEBOOK_API_APP_SECRET,
                                                             app_url = config.APP_URL,
                                                             graph_url = config.FACEBOOK_API_GRAPH_URL,
                                                             oauth_url = config.FACEBOOK_API_OAUTH_URL) 
                 
        
        # Call FB
        json_events = fb_connector.get_events(social_account.user_id, social_account.access_token)


        # Lets try this...build list of all item ids
        item_id_list = []
        q = db.GqlQuery("SELECT __key__ FROM SocialEvent WHERE social_account = :1", social_account)
        for item_key in q:
            item_id_list.append(datamodel.SocialEvent.get(item_key).social_account_item_id)

        
        # Parse and put into DB
        for event in json_events['data']:
            #query_check = datamodel.SocialEvent.gql('WHERE social_account = :1 AND social_account_item_id = :2', social_account, event['id'])    
            #if (query_check.count() == 0):
            if (event['id'] not in item_id_list):
                social_event = datamodel.SocialEvent(user=social_account.user,
                                                   social_account=social_account,
                                                   social_account_item_id=event['id'],
                                                   name=event['name'],
                                                   location_text=event['location'],
                                                   location_address=db.PostalAddress(event['location']),
                                                   start_time=datetime.datetime.strptime(event['start_time'], "%Y-%m-%dT%H:%M:%S+0000"),
                                                   end_time=datetime.datetime.strptime(event['end_time'], "%Y-%m-%dT%H:%M:%S+0000"),
                                                   rsvp=event['rsvp_status'])
                                                    
                social_event.put()                
Exemple #9
0
    float=5.05,
    datetime=d,
    date=d.date(),
    time=d.time(),
    list=[1, 2, 3],
    strlist=["hello", u'world'],
    user=users.User("*****@*****.**"),
    blob=db.Blob("somerandomdata"),
    text=db.Text("some random text"),
    category=db.Category("awesome"),
    link=db.Link("http://www.10gen.com"),
    email=db.Email("*****@*****.**"),
    geopt=db.GeoPt(40.74067, -73.99367),
    im=db.IM("http://aim.com/", "example"),
    phonenumber=db.PhoneNumber("1 (999) 123-4567"),
    postaladdress=db.PostalAddress("40 W 20th St., New York, NY"),
    rating=db.Rating(99),
)
out = db.get(e1.put())


def failIfNot(reference, value, type):
    assert value == reference
    assert isinstance(value, type)


failIfNot(e1.str, out.str, types.UnicodeType)

failIfNot(e1.bool, out.bool, types.BooleanType)

# TODO on AE this would always be types.LongType