Skip to content

Instantly share code, notes, and snippets.

@dmaahs2017
Created March 8, 2022 04:32
Show Gist options
  • Save dmaahs2017/58a032c4a056e576be5ae88daf8479cb to your computer and use it in GitHub Desktop.
Save dmaahs2017/58a032c4a056e576be5ae88daf8479cb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import json
import mysql.connector
def main():
with open("combined_bow.json") as f:
x = json.load(f)
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="iw1MbhCngTP42o",
database="emails",
)
cursor = mydb.cursor()
for word, count in x['bow'].items():
sql = "INSERT INTO ham (word, frequency) VALUES (%s, %s)"
values = (word, count)
cursor.execute(sql, values)
mydb.commit()
print(cursor.rowcount, f"record inserted. ({word}, {count})")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment