Guest User

Untitled

a guest
Jan 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import pycurl
  2. import csv
  3. from mydb import cursor
  4. from MySQLdb import escape_string
  5.  
  6. class Body:
  7. def __init__(self):
  8. self.contents = ''
  9.  
  10. def gotData(self, buffer):
  11. self.contents = self.contents + buffer
  12.  
  13. login_url = "http://localhost/handleLogin.php"
  14. insert_url = "http://localhost/actions/populateAdmin.php"
  15. cookie_file = "/tmp/wl_cookie"
  16.  
  17. try:
  18. csvfile = sys.argv[1]
  19. except:
  20. print "Usage %s CSVfile" % sys.argv[0]
  21. sys.exit(1)
  22.  
  23. # Login in to get a valid session
  24. curl = pycurl.Curl()
  25. body = Body()
  26.  
  27. payload = [("username", "sts"), ("passwd", "msts")]
  28. try:
  29. curl.setopt(curl.URL, login_url)
  30. curl.setopt(curl.COOKIEJAR, cookie_file)
  31. curl.setopt(curl.HTTPPOST, payload)
  32. curl.setopt(curl.WRITEFUNCTION, body.gotData)
  33. curl.perform()
  34. curl.close()
  35. print body.contents
  36. except:
  37. print "Local Curl Failed"
  38. print "URL: ", insert_url
  39. print "Payload: ", payload
  40. print "Result: ", body.contents
  41. sys.exit(2)
  42.  
  43. reader = csv.reader(open(csvfile, 'r'))
  44.  
  45. for row in reader:
  46.  
  47. try:
  48. **(location_id, vrm, valid_datetime) = [x.decode('utf-8-sig') for x in row ]**
  49. except:
  50. print "Error with row: " % row
  51. sys.exit(3)
  52.  
  53. **# Hack for Peel
  54. if (location_id == 295):
  55. location_id = "295"**
  56.  
  57. curl = pycurl.Curl()
  58. body = Body()
  59.  
  60. payload = [("fn", "addWhitelistEntryValue"),
  61. ("firstname", "WL"),
  62. ("surname", "USER"),
  63. ("vrm", vrm.encode('ascii', 'ignore')),
  64. ("locId", location_id.encode('ascii', 'ignore'))
  65. ]
  66. print payload
Add Comment
Please, Sign In to add comment