Advertisement
Guest User

Script to add sprints to sprints table

a guest
Apr 29th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # Script to add sprints to the sprints table automatically. Not part of main ETL
  4. import psycopg2
  5. import datetime
  6.  
  7. # Sets up database connection
  8. db = psycopg2.connect("dbname=qdwstage user=qdwadmin host=172.17.97.57 password=Olap123$")
  9. cursor = db.cursor()
  10. db.commit()
  11.  
  12. # Sets initial values
  13. sprint = 55
  14. startdate = datetime.datetime(2016, 5, 30)
  15. startdayid = 1172
  16.  
  17. # Adds rows while sprint is less that 70. 70 is arbritray in this case
  18. while sprint < 70:
  19.     # Creates an end date based on the start date
  20.     end = startdate + datetime.timedelta(days=11)
  21.  
  22.     # Formats the dates into nice text to fill the name field
  23.     start = startdate.strftime("(%Y %b %d - ")
  24.     end = end.strftime("%b %d)")
  25.     name = 's' + str(sprint) + ' ' + start+end
  26.     print(name)
  27.  
  28.     # Inserts the values into the table
  29.     cursor.execute("INSERT INTO public.sprints VALUES (%s,%s,%s,%s,%s,%s,%s)", (sprint, name, startdayid, startdayid + 13, startdayid +2, startdayid + 15, False))
  30.  
  31.     # Increments counter variables in preperation for adding next sprint
  32.     startdate += datetime.timedelta(days=14)
  33.     startdayid += 14
  34.     sprint += 1
  35.  
  36. db.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement