Advertisement
Guest User

Untitled

a guest
Feb 1st, 2014
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import sqlite3 as lite
  2.  
  3.  
  4. def create():
  5.     con = lite.connect('kilo40.db')
  6.     cur = con.cursor()
  7.  
  8.     p_file = open("photos.txt").readlines()
  9.  
  10.     result = []
  11.     id_w = ''
  12.     photo_link = ''
  13.     lose = 0
  14.     for elem in p_file:
  15.         try:
  16.             id_w, photo_link = elem.replace('\n', '').split(' : ')
  17.             result.append([int(id_w), photo_link])
  18.         except:
  19.             lose+=1
  20.             print lose
  21.  
  22.  
  23.     with con:
  24.         cur.execute("DROP TABLE IF EXISTS Photos")
  25.         cur.execute("CREATE TABLE Photos(Id INT, link TEXT)")
  26.         cur.executemany("INSERT INTO Photos VALUES(?, ?)", result)
  27.  
  28.  
  29. def main():
  30.     con = lite.connect('kilo40.db')
  31.     cur = con.cursor()
  32.     cur.execute("SELECT link FROM Photos WHERE id=9207738")
  33.  
  34.     rows = cur.fetchall()
  35.     for elem in rows:
  36.         print elem
  37.  
  38.  
  39. if __name__ == '__main__':
  40.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement