Exemplo n.º 1
0
        def artists_with_shows(day_delta, day_count=1):
            conn = hub.getConnection()

            start_date = date.today() + timedelta(day_delta)
            where_clause = AND(Event.q.date >= start_date, Event.q.approved != None)
            if day_count != 0:
                end_date = start_date + timedelta(day_count-1)
                where_clause = AND(where_clause, Event.q.date <= end_date)

            artists = conn.queryAll("""
                select artist.id, artist.name, venue.name
                from artist, event, artist_event, venue
                where artist.id = artist_event.artist_id and
                    artist_event.event_id = event.id and 
                    venue.id = event.venue_id and
                    %s
                order by artist.name
                """ % where_clause)

            day_result = {}
            if identity.current.user:
                tracked_artist_ids = [a.id for a in identity.current.user.artists]
            else:
                tracked_artist_ids = []
            for artist_id, artist_name, venue_name in artists:
                is_tracked = artist_id in tracked_artist_ids
                day_result[artist_name] = (artist_id, is_tracked, venue_name)
            return day_result
Exemplo n.º 2
0
        def events_in_period(day_delta, day_count=1):
            conn = hub.getConnection()

            start_date = date.today() + timedelta(day_delta)
            where_clause = AND(Event.q.date >= start_date, Event.q.approved != None)
            if day_count != 0:
                end_date = start_date + timedelta(day_count-1)
                where_clause = AND(where_clause, Event.q.date <= end_date)

            events = conn.queryAll("""
                select event.id, event.name, event.date, venue.name
                from event, venue
                where event.venue_id = venue.id
                    AND %s
                order by event.date, event.name
                """ % where_clause)

            day_result = {}
            if identity.current.user:
                tracked_event_ids = [a.id for a in identity.current.user.events]
            else:
                tracked_event_ids = []
            for event_id, event_name, event_date, venue_name in events:
                is_tracked = event_id in tracked_event_ids
                yield (event_id, event_name, event_date, venue_name, is_tracked)
Exemplo n.º 3
0
    def index(self, gclid=None):
        conn = hub.getConnection()

        events = conn.queryAll(
            """
            select event.id, event.name, venue.name
            from event, venue
            where event.venue_id = venue.id
                and event.date = CURRENT_DATE
                and event.approved is not NULL
            order by venue.name
            """
        )

        blurb_text = publish_parts(Blurb.random(), writer_name="html")["html_body"]

        return dict(events=events, blurb=blurb_text)
Exemplo n.º 4
0
    def list(self):
        conn = hub.getConnection()
        results = conn.queryAll("""
            select venue.id, venue.name, count(event.id)
            from venue, event
            where venue.id = event.venue_id
                and event.date >= CURRENT_DATE
            group by venue.id, venue.name
            order by venue.name
            """)

        tracked_venues = []
        if identity.current.user:
            tracked_venues = [v.id for v in identity.current.user.venues]

        venue_list = []
        for id, name, count in results:
            venue_list.append(dict(name=name, id=id, eventcount=count))
        return dict(venues=venue_list, count=len(venue_list),
            tracked_venues=tracked_venues)
Exemplo n.º 5
0
 def reviewdupes(self):
     conn = hub.getConnection()
     dupe_results = conn.queryAll("""
         select date, venue_id, count(*)
         from event
         where date >= CURRENT_DATE
         group by venue_id, date
         having count(*) > 1
         """)
     dupe_groups = []
     limit = 5
     for date, venue_id, count in dupe_results:
         possible_dupes = Event.selectBy(date=date, venueID=venue_id)
         if self.events_likely_dupes(possible_dupes):
             dupes = []
             for dupe in possible_dupes:
                 others = set(possible_dupes)
                 others.remove(dupe)
                 dupes.append((dupe, others))
             dupe_groups.append(dupes)
             if len(dupe_groups) >= limit:
                 break
     return dict(dupes=dupe_groups, dupe_count=len(dupe_results),
         artist_list=artist_list)
Exemplo n.º 6
0
def send_email(start, finish):
    conn = hub.getConnection()

    users_to_email = set()

    #
    # Gather results for tracked artists. Notify if events added since last update
    #
    artist_email = {}
    results = conn.queryAll(
        """
        select u.id, e.name, e.date, v.name
        from user_acct u, artist_user_acct au, artist a, artist_event ae, event e, venue v
        where
            u.event_email is true
            and u.id = au.user_acct_id
            and a.id = au.artist_id
            and a.id = ae.artist_id
            and ae.event_id = e.id
            and e.venue_id = v.id
            and e.created >= '%s'
            and e.created < '%s'
            and e.date >= CURRENT_DATE
        """
        % (start, finish)
    )
    for user_id, name, date, venue_name in results:
        evt_list = artist_email.get(user_id, list())
        evt_list.append((unicode(name, "utf-8"), date, unicode(venue_name, "utf-8")))
        artist_email[user_id] = evt_list
        users_to_email.add(user_id)

    #
    # Gather results for tracked events. Notify if they're today
    #
    event_email = {}
    results = conn.queryAll(
        """
        select e.id, e.name, att.user_id, v.name
        from event e, attendance att, venue v
            where e.date = CURRENT_DATE
            and e.id = att.event_id
            and e.venue_id = v.id
        """
    )
    for event_id, event_name, user_id, venue_name in results:
        evt_list = event_email.get(user_id, list())
        evt_list.append((unicode(event_name, "utf-8"), venue_name))
        event_email[user_id] = evt_list
        users_to_email.add(user_id)

    # Gather results for tracked venues. Once a week.
    # why do this here, instead of having a separate scheduled function called?
    # because we want to put both artist and venue notifications in the same email.
    venue_email = {}
    if finish.isoweekday() == 4:
        results = conn.queryAll(
            """
            select u.id, e.name, e.date, v.name
            from user_acct u, venue v, event e, user_acct_venue uv
            where
                u.event_email is true
                and e.venue_id = v.id
                and u.id = uv.user_acct_id
                and uv.venue_id = v.id
                and e.date >= CURRENT_DATE
                order by e.date
            """
        )

        for user_id, event_name, date, venue_name in results:
            venue_dict = venue_email.get(user_id, dict())
            venue = venue_dict.get(venue_name, list())
            venue.append((unicode(event_name, "utf-8"), date))
            venue_dict[venue_name] = venue
            venue_email[user_id] = venue_dict
            users_to_email.add(user_id)

    for id in users_to_email:
        import pkg_resources

        u = UserAcct.get(id)

        event_text = ""
        for event_name, venue_name in event_email.get(id, list()):
            event_text += u"%s, at %s\n" % (event_name, venue_name)
        if event_text:
            hdr_txt = "These events you want to go to are TONIGHT!\n\n"
            event_text = hdr_txt + event_text + "\n"

        artist_text = ""
        for event_name, date, venue_name in artist_email.get(id, list()):
            artist_text += u"%s, %s at %s\n" % (event_name, date, venue_name)
        if artist_text:
            hdr_txt = "Newly added shows featuring artists you are tracking:\n\n"
            artist_text = hdr_txt + artist_text + "\n"

        venue_text = ""
        for venue_name, event_list in venue_email.get(id, dict()).iteritems():
            venue_text += venue_name + "\n" + ("-" * len(venue_name)) + "\n"
            for name, date in event_list:
                venue_text += u"%s: %s\n" % (date, name)
            venue_text += "\n"
        if venue_text:
            hdr_txt = "Upcoming shows at the venues you are tracking:\n\n"
            venue_text = hdr_txt + venue_text

        text = event_text + artist_text + venue_text

        user_url = "http://bandradar.com/users/%s" % u.user_name
        msg_to = u.email_address
        msg_from = "BandRadar Events <*****@*****.**>"
        body = pkg_resources.resource_string(__name__, "templates/new_event_email.txt")
        body = body % {"text": text, "user_url": user_url}

        util.email(msg_to, msg_from, "BandRadar upcoming events", body)

    return (len(users_to_email), len(artist_email), len(venue_email))