def unit_get_monthly_livelist(year, month):
    url = url_prefix_dict["unit"] + year + "-" + month + "/"
    r = requests.get(url)
    soup = BeautifulSoup(r.text, "html.parser")
    livelist = soup.select(".p-schedule__item")
    liveinfo_list = []

    for live in livelist:
        try:
            artists = live.select(".p-schedule__item-lineup")[0].text
        except IndexError:
            artists = "リンク先をみてください"
        artists_list = LiveDataCleaner().get_artists_name(artists)
        live_name = live.select(".p-schedule__item-title")[0].text
        live_url = live.find("a").get("href")
        img_url = live.find("img").get("src")
        day = live.select(".p-schedule__item-date")[0].text
        day = LiveDataCleaner().get_day(day)
        live_info = {
            "artists": artists,
            #"artists_list": artists_list,
            "live_name": live_name,
            "live_url": live_url,
            "img_url": img_url,
            "day": day,
            "month": month,
            "year": year,
            "livehouse": "unit"
        }
        liveinfo_list.append(live_info)
    return {"live_list": liveinfo_list}
def www_get_monthly_livelist(year, month):
    url = url_prefix_dict['www'] + year + month + ".php"
    r = requests.get(url)
    soup = BeautifulSoup(r.text, "html.parser")
    livelist = soup.find_all("article")
    liveinfo_list = []

    for live in livelist:
        artists = live.select(".title")[0].find("span").text
        artists_list = LiveDataCleaner().get_artists_name(
            live.select(".title")[0].find("span").text)
        live_name = live.select('.exp')[0].text
        live_url = live.select('a[href^="https://"]')[0].get('href')
        img_url = live.select(".visual")[0].find("img").get("src")
        day = live.select('.day')[0].text

        live_info = {
            "artists": artists,
            "live_name": live_name,
            "live_url": live_url,
            "img_url": img_url,
            "day": day,
            "month": month,
            "year": year,
            "livehouse": "www"
        }
        liveinfo_list.append(live_info)
    return {"live_list": liveinfo_list}
Beispiel #3
0
def create_liveartist_liveid(liveid, db: Session = Depends(get_db)):
    live = db.query(Live).filter(Live.pk_live_id == liveid).first()
    Cleaner = LiveDataCleaner()
    artists_list = Cleaner.remove_ng_artistname(
        Cleaner.get_artists_name(live.artists))
    liveartist_in = []

    for artist in artists_list:
        artist_info = spotify_api.spotify_artist_search(artist)['artist_info']
        liveartist_in.append(
            LiveArtist(live_id=live.pk_live_id,
                       artist_name=artist_info['name'],
                       spotify_id=artist_info['id'],
                       apple_id="apple",
                       img_url=artist_info['img_url'],
                       correction=artist_info['correction']))
    db.add_all(liveartist_in)
    db.commit()
    return artist_info
Beispiel #4
0
def create_liveartist(livehouse, year, month, db: Session = Depends(get_db)):
    lives = db.query(Live).filter(Live.livehouse == livehouse).filter(
        Live.year == int(year)).filter(Live.month == int(month)).all()
    Cleaner = LiveDataCleaner()
    for live in lives:
        artists_list = Cleaner.remove_ng_artistname(
            Cleaner.get_artists_name(live.artists))
        liveartist_in = []

        for artist in artists_list:
            artist_info = spotify_api.spotify_artist_search(
                artist)['artist_info']
            liveartist_in.append(
                LiveArtist(live_id=live.pk_live_id,
                           artist_name=artist_info['name'],
                           spotify_id=artist_info['id'],
                           apple_id="apple",
                           img_url=artist_info['img_url'],
                           correction=artist_info['correction']))
        db.add_all(liveartist_in)
    db.commit()
    return artist_info
def liquidroom_get_monthly_livelist(year, month):
    url = url_prefix_dict['liquidroom'] + year + "/" + month
    r = requests.get(url)
    soup = BeautifulSoup(r.text, "html.parser")
    livelist = soup.find_all("article")
    liveinfo_list = []

    for live in livelist:
        try:
            artists = live.select(".header")[0].find("h2").text
        except IndexError:
            artists = "リンク先をみてください"
        try:
            artists_list = LiveDataCleaner().get_artists_name(l)
        except NameError:
            artists_list = []
        try:
            live_name = live.select(".subtitle")[0].text
        except IndexError:
            live_name = "リンク先をみてください"
        live_url = live.select(".s_link")[0].get("href")
        try:
            img_url = live.select(".header")[0].find("img").get("src")
        except AttributeError:
            img_url = "none"
        day = live.select(".f1B")[0].text[:2]

        live_info = {
            "artists": artists,
            "live_name": live_name,
            "live_url": live_url,
            "img_url": img_url,
            "day": day,
            "month": month,
            "year": year,
            "livehouse": "liquidroom"
        }
        liveinfo_list.append(live_info)
    return {"live_list": liveinfo_list}
Beispiel #6
0
from fastapi import APIRouter, HTTPException, Depends
import requests
from bs4 import BeautifulSoup
from sqlalchemy.orm import Session, sessionmaker
from starlette.requests import Request

from db import Live, LiveKey, LiveArtist, LiveArtistWrong, LiveHouse, SongRanking, engine, session
from external_api import spotify_api
from data_cleaner.live_data_cleaner import LiveDataCleaner

SessionLocal = sessionmaker(autocommmit=False, autoflushs=False, bind=engine)
Cleaner = LiveDataCleaner()


def get_db(request: Request):
    return request.state.db


router = APIRouter()


@router.post("/db/create/ranking/jwave")
def cerate_ranking_jwave(db: Session = Depends(get_db)):
    url = "https://www.j-wave.co.jp/original/tokiohot100/chart/main.htm"
    r = requests.get(url)
    soup = BeautifulSoup(r.content, "html.parser")
    music_list = soup.select("table")[0].select("table")[4].select(
        "tr")[0::2][1:]
    ranking_in = []

    for music in music_list:
Beispiel #7
0
def get_liveartist_live_id(live_id, db: Session = Depends(get_db)):
    content_list = []
    spotify_info_list = []
    spotify_prefix = "https://open.spotify.com/embed/artist/"
    apple_prefix = ""
    liveartists = db.query(LiveArtist).filter(
        LiveArtist.live_id == int(live_id)).all()
    live = db.query(Live).filter(Live.pk_live_id == live_id).first()

    if not len(liveartists) == 0:
        for liveartist in liveartists:
            if liveartist.correction == 1:
                related_artists_list = spotify_api.related_get_id(
                    liveartist.spotify_id)
                liveartist_info = {
                    'artist_name': liveartist.artist_name,
                    'playlist_url': spotify_prefix + liveartist.spotify_id,
                    'related_artists_list': related_artists_list,
                    'live_id': live_id,
                    'spotify_id': liveartist.spotify_id,
                }
            else:
                liveartist_info = {
                    'artist_name': liveartist.artist_name,
                    'playlist_url': spotify_prefix + liveartist.spotify_id,
                    'related_artists_list': [],
                    'live_id': live_id,
                    'spotify_id': liveartist.spotify_id,
                }
            content_list.append(liveartist_info)
    else:
        """
        LiveArtist をまだ保存してないLiveの場合
        応急処置的に表示する
        """
        artists = live.artists
        Cleaner = LiveDataCleaner()
        artist_list = Cleaner.remove_ng_artistname(
            Cleaner.get_artists_name(live.artists))
        for artist in artist_list:
            spotify_id = spotify_api.spotify_artist_search(
                artist)['artist_info']['id']
            if not spotify_id == 'none':
                related_artists_list = spotify_api.related_get(artist)
            else:
                """
                この状態のものの処理を工夫していきたい
                """
                related_artists_list = []
            liveartist_info = {
                'artist_name': artist,
                'playlist_url': spotify_prefix + spotify_id,
                'related_artists_list': related_artists_list,
                'live_id': live_id,
                'spotify_id': spotify_id,
            }
            content_list.append(liveartist_info)
    response = {
        "liveartist_list": content_list,
        "live_id": live_id,
        "year": live.year,
        "month": live.month,
        "day": live.day,
        "live_name": live.live_name
    }
    return response