SHARE
TWEET

Problem

a guest Jun 19th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import zipfile, sqlite3
  2. from pprint import pprint
  3.  
  4. inpx_zip = zipfile.ZipFile('flibusta_fb2_local.inpx')
  5. filelistt = inpx_zip.namelist()
  6. print(filelistt)
  7. finall = []
  8.  
  9. f = open(str(filelistt[1]))
  10. strlistt = f.readlines()
  11. for i in range(len(strlistt)):
  12.     finall.append(strlistt[i].split('\x04'))
  13. #print(finall)
  14.  
  15.  
  16. class Bookbase:
  17.     def __init__(self):
  18.         connection = sqlite3.connect('books.db')
  19.         self.connection = connection
  20.  
  21.     def get_connection(self):
  22.         return self.connection
  23.  
  24.     def init_table(self):
  25.         cursor = self.connection.cursor()
  26.         cursor.execute('''CREATE TABLE IF NOT EXISTS users
  27.                            (id INTEGER PRIMARY KEY AUTOINCREMENT,
  28.                            author_name VARCHAR(40),
  29.                            genre VARCHAR(15),
  30.                            cycle VARCHAR(40),
  31.                            book_name VARCHAR(40),
  32.                            numb_1 VARCHAR(10),
  33.                            numb_2 VARCHAR(10),
  34.                            numb_3 VARCHAR(10),
  35.                            numb_4 VARCHAR(10),
  36.                            numb_5 VARCHAR(10),
  37.                            format VARCHAR(5),
  38.                            date VARCHAR(10),
  39.                            language VARCHAR(5),
  40.                            numb_6 VARCHAR(10))''')
  41.         cursor.close()
  42.         self.connection.commit()
  43.  
  44.     def insert(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13):
  45.         cursor = self.connection.cursor()
  46.         cursor.execute(''' INSERT INTO users
  47.                            (author_name, genre, cycle, book_name, numb_1, numb_2, numb_3, numb_4, numb_5, format, date,
  48.                             language, numb_6)
  49.                            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,) ''',
  50.                        (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13))
  51.         cursor.close()
  52.         self.connection.commit()
  53.  
  54.     def get_all(self):
  55.         cursor = self.connection.cursor()
  56.         cursor.execute("SELECT * FROM author name")
  57.         rows = cursor.fetchall()
  58.         return rows
  59.  
  60.  
  61. exam = Bookbase()
  62. exam.init_table()
  63. for i in range(len(finall)):
  64.         exam.insert(arg1=finall[0], arg2=finall[1], arg3=finall[2], arg4=finall[3], arg5=finall[4],
  65.                     arg6=finall[5], arg7=finall[6], arg8=finall[7], arg9=finall[8], arg10=finall[9],
  66.                     arg11=finall[10], arg12=finall[11], arg13=finall[12])
  67.  
  68. print(exam.get_all())
  69. inpx_zip.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top