Advertisement
Guest User

Untitled

a guest
Apr 4th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. [daily_psg_report.py]
  2.  
  3. #Import libraries
  4.  
  5. import requests
  6. import http.client
  7. import datetime
  8. import Your-Postgres-Script
  9.  
  10. #Declare date variable as string and format for URL
  11.  
  12. now = datetime.datetime.now()
  13.  
  14. dateStr = now.strftime("%m") + "%2" + now.strftime("%d") + "%2" + now.strftime("%Y")
  15.  
  16. #Set HTTP variables
  17.  
  18. httpHeaders = "HTTP/1.0 encoding = csv/xlsv"
  19. url = "http://cccis.com/report?from=" + dateStr + "&to=" + dateStr + "&otherParameters"
  20. authUser = "Username"
  21. authPass = "password"
  22.  
  23. #Execute GET request by setting variable as the reponse
  24.  
  25. resp = requests.get(url, headers=httpHeaders,auth=(authUser,authPass))
  26.  
  27. #Pass response (as file) to function in your Postgres INSERT script
  28.  
  29. postgresInsert(resp.content)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement