|
@@ -1,83 +0,0 @@
|
|
|
-import mysql.connector
|
|
|
-import json
|
|
|
-
|
|
|
-
|
|
|
-db_config = {
|
|
|
- 'host': 'rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com',
|
|
|
- 'database': 'incentive',
|
|
|
- 'port': 3306,
|
|
|
- 'user': 'wx2016_longvideo',
|
|
|
- 'password': 'wx2016_longvideoP@assword1234',
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-cnx = mysql.connector.connect(**db_config)
|
|
|
-cursor = cnx.cursor()
|
|
|
-
|
|
|
-
|
|
|
-all_field_names = ['key_words', 'search_keys', 'extra_keys', 'category_list', 'tone', 'target_audience',
|
|
|
- 'target_age', 'target_gender', 'address', 'theme']
|
|
|
-
|
|
|
-json_field_names = ['key_words', 'search_keys', 'extra_keys', 'category_list']
|
|
|
-
|
|
|
-normal_field_names = ['tone', 'target_audience',
|
|
|
- 'target_age', 'target_gender', 'address', 'theme']
|
|
|
-
|
|
|
-
|
|
|
-insert_batch = []
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-select_sql = "SELECT * FROM video_content;"
|
|
|
-cursor.execute(select_sql)
|
|
|
-rows = cursor.fetchall()
|
|
|
-print("Reading data from video_content table...")
|
|
|
-print("row count: ", len(rows))
|
|
|
-
|
|
|
-for row in rows:
|
|
|
- video_id = row[1]
|
|
|
-
|
|
|
- for field_name in json_field_names:
|
|
|
-
|
|
|
- json_data = row[all_field_names.index(field_name) + 2]
|
|
|
-
|
|
|
- if not json_data:
|
|
|
- continue
|
|
|
- if json_data[0] != '[':
|
|
|
- continue
|
|
|
-
|
|
|
- tags = json.loads(json_data) if json_data else []
|
|
|
-
|
|
|
- for tag in tags:
|
|
|
- insert_batch.append((video_id, tag, field_name))
|
|
|
-
|
|
|
- for field_name in normal_field_names:
|
|
|
-
|
|
|
- value = row[all_field_names.index(field_name) + 2]
|
|
|
-
|
|
|
- insert_batch.append((video_id, value, field_name))
|
|
|
-
|
|
|
-
|
|
|
- if len(insert_batch) >= 1000:
|
|
|
- cursor.executemany("""
|
|
|
- INSERT INTO video_content_mapping (video_id, tag, tag_type)
|
|
|
- VALUES (%s, %s, %s)
|
|
|
- """, insert_batch)
|
|
|
-
|
|
|
- print(f"Inserting records {len(insert_batch)} rows...")
|
|
|
- insert_batch.clear()
|
|
|
-
|
|
|
-
|
|
|
-if insert_batch:
|
|
|
- cursor.executemany("""
|
|
|
- INSERT INTO video_content_mapping (video_id, tag, tag_type)
|
|
|
- VALUES (%s, %s, %s)
|
|
|
- """, insert_batch)
|
|
|
- print(f"Inserting records {len(insert_batch)} rows...")
|
|
|
-
|
|
|
-
|
|
|
-cnx.commit()
|
|
|
-
|
|
|
-
|
|
|
-cursor.close()
|
|
|
-cnx.close()
|