MCPcopy Create free account
hub / github.com/datehoer/hotToday / insert_data

Function insert_data

task.py:269–290  ·  view source on GitHub ↗

通用数据插入函数

(table_name, data)

Source from the content-addressed store, hash-verified

267
268
269def insert_data(table_name, data):
270 """通用数据插入函数"""
271 if not data:
272 logger.error(f"{table_name} data fetch failed")
273 return
274 cursor = None
275 try:
276 start = time.monotonic()
277 cursor = conn.cursor()
278 if "data" in data:
279 data = data["data"]
280 logger.info(f'Inserting "{table_name}"...')
281 cursor.execute(
282 f'INSERT INTO "{table_name}" (data, insert_time) VALUES (%s, %s)',
283 (json.dumps(data), int(time.time()))
284 )
285 logger.info(f'"{table_name}" inserted in {time.monotonic() - start:.2f}s')
286 except Exception as err:
287 logger.exception(f"Error inserting into {table_name}: {err}")
288 finally:
289 if cursor:
290 cursor.close()
291
292
293if __name__ == "__main__":

Callers 10

get_weibo_dataFunction · 0.70
get_zhihu_hot_dataFunction · 0.70
get_douyin_hot_dataFunction · 0.70
get_bilibili_hot_dataFunction · 0.70
get_wx_read_rankFunction · 0.70
get_tieba_topicFunction · 0.70
get_juejin_hotFunction · 0.70
get_toutiao_hotFunction · 0.70
get_ssp_hotFunction · 0.70
safe_insertFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected