Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. import psycopg2
  2.  
  3. conn = psycopg2.connect(host="194.182.74.138",
  4.                         dbname="vkbot_db",
  5.                         user="vkbot_user",
  6.                         password="vkbot_password")
  7.  
  8. cursor = conn.cursor()
  9.  
  10. BACKSLASH = '\n'
  11.  
  12. def swearwords_fillng(file: str):
  13.     with open(file, 'rt') as text_file:
  14.         for line in text_file.readlines():
  15.             print(line.strip('\n').lower())
  16.             cursor.execute(f"""
  17.                            INSERT INTO public."Key Words"(
  18.                                 word, word_type_choice)
  19.                             VALUES ('{line.strip(BACKSLASH).lower()}', 'SWR');
  20.                           """)
  21.         conn.commit()
  22.  
  23. def goodbyewords_fillng(file: str):
  24.     with open(file, 'rt') as text_file:
  25.         for line in text_file.readlines():
  26.             print(line.strip('\n').lower())
  27.             cursor.execute(f"""
  28.                            INSERT INTO public."Key Words"(
  29.                                 word, word_type_choice)
  30.                             VALUES ('{line.strip(BACKSLASH).lower()}', 'GDB');
  31.                           """)
  32.         conn.commit()
  33.  
  34. def welcomewords_fillng(file: str):
  35.     with open(file, 'rt') as text_file:
  36.         for line in text_file.readlines():
  37.             print(line.strip('\n').lower())
  38.             cursor.execute(f"""
  39.                            INSERT INTO public."Key Words"(
  40.                                 word, word_type_choice)
  41.                             VALUES ('{line.strip(BACKSLASH).lower()}', 'WLC');
  42.                           """)
  43.         conn.commit()
  44.  
  45. goodbyewords_fillng(file='additional_modules/goodbyewords.txt')
  46. swearwords_fillng(file='additional_modules/swearwords.txt')
  47. welcomewords_fillng(file='additional_modules/welcomewords.txt')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement