import sqlite3
import random
import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup
import ssl
from urllib.request import urlopen
from collections import Counter
import re
conn = sqlite3.connect('EdwardH.sqlite')
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS datasources')
cur.execute('DROP TABLE IF EXISTS StopWords')
cur.execute('DROP TABLE IF EXISTS IMDB')
cur.execute('DROP TABLE IF EXISTS NYT')
cur.execute('CREATE TABLE datasources (id INTEGER PRIMARY KEY ,
datasources INTEGER, description INTEGER, sourceurl WEBSITE )')
cur.execute('CREATE TABLE StopWords(id INTEGER, Word INTEGER, Freq INTEGER)')
cur.execute('CREATE TABLE IMDB(id INTEGER, Word INTEGER, Freq INTEGER )')
cur.execute('CREATE TABLE NYT(id INTEGER, Word INTEGER, Freq INTEGER )')
a1 = 0
a2 = 0
c1 = 0
count = {}
fhand1 = urllib.request.urlopen('https://raw.githubusercontent.com/nimdvir/teaching/master/stopwords.txt')
для строки в fhand1: print (line.decode (). Strip ())
for w in fhand1.read().strip().split():
c1 += 1
w = w.lower();
if w in count:
count[w] += 1
else:
count[w] = 1
for w, freq in count.items():
cur.execute('INSERT INTO StopWords (id, Word, Freq ) VALUES(?,?,?)',
(c1, w,count))
print(c1)
c2 = 0
count = {}
fhand2 = urllib.request.urlopen('https://raw.githubusercontent.com/nimdvir/teaching/master/imdb.txt')
for line in fhand2:
print(line.decode().strip())
for w in fhand2.read().split():
w = w.lower();
if w in count:
count[w] += 1
else:
count[w] = 1
for word, freq in count.items():
cur.execute('INSERT INTO IMDB (id, Word, Freq ) VALUES(?, ?,?)'
(c2,w,count))
count={}
fhand3 = urllib.request.urlopen('https://raw.githubusercontent.com/nimdvir/teaching/master/nyt.txt')
for line in fhand3:
print(line.decode().strip())
for w in fhand3.read().split():
w = w.lower();
if w in count:
count[w] += 1
else:
count[w] = 1
for word, freq in count.items():
cur.execute('INSERT INTO StopWords ( Word, Freq ) VALUES(?,?)',(w,count))
Я хочу запустить базу данных через StopWords, IMDB и NYT, но все равно нет результатов . Я исследовал db.commit () и не уверен, где конкретно его разместить. РЕДАКТИРОВАТЬ: Я добавил полный код, чтобы вы могли увидеть все и, возможно, найти проблему.