Created
March 8, 2022 04:32
-
-
Save dmaahs2017/58a032c4a056e576be5ae88daf8479cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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