Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions clean_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import re
import html
import sqlite3

con = sqlite3.connect('works_db')
cur = con.cursor()

# очистка полей от html
info_by_id = cur.execute("SELECT ID, skills, otherInfo FROM works;")

def clean_html(string):
# https://stackoverflow.com/questions/753052/strip-html-from-strings-in-python
tagless = re.sub('<[^<]+?>', '', string)
return html.unescape(tagless).replace('\xa0', '')

cleaned_info = {}
for row in info_by_id:
cl_skills = clean_html(row[1])
cl_other = clean_html(row[2])
cleaned_info[row[0]] = (cl_skills, cl_other)

stmt = "UPDATE works SET skills = ?, otherInfo = ? WHERE ID = ?"
for k, v in cleaned_info.items():
skills = v[0]
other = v[1]
cur.execute(stmt, [skills, other, k])

con.commit()
cur.close()
con.close()
Loading