Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- """
- This is a package SPECIFICALLY made to work with myfiles.db
- This package is a HELPER to the flask app for klichka's main site.
- It's purpose is to black box some features.
- """
- # DECLARATIONS TO FIRE UP THE DATABASE. If you wish to change the database used then just change the code. This is use once!
- # Note however that you cannot change the name name without changing all the code, this can be fixed, but for the scope it will not be.
- thedb = sqlite3.connect('myfiles.db')
- c = thedb.cursor()
- # [(0, u'Filename', u'varchar(255)', 0, None, 0), (1, u'sourcecode', u'text', 0, None, 0), (2, u'description', u'text', 0, None, 0), (3, u'heading', u'text', 0, None, 0)]
- def getFileNames():
- """
- Returns file names from thedb's mytable
- """
- c.execute("SELECT Filename from aboutlist")
- output = c.fetchall()
- return denest(output)
- def denest(nested_data,index=0):
- """
- Removes the element at 'index' from a list and puts it into a new list.
- This is used for denesting items in a structure like [(1,0),(2,5)(3,7)] into [1,2,3]
- ***this will NOT mutate any parameter***
- """
- answer = []
- for item in nested_data:
- answer.append(item[index])
- return answer
- def getFile(filename):
- """
- Gets the first reference to filename in mytable
- This function returns a tuple
- """
- c.execute('SELECT * FROM aboutlist WHERE Filename=?',(filename,))
- myoutput = c.fetchall()
- return myoutput[0] # FileName, Sourcecode, Description, Heading
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement