Пример #1
0
def tweet(cnt_list, nm_list, cmt_list, cnt_mx_db):
    try:
        i = 0
        for cnt in cnt_list:
            if int(cnt) > cnt_mx_db:
                # DB接続
                arg = db_connect()
                conn = arg[0]
                cur = arg[1]
                # DB(INSERT文)
                db_insert_bbs(cur, tbl_name, int(cnt))
                # DB切断
                db_close(conn, cur)

                # Tweet
                if not "http" in cmt_list[i] and (
                        len(cmt_list[i]) > str_count_boundary_value
                        or int(cnt) % count_multiple == 0):
                    tweet = str_tweet.format(cnt, nm_list[i], cmt_list[i], url)
                    if len(tweet) > 260:
                        cnt_del_str = len(tweet) - 260
                        tweet = str_tweet.format(cnt, nm_list[i],
                                                 cmt_list[i][:-cnt_del_str],
                                                 url)
                    proc_tweet(tweet)
                    sleep(30)
            i += 1

    except Exception as e:
        logging.eeror(e)
        raise
Пример #2
0
def check_movie():

    # 動画IDを格納
    # listVideoId = []

    while True:

        # UTC(協定世界時)を取得し、「YouTube Data API (v3)」より直近1日の新規動画情報(json)を取得
        awareDT = (datetime.now(timezone.utc) - timedelta(days=1)).isoformat()
        req = requests.get(
            "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId="
            + channelId + "&key=" + key + "&publishedAfter=" + awareDT[0:23] +
            "Z")
        soup = bs4.BeautifulSoup(req.text, "lxml")
        jsonText = soup.p.string
        dictText = json.loads(jsonText)
        listItems = dictText.get("items")

        # 動画IDとタイトルを取得
        for listValue in listItems:

            videoId = listValue["id"]["videoId"]
            title = listValue["snippet"]["title"]

            # DB接続
            arg = db_connect()
            conn = arg[0]
            cur = arg[1]

            # DB(SELECT文)
            cnt = db_check_movie(cur, tblName, videoId)

            # DB切断
            db_close(conn, cur)

            if cnt == 0:

                # DB接続
                arg = db_connect()
                conn = arg[0]
                cur = arg[1]

                # DB(INSERT文)
                db_insert_movie(cur, tblName, videoId)

                # DB切断
                db_close(conn, cur)

                strTweet = strTmp.format(title, videoId)
                proc_tweet(strTweet)

        sleep(150)
Пример #3
0
def check_twitter():

    while True:
        # 本日の日付を取得
        today = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d')
        
        # ツイートポストエンドポイント
        url = "https://api.twitter.com/1.1/search/tweets.json"
        query = "-" + keyword + " from:" + from_user + " since:" + today
        params = {'q' : query, 'count' : 10}
        # 認証処理
        twitter = OAuth1Session(CK, CS, AT, ATS)
        # post送信
        res = twitter.get(url, params=params)

        if res.status_code == 200:  # 正常投稿出来た場合

            results = json.loads(res.text)

            for tweet in results['statuses']:

                tweetId = tweet['id']
                strTweet = strTmp.format(text=tweet['text'])

                # DB接続
                arg = db_connect()
                conn = arg[0]
                cur = arg[1]
                #S ELECT処理
                cnt = db_check_twitter(cur, tblName, tweetId)
                # DB切断
                db_close(conn, cur)

                if cnt == 0:
                    # DB接続
                    arg = db_connect()
                    conn = arg[0]
                    cur = arg[1]

                    # DB(INSERT文)
                    db_insert_tweet_id(cur, tblName, tweetId)

                    # DB切断
                    db_close(conn, cur)

                    #ツイート
                    proc_tweet(strTweet)
                
        sleep(150)
Пример #4
0
def check_reserve_yt():

    # 動画IDを格納
    # listVideoId = []

    while True:

        url = r"https://www.googleapis.com/youtube/v3/search?key={key}&part=snippet&channelId={channelId}&type=video&eventType=upcoming&maxResults=50"
        req = requests.get(url.format(key=key, channelId=channelId))
        soup = bs4.BeautifulSoup(req.text, "lxml")
        jsonText = soup.p.string
        dictText = json.loads(jsonText)
        listItems = dictText.get("items")

        # 動画IDとタイトルを取得
        for listValue in listItems:

            videoId = listValue["id"]["videoId"]

            url = r"https://www.youtube.com/watch?v=" + videoId

            # DB接続
            arg = db_connect()
            conn = arg[0]
            cur = arg[1]

            # DB(SELECT文)
            cnt = db_check_movie(cur, tblName, videoId)

            # DB切断
            db_close(conn, cur)

            if cnt == 0:

                # DB接続
                arg = db_connect()
                conn = arg[0]
                cur = arg[1]

                # DB(INSERT文)
                db_insert_movie(cur, tblName, videoId)

                # DB切断
                db_close(conn, cur)

                strTweet = strTmp.format(url=url)
                proc_tweet(strTweet)

        sleep(150)
Пример #5
0
def update_db():
    try:
        # DB接続
        arg = db_connect()
        conn = arg[0]
        cur = arg[1]
        # DB(SELECT文)
        max_cnt = db_check_bbs(cur, tbl_name)[0]
        if max_cnt is None:
            max_cnt = 0
        # DB切断
        db_close(conn, cur)

    except Exception as e:
        logging.error(e)
        raise

    return max_cnt
Пример #6
0
def check_start_live():
    while True:

        # chk_comment.pyのテストの場合はcheck_commentのみを処理する
        if MODE_SETTING == "TEST2":
            bloadcast_url = os.environ["NICONICO_BLOADCAST_URL_TEST2"]
            check_comment(bloadcast_url)
            break

        sleep(15)
        #HTMLスクレビング
        res = requests.get(r"https://com.nicovideo.jp/community/" +
                           community_id)
        res.raise_for_status()
        soup = bs4.BeautifulSoup(res.text, "html.parser")
        try:
            bloadcast_url = soup.find(
                "a",
                class_="now_live_inner").get("href").rstrip("?ref=community")

            # DB接続
            arg = db_connect()
            conn = arg[0]
            cur = arg[1]

            # DB(SELECT文)
            count = db_check(cur, dbName, bloadcast_url)

            if count == 0:
                db_insert(cur, dbName, bloadcast_url)
                proc_tweet(strTweet + bloadcast_url)
                # threadChkStart_1 = threading.Thread(target=proc_ichiba, args=(bloadcast_url,))
                # threadChkStart_2 = threading.Thread(target=check_comment, args=(bloadcast_url,))
                # threadChkStart_1.start()
                # threadChkStart_2.start()
            db_close(conn, cur)

        except AttributeError:
            pass

        sleep(15)