MCPcopy Create free account
hub / github.com/chinesehuazhou/python-weekly / insert_into_database

Function insert_into_database

resources/weekly_save_count.py:72–89  ·  view source on GitHub ↗
(entries)

Source from the content-addressed store, hash-verified

70 return entries
71
72def insert_into_database(entries):
73 with sqlite3.connect(db_path) as conn:
74 cursor = conn.cursor()
75 for entry in entries:
76 cursor.execute('SELECT issue_no FROM weekly_summary WHERE issue_no = ?', (entry['issue_no'],))
77 if cursor.fetchone() is None:
78 cursor.execute('''
79 INSERT INTO weekly_summary (issue_no, date, article_count, project_count, audio_video_count, hot_topic_count, book_count)
80 VALUES (?, ?, ?, ?, ?, ?, ?)
81 ''', (
82 entry['issue_no'],
83 entry['date'],
84 entry.get('article_count', 0),
85 entry.get('project_count', 0),
86 entry.get('audio_video_count', 0),
87 entry.get('hot_topic_count', 0),
88 entry.get('book_count', 0)
89 ))
90
91def print_all_data():
92 with sqlite3.connect(db_path) as conn:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected