Пример #1
0
    def event_insert_item(self, item):
        cursor = self.db.cursor()

        rank = item['rank']
        artist_event = item['artist_event']
        venue = item['venue']

        try:
            city_list = BoxString.normalize_city(item['city'])
            city = city_list[0]
            state = city_list[1]

            date_list = item['date']

            gross_sales_list = BoxString.normalize_prices(item['gross_sales'])
            sale = gross_sales_list[0]

            attend_cap = BoxString.normalize_attend_capacity(item['attend_cap'])
            attend = attend_cap[0]
            capacity = attend_cap[1]

            shows_sellout_list = BoxString.normalize_shows_sellout(item['shows_sellout'])
            show = shows_sellout_list[0]
            sellout = shows_sellout_list[1]

            update_date = item["create_date"]

            check_query = """SELECT COUNT(*) """\
                          """FROM boxoffice_app_event """ \
                          """WHERE id = (SELECT boxoffice_app_event.id """ \
                          """FROM boxoffice_app_event """ \
                          """WHERE artist_event_id=(SELECT id FROM boxoffice_app_artistevent where name = "%s") """ \
                          """AND venue_id=(SELECT id FROM boxoffice_app_venue where name = "%s") """ \
                          """AND city_id=(SELECT id FROM boxoffice_app_city where name = "%s" AND state = "%s") """ \
                          """AND dates = "%s" ) """ \
                          % (artist_event, venue, city, state, date_list)
            cursor.execute(check_query)

            for row in cursor:
                if row[0] > 0:
                    print "%s exist in Event" % '%s / %s / %s / %s' % (artist_event, city, venue, date_list)
                else:
                    query = """INSERT INTO boxoffice_app_event VALUES (""" \
                            """NULL, """ \
                            """(SELECT id FROM boxoffice_app_artistevent WHERE name = "%s"), """ \
                            """(SELECT id FROM boxoffice_app_city WHERE name = "%s" AND state = "%s"), """ \
                            """(SELECT id FROM boxoffice_app_venue WHERE name = "%s"), "%s", %s, %s, %s, %s, %s, "%s", "%s");""" \
                            % (artist_event, city, state, venue, sale, attend, capacity, show, sellout, rank, date_list, update_date)
                    cursor.execute(query)
                    self.db.commit()

        except ValueError as e:
            self.create_error_log('Event', item)
        except Exception as e:
            print 'Error ----------------------%s--------------------------------------------------' % 'Event'
            print e.args
            print item
            self.create_error_log('Event', item)
            raise Exception("Event Insert Error")
Пример #2
0
    def event_prices_insert_item(self, item):
        cursor = self.db.cursor()

        try:
            artist_event = item['artist_event']
            venue = item['venue']
            city_list = BoxString.normalize_city(item['city'])
            city = city_list[0]
            state = city_list[1]
            date_list = item['date']
            update_date = item["create_date"]

            prices_list = BoxString.normalize_prices(item['prices'])
            for price in prices_list:
                check_query = """SELECT COUNT(*) """ \
                              """FROM boxoffice_app_eventprice """ \
                              """WHERE event_id = (SELECT boxoffice_app_event.id """ \
                              """FROM boxoffice_app_event """ \
                              """WHERE artist_event_id=(SELECT id FROM boxoffice_app_artistevent where name = "%s") """ \
                              """AND venue_id=(SELECT id FROM boxoffice_app_venue where name = "%s") """ \
                              """AND city_id=(SELECT id FROM boxoffice_app_city where name = "%s" AND state = "%s") """ \
                              """AND dates = "%s" ) """ \
                              """AND price_id = (SELECT id """ \
                              """FROM boxoffice_app_price """ \
                              """WHERE price = "%s"); """ \
                              % (artist_event, venue, city, state, date_list, price)
                cursor.execute(check_query)
                for row in cursor:
                    if row[0] > 0:
                        print "%s exist in Event_Prices" % '%s-%s' % (artist_event, price)
                    else:
                        query = """INSERT INTO boxoffice_app_eventprice VALUES (NULL, """ \
                                """(SELECT boxoffice_app_event.id """ \
                                """FROM boxoffice_app_event """ \
                                """WHERE artist_event_id=(SELECT id FROM boxoffice_app_artistevent where name = "%s") """ \
                                """AND venue_id=(SELECT id FROM boxoffice_app_venue where name = "%s") """ \
                                """AND city_id=(SELECT id FROM boxoffice_app_city where name = "%s" AND state = "%s") """ \
                                """AND dates = "%s" ), """ \
                                """(SELECT id """ \
                                """FROM boxoffice_app_price """ \
                                """WHERE price = "%s")); """ \
                                % (artist_event, venue, city, state, date_list, price)

                        cursor.execute(query)
                        self.db.commit()
        except ValueError as e:
            self.create_error_log('Event_Prices', item)
        except Exception as e:
            print 'Error ----------------------%s--------------------------------------------------' % 'Event_Prices'
            print e.args
            print item
            self.create_error_log('Event_Prices', item)
Пример #3
0
    def dates_insert_item(self, item):
        cursor = self.db.cursor()

        artist_event = item['artist_event']
        venue = item['venue']
        city_list = BoxString.normalize_city(item['city'])
        city = city_list[0]
        state = city_list[1]
        date_list = item['date']
        update_date = item['create_date']

        parser = BoxDateParser()
        array = parser.get_date_string(date_list)

        if array == None:
            self.create_error_log('Date', item)
        else:
            try:
                for dateObj in array:
                    for date in dateObj[2]:
                        check_query = """SELECT COUNT(*) """ \
                                      """FROM boxoffice_app_date """ \
                                      """WHERE event_id = (SELECT boxoffice_app_event.id """ \
                                      """FROM boxoffice_app_event """ \
                                      """WHERE artist_event_id=(SELECT id FROM boxoffice_app_artistevent where name = "%s") """ \
                                      """AND venue_id=(SELECT id FROM boxoffice_app_venue where name = "%s") """ \
                                      """AND city_id=(SELECT id FROM boxoffice_app_city where name = "%s" AND state = "%s") """ \
                                      """AND dates = "%s" ) """ \
                                      """AND event_date = "%s-%s-%s"; """ \
                                      % (artist_event, venue, city, state, date_list, dateObj[0], dateObj[1], date)
                        cursor.execute(check_query)
                        for row in cursor:
                            if row[0] > 0:
                                print "%s exist in Dates" % '%s-%s-%s' % (dateObj[0], dateObj[1], date)
                            else:
                                query = """INSERT INTO boxoffice_app_date VALUES (NULL, """ \
                                        """(SELECT boxoffice_app_event.id """ \
                                        """FROM boxoffice_app_event """ \
                                        """WHERE artist_event_id=(SELECT id FROM boxoffice_app_artistevent where name = "%s") """ \
                                        """AND venue_id=(SELECT id FROM boxoffice_app_venue where name = "%s") """ \
                                        """AND city_id=(SELECT id FROM boxoffice_app_city where name = "%s" AND state = "%s") """ \
                                        """AND dates = "%s" ), "%s-%s-%s"); """ \
                                        % (artist_event, venue, city, state, date_list, dateObj[0], dateObj[1], date)

                                cursor.execute(query)
                                self.db.commit()
            except ValueError as e:
                self.create_error_log('Date', item)
            except Exception as e:
                print 'Error ----------------------%s--------------------------------------------------' % 'Date'
                print e.args
                print item
                self.create_error_log('Date', item)
Пример #4
0
    def prices_insert_item(self, item):
        cursor = self.db.cursor()

        prices_list = BoxString.normalize_prices(item['prices'])

        for price in prices_list:

            check_query = """SELECT COUNT(*) FROM boxoffice_app_price WHERE price = "%s";""" % price
            cursor.execute(check_query)

            for row in cursor:
                if row[0] > 0:
                    print "%s exist in Prices" % price
                else:
                    query = """INSERT INTO boxoffice_app_price (price) VALUES ("%s");""" % price
                    cursor.execute(query)
                    self.db.commit()
Пример #5
0
    def city_insert_item(self, item):
        cursor = self.db.cursor()

        city_list = BoxString.normalize_city(item['city'])
        city = city_list[0]
        state = city_list[1]

        check_query = """SELECT COUNT(*) FROM boxoffice_app_city WHERE name = "%s" AND state = "%s";""" % (city, state)
        cursor.execute(check_query)

        for row in cursor:
            if row[0] > 0:
                print "%s exist in City" % '%s-%s' % (city, state)
            else:
                query = """INSERT INTO boxoffice_app_city (name, state) VALUES ("%s", "%s");""" % (city, state)
                cursor.execute(query)
                self.db.commit()