Advertisement
Guest User

aboutfunc.py

a guest
Jul 22nd, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import sqlite3
  2. """
  3. This is a package SPECIFICALLY made to work with myfiles.db
  4. This package is a HELPER to the flask app for klichka's main site.
  5. It's purpose is to black box some features.
  6. """
  7.  
  8. # DECLARATIONS TO FIRE UP THE DATABASE. If you wish to change the database used then just change the code. This is use once!
  9. # 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.
  10.  
  11. thedb = sqlite3.connect('myfiles.db')
  12.  
  13. c = thedb.cursor()
  14. # [(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)]
  15.  
  16. def getFileNames():
  17. """
  18. Returns file names from thedb's mytable
  19. """
  20. c.execute("SELECT Filename from aboutlist")
  21. output = c.fetchall()
  22. return denest(output)
  23.  
  24.  
  25. def denest(nested_data,index=0):
  26. """
  27. Removes the element at 'index' from a list and puts it into a new list.
  28. This is used for denesting items in a structure like [(1,0),(2,5)(3,7)] into [1,2,3]
  29.  
  30. ***this will NOT mutate any parameter***
  31. """
  32. answer = []
  33. for item in nested_data:
  34. answer.append(item[index])
  35. return answer
  36.  
  37. def getFile(filename):
  38. """
  39. Gets the first reference to filename in mytable
  40. This function returns a tuple
  41. """
  42. c.execute('SELECT * FROM aboutlist WHERE Filename=?',(filename,))
  43. myoutput = c.fetchall()
  44. return myoutput[0] # FileName, Sourcecode, Description, Heading
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement