Advertisement
Guest User

Untitled

a guest
Oct 7th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf8 -*-
  3.  
  4.  
  5.  
  6. import sys, csv, codecs, webbrowser
  7.  
  8. #Turbolister CSV File
  9. tl_csv_file = "/home/Turbolister_CSV.csv"
  10.  
  11. #Define CSV Reader
  12. tl_csv_reader = csv.DictReader(codecs.open(tl_csv_file, "rb"),delimiter=';')
  13.  
  14. #Choose search type
  15. def def_search_type():
  16.     print "\nsearch script for turbolister csv file\n"
  17.     search_type = raw_input("search for code[c], title[t] or desription[d]?:\n")
  18.     return search_type
  19.  
  20.  
  21. def code_search():
  22.     new_search = ""
  23.     while new_search != "n":
  24.         tl_csv_reader = csv.DictReader(codecs.open(tl_csv_file, "rb"),delimiter=';')
  25.         input_code = raw_input("please enter product to search for: ")
  26.         results=[]
  27.         for line in tl_csv_reader:
  28.             if line["Custom Label"].count(input_code):
  29.                 results.append((line["Custom Label"], line["Title"], line["Description"]))
  30.                 print line["Custom Label"]
  31.         len_results = len(results)
  32.         print "%s results, open in browser?" % len_results
  33.         opentrue = raw_input("y/n\n")
  34.         if opentrue == "y":
  35.             results_file = "/tmp/result_file1.html"
  36.             f = open(results_file, 'w')
  37.             for product in results:
  38.                 print len(product)
  39.                 f.write(product[2])
  40.             f.close()
  41.             webbrowser.open(results_file,new=2)
  42.         if opentrue == "n":
  43.             new_search = raw_input("new search? (y/n):\n")
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. while True:
  51.     search_type = def_search_type()
  52.  
  53.     if search_type == "c":
  54.         while True:
  55.             code_search()
  56.  
  57.     elif search_type == "t":
  58.         print "not implemented yet"
  59.  
  60.     elif search_type == "d":
  61.         print "not implemented yet"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement