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

Function insert_data

sometask.py:255–276  ·  view source on GitHub ↗

通用数据插入函数

(table_name, data)

Source from the content-addressed store, hash-verified

253
254
255def insert_data(table_name, data):
256 """通用数据插入函数"""
257 if not data:
258 logger.error(f"{table_name} data fetch failed")
259 return
260 cursor = None
261 try:
262 start = time.monotonic()
263 cursor = conn.cursor()
264 if "data" in data:
265 data = data["data"]
266 logger.info(f'Inserting "{table_name}"...')
267 cursor.execute(
268 f'INSERT INTO "{table_name}" (data, insert_time) VALUES (%s, %s)',
269 (json.dumps(data), int(time.time()))
270 )
271 logger.info(f'"{table_name}" inserted in {time.monotonic() - start:.2f}s')
272 except Exception as err:
273 logger.exception(f"Error inserting into {table_name}: {err}")
274 finally:
275 if cursor:
276 cursor.close()
277
278
279if __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