コード例 #1
0
ファイル: app.py プロジェクト: guilhermebruzzi/bands
def cadastro():
    current_user = get_current_user()
    data = request.form

    if request.method == 'POST':
        if validate_answers(data):
            set_user_tipo(current_user, data["musico-ou-fa"])

            if data["banda"]:
                get_or_create_band({"name": data["banda"], "musician": current_user})

            return redirect(url_for('minhas_bandas'))

    return render_template('cadastro.html', current_user=current_user, main_questions=MAIN_QUESTIONS, post_data=data)
コード例 #2
0
ファイル: app.py プロジェクト: guilhermebruzzi/bands
def search_band(band_name):
    current_user = None  # TODO: Adicionar em minhas bandas: get_current_user()
    current_city = "Rio de Janeiro"  # get_current_city(ip=get_client_ip())

    band = get_or_create_band({
        'slug': get_slug(band_name),
        'name': band_name,
        'user': current_user
    })

    shows = get_shows_from_bands([band],
                                 limit_per_artist=1,
                                 city=current_city,
                                 call_lastfm_if_dont_have_shows=True,
                                 call_lastfm_without_subprocess=True)

    show = None

    if shows:
        show = shows[0][1][0]  # Pegando apenas o objeto show da banda

    return render_template("resultado_uma_banda.html",
                           band=band,
                           show=show,
                           notas=range(11),
                           BANDAS_CAMISAS=BANDAS_CAMISAS,
                           formulario_pag_seguro=formulario_pag_seguro)
コード例 #3
0
def run_migration():
    answers = get_all_answers_from_question("musico-favoritos")
    answers.extend(get_all_answers_from_question("fa-favoritos"))

    for answer in answers:
        bandsList = answer.answer
        for bands in bandsList.split(","):
            for splited in bands.split('\n'):
                band = splited.strip().title()
                if band:
                    data = {
                        "slug": get_slug(band),
                        "name": band,
                        "user": answer.user
                    }

                    get_or_create_band(data)
コード例 #4
0
def run_migration():
    answers = get_all_answers_from_question("musico-favoritos")
    answers.extend(get_all_answers_from_question("fa-favoritos"))

    for answer in answers:
        bandsList = answer.answer
        for bands in bandsList.split(","):
            for splited in bands.split('\n'):
                band = splited.strip().title()
                if band:
                    data = {
                        "slug": get_slug(band),
                        "name": band,
                        "user": answer.user
                    }

                    get_or_create_band(data)
コード例 #5
0
ファイル: app.py プロジェクト: guilhermebruzzi/bands
def add_band():
    name = request.form['band']
    user = get_current_user()
    if user:
        band = get_or_create_band({'slug': get_slug(name), 'name': name, 'user': user})
        return "%s\n%s" % (band.name, band.slug)
    else:
        return "Ninguem logado"
コード例 #6
0
ファイル: lastfm_test.py プロジェクト: guilhermebruzzi/bands
    def setUp(self):
        self.__delete_all__() #  Chama a funcao que deleta todos os models que essa classe testa

        self.artists = ["Franz Ferdinand", "Ivete Sangalo", "Chico Buarque", "Muse"]
        self.bands = [get_or_create_band({"name": artist}) for artist in self.artists]

        self.franz_similares_data = [ "Kaiser Chiefs", "Arctic Monkeys", "The Strokes"]
        self.franz_similares_slug = [ "kaiser-chiefs", "arctic-monkeys", "the-strokes"]
コード例 #7
0
ファイル: app.py プロジェクト: guilhermebruzzi/bands
def cadastro():
    current_user = get_current_user()
    data = request.form

    if request.method == 'POST':
        if validate_answers(data):
            set_user_tipo(current_user, data["musico-ou-fa"])

            if data["banda"]:
                get_or_create_band({
                    "name": data["banda"],
                    "musician": current_user
                })

            return redirect(url_for('minhas_bandas'))

    return render_template('cadastro.html',
                           current_user=current_user,
                           main_questions=MAIN_QUESTIONS,
                           post_data=data)
コード例 #8
0
ファイル: app.py プロジェクト: guilhermebruzzi/bands
def show_from_band(band_name):
    current_user = None # TODO: Adicionar em minhas bandas: get_current_user()
    current_city = "Rio de Janeiro" # get_current_city(ip=get_client_ip())
    band = get_or_create_band({'slug': get_slug(band_name), 'name': band_name, 'user': current_user})
    shows = get_shows_from_bands([band], limit_per_artist=1, city=current_city, call_lastfm_if_dont_have_shows=True, call_lastfm_without_subprocess=True)
    show = None
    if shows:
        show = shows[0][1][0] # Pegando apenas o objeto show da banda
    elif len(band.users) == 0:
        band.delete()
    return render_template("show_de_uma_banda.html", band=band, show=show)
コード例 #9
0
ファイル: app.py プロジェクト: guilhermebruzzi/bands
def add_band():
    name = request.form['band']
    user = get_current_user()
    if user:
        band = get_or_create_band({
            'slug': get_slug(name),
            'name': name,
            'user': user
        })
        return "%s\n%s" % (band.name, band.slug)
    else:
        return "Ninguem logado"
コード例 #10
0
ファイル: app.py プロジェクト: guilhermebruzzi/bands
def search_band(band_name):
    current_user = None # TODO: Adicionar em minhas bandas: get_current_user()
    current_city = "Rio de Janeiro" # get_current_city(ip=get_client_ip())

    band = get_or_create_band({'slug': get_slug(band_name), 'name': band_name, 'user': current_user})

    shows = get_shows_from_bands([band], limit_per_artist=1, city=current_city, call_lastfm_if_dont_have_shows=True, call_lastfm_without_subprocess=True)

    show = None

    if shows:
        show = shows[0][1][0] # Pegando apenas o objeto show da banda

    return render_template("resultado_uma_banda.html", band=band, show=show, notas=range(11), BANDAS_CAMISAS=BANDAS_CAMISAS,
        formulario_pag_seguro=formulario_pag_seguro)
コード例 #11
0
ファイル: lastfm_test.py プロジェクト: guilhermebruzzi/bands
    def setUp(self):
        self.__delete_all__(
        )  #  Chama a funcao que deleta todos os models que essa classe testa

        self.artists = [
            "Franz Ferdinand", "Ivete Sangalo", "Chico Buarque", "Muse"
        ]
        self.bands = [
            get_or_create_band({"name": artist}) for artist in self.artists
        ]

        self.franz_similares_data = [
            "Kaiser Chiefs", "Arctic Monkeys", "The Strokes"
        ]
        self.franz_similares_slug = [
            "kaiser-chiefs", "arctic-monkeys", "the-strokes"
        ]
コード例 #12
0
ファイル: app.py プロジェクト: guilhermebruzzi/bands
def show_from_band(band_name):
    current_user = None  # TODO: Adicionar em minhas bandas: get_current_user()
    current_city = "Rio de Janeiro"  # get_current_city(ip=get_client_ip())
    band = get_or_create_band({
        'slug': get_slug(band_name),
        'name': band_name,
        'user': current_user
    })
    shows = get_shows_from_bands([band],
                                 limit_per_artist=1,
                                 city=current_city,
                                 call_lastfm_if_dont_have_shows=True,
                                 call_lastfm_without_subprocess=True)
    show = None
    if shows:
        show = shows[0][1][0]  # Pegando apenas o objeto show da banda
    elif len(band.users) == 0:
        band.delete()
    return render_template("show_de_uma_banda.html", band=band, show=show)
コード例 #13
0
ファイル: lastfm.py プロジェクト: guilhermebruzzi/bands
def __get_shows__(url_shows):
    response_lastfm = get_json(url_shows)
    shows_json = response_lastfm["events"]["event"] if "events" in response_lastfm and "event" in response_lastfm["events"] else []
    shows = []
    if not type(shows_json) is list:
        shows_json = [shows_json]
    
    for show_json in shows_json:
        try:
            artists = show_json['artists']['artist']
        except TypeError as e:
            print e
            print show_json
            continue
        if not type(artists) is list:
            artists = [artists]
        show_datetime = datetime.strptime(show_json['startDate'], '%a, %d %b %Y %H:%M:%S') #  From USA pattern to datetime
        show =  get_or_create_show({
            'artists': [get_or_create_band({'name': artist}) for artist in artists],
            'attendance_count': show_json['attendance'], #  number of people going
            'cover_image': show_json['image'][2]['#text'], #  Large
            'description': show_json['description'],
            'datetime_usa': datetime.strftime(show_datetime, '%Y-%m-%d %H:%M:%S'), #  From datetime to string
            'title': show_json['title'],
            'website': show_json['website'],
            'location': get_or_create_location({
                'name': show_json['venue']['name'],
                'city': show_json['venue']['location']['city'],
                'street': show_json['venue']['location']['street'],
                'postalcode': show_json['venue']['location']['postalcode'],
                'website': show_json['venue']['website'],
                'phonenumber': show_json['venue']['phonenumber'],
                'image': show_json["image"][2]["#text"], #  Large
            })
        })
        if not show in shows:
            shows.append(show)
#    TODO: Logging de warning - if len(shows) == 0 :
#        print url_shows
    return shows
コード例 #14
0
def __get_shows__(url_shows):
    response_lastfm = get_json(url_shows)
    shows_json = response_lastfm["events"][
        "event"] if "events" in response_lastfm and "event" in response_lastfm[
            "events"] else []
    shows = []
    if not type(shows_json) is list:
        shows_json = [shows_json]

    for show_json in shows_json:
        try:
            artists = show_json['artists']['artist']
        except TypeError as e:
            print e
            print show_json
            continue
        if not type(artists) is list:
            artists = [artists]
        show_datetime = datetime.strptime(
            show_json['startDate'],
            '%a, %d %b %Y %H:%M:%S')  #  From USA pattern to datetime
        show = get_or_create_show({
            'artists':
            [get_or_create_band({'name': artist}) for artist in artists],
            'attendance_count':
            show_json['attendance'],  #  number of people going
            'cover_image':
            show_json['image'][2]['#text'],  #  Large
            'description':
            show_json['description'],
            'datetime_usa':
            datetime.strftime(show_datetime,
                              '%Y-%m-%d %H:%M:%S'),  #  From datetime to string
            'title':
            show_json['title'],
            'website':
            show_json['website'],
            'location':
            get_or_create_location({
                'name':
                show_json['venue']['name'],
                'city':
                show_json['venue']['location']['city'],
                'street':
                show_json['venue']['location']['street'],
                'postalcode':
                show_json['venue']['location']['postalcode'],
                'website':
                show_json['venue']['website'],
                'phonenumber':
                show_json['venue']['phonenumber'],
                'image':
                show_json["image"][2]["#text"],  #  Large
            })
        })
        if not show in shows:
            shows.append(show)


#    TODO: Logging de warning - if len(shows) == 0 :
#        print url_shows
    return shows