コード例 #1
0
ファイル: video_api.py プロジェクト: ShotaOkawa/YTCProject
def get_video_data(analysis_video_ids):
    video_data = []
    daily_flg = '1'
    for video_id in analysis_video_ids:
        ins_data = []
        # APIから動画ID・動画タイトルを取得
        part = 'snippet'
        print(video_id)
        response = requests.get(stat_url % (API_KEY, video_id, part))
        if response.status_code != 200:
            logger.error('YouTubeとの接続に失敗しました。処理を停止します。')
            os.sysexit()

        result = response.json()
        print(result)
        if not result['items']:
            logger.warning('対象の動画が存在しませんでした。 動画ID:' + video_id)
            continue

        video_id = result['items'][0]['id']
        video_title = result['items'][0]['snippet']['title']

        # APIから再生回数・評価数を取得
        part = 'statistics'
        response = requests.get(stat_url % (API_KEY, video_id, part))
        if response.status_code != 200:
            logger.error('YouTubeとの接続に失敗しました。処理を停止します。')
            continue

        result = response.json()
        view_cnt = '0'
        good_cnt = '0'
        bad_cnt = '0'
        if result['items'][0]['statistics']['viewCount']:
            view_cnt = result['items'][0]['statistics']['viewCount']
        if result['items'][0]['statistics']['likeCount']:
            good_cnt = result['items'][0]['statistics']['likeCount']
        if result['items'][0]['statistics']['dislikeCount']:
            bad_cnt = result['items'][0]['statistics']['dislikeCount']

        # 配列にAPIの取得結果を格納する
        ins_data.append(video_id)
        ins_data.append(video_title)
        ins_data.append(view_cnt)
        ins_data.append(good_cnt)
        ins_data.append(bad_cnt)
        ins_data.append(daily_flg)
        ins_data.append(now)
        video_data.append(ins_data)

    return video_data
コード例 #2
0
def ins_comment_data(comment_data):
    try:
        conn = mysql.connector.connect(user=db_user,
                                       password=db_pass,
                                       host=db_host,
                                       database=db_name)
        cur = conn.cursor()
        insert_sql = "INSERT INTO comment values (%s,%s,%s,%s,%s)"
        for ins_data in comment_data:
            cur.execute(insert_sql, ins_data)
    except Exception as e:
        logger.error(e)
        conn.rollback()
        os.sysexit()
    finally:
        cur.close()
        conn.commit()
        conn.close()
コード例 #3
0
def get_analysis_video_id():
    try:
        conn = mysql.connector.connect(password=db_pass,
                                       user=db_user,
                                       host=db_host,
                                       database=db_name)
        cur = conn.cursor()
        sql = "SELECT video_id FROM analysis_video"
        cur.execute(sql)
        result = []
        for video_id in cur.fetchall():
            result.append(video_id[0])
    except Exception as e:
        logger.error(e)
        os.sysexit()
    finally:
        cur.close()
        conn.close()
    return result
コード例 #4
0
            sys.exit(0)
    while outfile == '':
        try:
            outfile = raw_input('Output file: ')
        except:
            print
            sys.exit(0)
elif len(args) == 1:
    infile = args[0]
elif len(args) == 2:
    infile = args[0]
    outfile = args[1]
else:
    os.stderr.write('Usage: %s [input-bitmap-file [output-svg-file]]\n' %
                    sys.argv[0])
    os.sysexit(1)

# Now do some fixups, including defaulting the output file name
if infile.endswith('.pbm') or infile.endswith('.pts'):
    tmp_prefix = infile[:-3]
    solfile = infile[:-3] + 'tour'
    if outfile == '':
        outfile = infile[:-3] + 'svg'
elif infile.endswith('.PBM') or infile.endswith('.PTS'):
    tmp_prefix = infile[:-3]
    solfile = infile[:-3] + 'TOUR'
    if outfile == '':
        outfile = infile[:-3] + 'SVG'
else:
    tmp_prefix = os.path.split(infile)[1]
    solfile = infile + '.tour'
コード例 #5
0
ファイル: tspart.py プロジェクト: johnwun/tsp_art_tools
			print
			sys.exit( 0 )
	while outfile == '':
		try:
			outfile = raw_input( 'Output file: ' )
		except:
			print
			sys.exit( 0 )
elif len( args ) == 1:
	infile = args[0]
elif len( args ) == 2:
	infile = args[0]
	outfile = args[1]
else:
	os.stderr.write( 'Usage: %s [input-bitmap-file [output-svg-file]]\n' % sys.argv[0] )
	os.sysexit(1)


# Now do some fixups, including defaulting the output file name
if infile.endswith( '.pbm' ) or infile.endswith( '.pts' ):
	tmp_prefix = infile[:-3]
	solfile = infile[:-3] + 'tour'
	if outfile == '':
		outfile = infile[:-3] + 'svg'
elif infile.endswith( '.PBM' ) or infile.endswith( '.PTS' ):
	tmp_prefix = infile[:-3]
	solfile = infile[:-3] + 'TOUR'
	if outfile == '':
		outfile = infile[:-3] + 'SVG'
else:
	tmp_prefix = os.path.split( infile )[1]
コード例 #6
0
ファイル: main.py プロジェクト: sai-vidya/cd-stream
import os
import logging
from helpers.read_yaml import load_config
from helpers.DBEngines import DBEngine

print(dir(logging))

if __name__ == '__main__':
    config = load_config()

    if config == {}:
        os.sysexit()
    else:
        db = DBEngine(config)
        db_info = db.test_connection()
        logging.warning(db_info)

        if db.test_connection()['status'].upper() == 'SUCCEEDED':
            db.test_replication()
            pass