Advertisement
GameNationRDF

script.py

Aug 4th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. #!/usr/bin/python
  2. import cgi
  3. from google.cloud import datastore
  4.  
  5. client = datastore.Client()
  6. key = client.key("carlist")
  7. car = datastore.Entity(key)
  8.  
  9. form = cgi.FieldStorage()
  10.  
  11. search_make = form.getvalue("f_make")
  12. search_model = form.getvalue("f_model")
  13. search_year = form.getvalue("f_year")
  14. search_color = form.getvalue("f_color")
  15. search_price = form.getvalue("f_price")
  16. search_power = form.getvalue("f_power")
  17.  
  18. features = {"make"  : unicode(search_make),
  19.             "model" : unicode(search_model),
  20.             "year"  : int(search_year),
  21.             "color" : unicode(search_color),
  22.             "price" : int(search_price),
  23.             "power" : int(search_power)}
  24. car.update(features)
  25.  
  26. client.put(car)
  27.  
  28. format_price = ("{:,}".format(int(search_price)))
  29.  
  30. print "Content-type:text/html\r\n\r\n"
  31. print "<html>"
  32. print "<head>"
  33. print "<title>Car</title>"
  34. print "</head>"
  35. print "<body>"
  36. print "<h2> Make: "    + search_make  + "</h2>"
  37. print "<h2> Model: "   + search_model + "</h2>"
  38. print "<h2> Year: "    + search_year  + "</h2>"
  39. print "<h2> Color: "   + search_color + "</h2>"
  40. print "<h2> Price: $ " + format_price + "</h2>"
  41. print "<h2> Power: "   + search_power + " HP </h2>"
  42.  
  43. print "<form action=\"http://35.195.58.189/\">"
  44. print "<input type=\"submit\" value=\"Go Back\" />"
  45. print "</form>"
  46.  
  47. print "<form action=\"/cgi-bin/cars.py\">"
  48. print "<input type=\"submit\" value=\"View cars\" />"
  49. print "</form>"
  50.  
  51. print "</body>"
  52. print "</html>"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement