Beispiel #1
0
 def post(self, event_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     original_master = fusion_tables.select_first(configuration['master table'], condition="'event slug' = '%s'" % event_slug)[0]
     data = self.request.POST['data']
     master = json.loads(data)
     master['location slug'] = location_slug(master)
     # check if the new location is in use, if so, reuse it's location slug
     same_location_condition = "ST_INTERSECTS('latitude', CIRCLE(LATLNG(%f,%f),2))" % (round(float(master['latitude']), 5), round(float(master['longitude']), 5))  # 3 meter
     same_location = fusion_tables.select_first(configuration['master table'], condition=same_location_condition)
     if same_location:
         logging.info("Using the location slug of an existing location [%s] instead of [%s]" % (same_location[0]['location slug'], master['location slug']))
         master['location slug'] = same_location[0]['location slug']
     else:
         base_location_slug = location_slug(master)
         logging.info("This is a new location [%s]" % base_location_slug)
         master['location slug'] = base_location_slug
         # add (1) or (2) or etc... to the location slug if it's already in use
         while fusion_tables.select_first(configuration['master table'], condition="'location slug' = '%s'" % master['location slug']):
             logging.info("Adding (1), (2),... to location slug [%s] because it already existed." % master['location slug'])
             counter = 1 if 'counter' not in locals() else counter + 1
             master['location slug'] = base_location_slug + '-(' + str(counter) + ')'
     if master['location slug'] != original_master['location slug']:
         # otherwise the old location and event remains visible because the FT layer cannot filter them out
         logging.info("Starting task on queue for deleting old versions of moved event %s" % original_master['event slug'])
         taskqueue.add(method="GET", url='/sync/old_version_of_updated_events/%s?id=%s' % (original_master['event slug'], configuration['id']))
     master['state'] = 'updated'
     master['sequence'] = int(original_master['sequence']) + 1
     master['entry date'] = original_master['entry date']
     master['update date'] = datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['update after sync'] = 'true'  # this will trigger sync_old_version_of_updated_events()
     master['renewal date'] = (datetime.today() + timedelta(days=30 * 6)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['event slug'] = original_master['event slug']
     master['hashtags'] = ','.join(["#%s#" % slugify(tag) for tag in extract_hash_tags(master['description'])])
     master['rowid'] = original_master['rowid']
     fusion_tables.update_with_implicit_rowid(configuration['master table'], master)
     sync.sync_updated_events(configuration, condition="'event slug' = '%s'" % master['event slug'])
     logging.info("LIST_OF_UPDATED_ROWS [%s] [%s] %s" % (configuration['id'], master['update date'], data))
     sender = 'info@%s.appspotmail.com' % (app_id)
     message = mail.EmailMessage(sender=sender, to="*****@*****.**")
     message.subject = "Event updated in MapTiming %s" % configuration['title']
     message.body = "http://%s.maptiming.com#event/%s" % (configuration['id'], master['event slug'])
     logging.info("Sending mail from %s: %s - %s" % (sender, message.subject, message.body))
     message.send()
     # return the web-page content
     self.response.out.write(master['event slug'])
     return
def random_master(configuration=None):
    master = {}
    start = datetime(2014, randint(1, 12), randint(1, 28), randint(8, 20), 0, 0)
    master['start'] = start.strftime(FUSION_TABLE_DATE_TIME_FORMAT)
    master['description'] = random_text(sentences=1)
    master['contact'] = "*****@*****.**" % random_text(words=1)
    master['website'] = "http://www.%s.com" % random_text(words=1)
    master['registration required'] = 'true' if randint(0, 1) == 1 else 'false'
    master['owner'] = "*****@*****.**" % random_text(words=1)
    master['moderator'] = "*****@*****.**" % random_text(words=1)
    master['state'] = "new"
    master['sequence'] = "0"
    master['entry date'] = datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT)
    master['update date'] = datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT)
    master['renewal date'] = (datetime.today() + timedelta(days=30 * 6)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
    master['location name'] = random_text(words=randint(1, 4))
    postal_code = randint(1000,9999)
    master['address'] = "%s %d, %d %s" % (random_text(words=1), randint(1,100), postal_code, random_text(words=1))
    master['postal code'] = postal_code
    master['latitude'] = float(randint(50734, 51444)) / 1000
    master['longitude'] = float(randint(2547, 5840)) / 1000
    master['location slug'] = location_slug(master)
    master['location details'] = random_text(words=randint(0,4))
    if configuration:
        master['tags'] = random_tags(configuration['tags'])
    else:
        master['tags'] = ''
    master['hashtags'] = random_text(words=randint(0, 1))
    # second
    multi_day = True if randint(1, 10) < 2 else False
    if multi_day:
        master['end'] = (start + timedelta(hours=randint(0, 3), days=randint(1, 7))).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
        master['calendar rule'] = ''
    else:
        master['end'] = (start + timedelta(hours=randint(1, 3))).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
        chance = randint(1, 10)
        if chance < 3:
            master['calendar rule'] = "RRULE:FREQ=DAILY;UNTIL=%s" % (start + timedelta(days=30 * 6)).strftime(ISO_DATE_TIME_FORMAT)
        elif chance < 7:
            master['calendar rule'] = "RRULE:FREQ=WEEKLY;BYDAY=%s;COUNT=16" % {0: 'MO', 1: 'TU', 2: 'WE', 3: 'TH', 4: 'FR', 5: 'SA', 6: 'SU'}[start.weekday()]
        else:
            master['calendar rule'] = "RRULE:FREQ=MONTHLY;BYMONTHDAY=%d" % start.day
    master['event name'] = "%s %s" % (master['location name'], master['calendar rule'])
    master['event slug'] = event_slug(master)
    return master
Beispiel #3
0
 def post(self):
     configuration = customer_configuration.get_configuration(self.request)
     data = self.request.POST['data']
     master = json.loads(data)
     # check if the location is in use, if so, reuse it's location slug
     same_location_condition = "ST_INTERSECTS('latitude', CIRCLE(LATLNG(%f,%f),2))" % (round(float(master['latitude']), 5), round(float(master['longitude']), 5))  # 3 meter
     same_location = fusion_tables.select_first(configuration['master table'], condition=same_location_condition)
     if same_location:
         logging.info("Using the location slug of an existing location [%s] instead of [%s]" % (same_location[0]['location slug'], master['location slug']))
         master['location slug'] = same_location[0]['location slug']
     else:
         base_location_slug = location_slug(master)
         logging.info("This is a new location [%s]" % base_location_slug)
         master['location slug'] = base_location_slug
         # add (1) or (2) or etc... to the location slug if it's already in use
         while fusion_tables.select_first(configuration['master table'], condition="'location slug' = '%s'" % master['location slug']):
             logging.info("Adding (1), (2),... to location slug [%s] because it already existed." % master['location slug'])
             counter = 1 if 'counter' not in locals() else counter + 1
             master['location slug'] = base_location_slug + '-(' + str(counter) + ')'
     master['state'] = 'new'
     master['sequence'] = 1
     master['entry date'] = datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['update date'] = datetime.today().strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['renewal date'] = (datetime.today() + timedelta(days=30 * 6)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     base_event_slug = event_slug(master)
     master['event slug'] = base_event_slug
     # add (1) or (2) or etc... to the event slug if it's already in use
     while fusion_tables.select_first(configuration['master table'], condition="'event slug' = '%s'" % master['event slug']):
         counter = 1 if 'counter' not in locals() else counter + 1
         master['event slug'] = base_event_slug + '-(' + str(counter) + ')'
     # hashtags
     master['hashtags'] = ','.join(["#%s#" % slugify(tag) for tag in extract_hash_tags(master['description'])])
     fusion_tables.insert(configuration['master table'], master)
     sync.sync_new_events(configuration, condition="'event slug' = '%s'" % master['event slug'])
     logging.info("LIST_OF_ADDED_ROWS [%s] [%s] %s" % (configuration['id'], master['update date'], data))
     sender = 'info@%s.appspotmail.com' % (app_id)
     message = mail.EmailMessage(sender=sender, to="*****@*****.**")
     message.subject = "New event added to MapTiming %s" % configuration['title']
     message.body = "http://%s.maptiming.com#event/%s" % (configuration['id'], master['event slug'])
     logging.info("Sending mail from %s: %s - %s" % (sender, message.subject, message.body))
     message.send()
     # return the web-page content
     self.response.out.write(master['event slug'])
     return
Beispiel #4
0
 def post(self, event_slug=None):
     configuration = customer_configuration.get_configuration(self.request)
     original_master = fusion_tables.select_first(
         configuration['master table'],
         condition="'event slug' = '%s'" % event_slug)[0]
     data = self.request.POST['data']
     master = json.loads(data)
     master['location slug'] = location_slug(master)
     # check if the new location is in use, if so, reuse it's location slug
     same_location_condition = "ST_INTERSECTS('latitude', CIRCLE(LATLNG(%f,%f),2))" % (
         round(float(master['latitude']),
               5), round(float(master['longitude']), 5))  # 3 meter
     same_location = fusion_tables.select_first(
         configuration['master table'], condition=same_location_condition)
     if same_location:
         logging.info(
             "Using the location slug of an existing location [%s] instead of [%s]"
             % (same_location[0]['location slug'], master['location slug']))
         master['location slug'] = same_location[0]['location slug']
     else:
         base_location_slug = location_slug(master)
         logging.info("This is a new location [%s]" % base_location_slug)
         master['location slug'] = base_location_slug
         # add (1) or (2) or etc... to the location slug if it's already in use
         while fusion_tables.select_first(
                 configuration['master table'],
                 condition="'location slug' = '%s'" %
                 master['location slug']):
             logging.info(
                 "Adding (1), (2),... to location slug [%s] because it already existed."
                 % master['location slug'])
             counter = 1 if 'counter' not in locals() else counter + 1
             master['location slug'] = base_location_slug + '-(' + str(
                 counter) + ')'
     if master['location slug'] != original_master['location slug']:
         # otherwise the old location and event remains visible because the FT layer cannot filter them out
         logging.info(
             "Starting task on queue for deleting old versions of moved event %s"
             % original_master['event slug'])
         taskqueue.add(method="GET",
                       url='/sync/old_version_of_updated_events/%s?id=%s' %
                       (original_master['event slug'], configuration['id']))
     master['state'] = 'updated'
     master['sequence'] = int(original_master['sequence']) + 1
     master['entry date'] = original_master['entry date']
     master['update date'] = datetime.today().strftime(
         FUSION_TABLE_DATE_TIME_FORMAT)
     master[
         'update after sync'] = 'true'  # this will trigger sync_old_version_of_updated_events()
     master['renewal date'] = (
         datetime.today() +
         timedelta(days=30 * 6)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     master['event slug'] = original_master['event slug']
     master['hashtags'] = ','.join([
         "#%s#" % slugify(tag)
         for tag in extract_hash_tags(master['description'])
     ])
     master['rowid'] = original_master['rowid']
     fusion_tables.update_with_implicit_rowid(configuration['master table'],
                                              master)
     sync.sync_updated_events(configuration,
                              condition="'event slug' = '%s'" %
                              master['event slug'])
     logging.info("LIST_OF_UPDATED_ROWS [%s] [%s] %s" %
                  (configuration['id'], master['update date'], data))
     sender = 'info@%s.appspotmail.com' % (app_id)
     message = mail.EmailMessage(sender=sender,
                                 to="*****@*****.**")
     message.subject = "Event updated in MapTiming %s" % configuration[
         'title']
     message.body = "http://%s.maptiming.com#event/%s" % (
         configuration['id'], master['event slug'])
     logging.info("Sending mail from %s: %s - %s" %
                  (sender, message.subject, message.body))
     message.send()
     # return the web-page content
     self.response.out.write(master['event slug'])
     return
Beispiel #5
0
 def post(self):
     configuration = customer_configuration.get_configuration(self.request)
     data = self.request.POST['data']
     master = json.loads(data)
     # check if the location is in use, if so, reuse it's location slug
     same_location_condition = "ST_INTERSECTS('latitude', CIRCLE(LATLNG(%f,%f),2))" % (
         round(float(master['latitude']),
               5), round(float(master['longitude']), 5))  # 3 meter
     same_location = fusion_tables.select_first(
         configuration['master table'], condition=same_location_condition)
     if same_location:
         logging.info(
             "Using the location slug of an existing location [%s] instead of [%s]"
             % (same_location[0]['location slug'], master['location slug']))
         master['location slug'] = same_location[0]['location slug']
     else:
         base_location_slug = location_slug(master)
         logging.info("This is a new location [%s]" % base_location_slug)
         master['location slug'] = base_location_slug
         # add (1) or (2) or etc... to the location slug if it's already in use
         while fusion_tables.select_first(
                 configuration['master table'],
                 condition="'location slug' = '%s'" %
                 master['location slug']):
             logging.info(
                 "Adding (1), (2),... to location slug [%s] because it already existed."
                 % master['location slug'])
             counter = 1 if 'counter' not in locals() else counter + 1
             master['location slug'] = base_location_slug + '-(' + str(
                 counter) + ')'
     master['state'] = 'new'
     master['sequence'] = 1
     master['entry date'] = datetime.today().strftime(
         FUSION_TABLE_DATE_TIME_FORMAT)
     master['update date'] = datetime.today().strftime(
         FUSION_TABLE_DATE_TIME_FORMAT)
     master['renewal date'] = (
         datetime.today() +
         timedelta(days=30 * 6)).strftime(FUSION_TABLE_DATE_TIME_FORMAT)
     base_event_slug = event_slug(master)
     master['event slug'] = base_event_slug
     # add (1) or (2) or etc... to the event slug if it's already in use
     while fusion_tables.select_first(configuration['master table'],
                                      condition="'event slug' = '%s'" %
                                      master['event slug']):
         counter = 1 if 'counter' not in locals() else counter + 1
         master['event slug'] = base_event_slug + '-(' + str(counter) + ')'
     # hashtags
     master['hashtags'] = ','.join([
         "#%s#" % slugify(tag)
         for tag in extract_hash_tags(master['description'])
     ])
     fusion_tables.insert(configuration['master table'], master)
     sync.sync_new_events(configuration,
                          condition="'event slug' = '%s'" %
                          master['event slug'])
     logging.info("LIST_OF_ADDED_ROWS [%s] [%s] %s" %
                  (configuration['id'], master['update date'], data))
     sender = 'info@%s.appspotmail.com' % (app_id)
     message = mail.EmailMessage(sender=sender,
                                 to="*****@*****.**")
     message.subject = "New event added to MapTiming %s" % configuration[
         'title']
     message.body = "http://%s.maptiming.com#event/%s" % (
         configuration['id'], master['event slug'])
     logging.info("Sending mail from %s: %s - %s" %
                  (sender, message.subject, message.body))
     message.send()
     # return the web-page content
     self.response.out.write(master['event slug'])
     return