Advertisement
Guest User

Untitled

a guest
Jul 18th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.11 KB | None | 0 0
  1. username = request.form['user']
  2. user = db_interaction.get_user_info(username)
  3. f = ["a", "b", "c", "d"]
  4. i = 0
  5. id = 0
  6. for field in user:
  7.     if i==3:
  8.         id = field
  9.         break
  10.     else:
  11.         f[i] = str(field)
  12.         i = i+1
  13. uid = str(db_interaction.get_user_id(username))
  14. j = uid.replace('(', '')
  15. d = j.replace(')', '')
  16. id = d.replace(',', '')
  17. notif = Notification()
  18. link = notif.get_subscribe_link(id)
  19. session['user'] = username
  20. session['password'] = f[1]
  21. session['email'] = f[2]
  22. session['id'] = id
  23. session['link'] = link
  24. session['auth'] = "authenticated"
  25. if db_interaction.get_date(username) is not None: #date in db is not null, i.e. we have data from previous days or today
  26.     date_db = db_interaction.get_date(username)
  27.     uid = str(date_db)
  28.     j = uid.replace('(', '')
  29.     d = j.replace(')', '')
  30.     ddb = d.replace(',', '')
  31.     date_curr = datetime.datetime.today().day
  32.     if str(date_curr) != ddb: #data from previous day
  33.         db_interaction.set_sleeps(username, sleep_timestamp[0], sleep_timestamp[1], sleep_timestamp[2], sleep_timestamp[3], sleep_timestamp[4], sleep_timestamp[5], sleep_timestamp[6])
  34.         db_interaction.set_wakes(username, wake_timestamp[0], wake_timestamp[1], wake_timestamp[2], wake_timestamp[3], wake_timestamp[4], wake_timestamp[5], wake_timestamp[6])
  35.         db_interaction.set_kcals(username, kcal[0], kcal[1], kcal[2], kcal[3], kcal[4], kcal[5], kcal[6])
  36.         session['auth'] = "authenticated"
  37.         return render_template('personal.html', user=username, password=f[1], email=f[2], id=f[3], link=link, auth="authenticated"
  38.                                                          day7="7daysAgo", day6="6daysAgo", day5="5daysAgo", day4="4daysAgo", day3="3daysAgo", day2="2daysAgo", day1="1dayAgo",
  39.                                                          cal7=kcal[6], cal6=kcal[5], cal5=kcal[4], cal4=kcal[3], cal3=kcal[2], cal2=kcal[1], cal1=kcal[0],
  40.                                                          sleep7=sleep_timestamp[6], sleep6=sleep_timestamp[5], sleep5=sleep_timestamp[4], sleep4=sleep_timestamp[3], sleep3=sleep_timestamp[2],
  41.                                                          sleep2=sleep_timestamp[1], sleep1=sleep_timestamp[0], wake7=wake_timestamp[6], wake6=wake_timestamp[5], wake5=wake_timestamp[4],
  42.                                                          wake3=wake_timestamp[2], wake2=wake_timestamp[1], wake1=wake_timestamp[0], wake4=wake_timestamp[3])
  43.     else: #data has been saved in the same day
  44.         sleep = db_interaction.get_sleep(username)
  45.         uid = str(sleep)
  46.         j = uid.replace('(', '')
  47.         d = j.replace(')', '')
  48.         sleep = d.replace(',', '')
  49.         wake = db_interaction.get_wake(username)
  50.         uid = str(wake)
  51.         j = uid.replace('(', '')
  52.         d = j.replace(')', '')
  53.         wake = d.replace(',', '')
  54.         if sleep is None: #algorithm hasn't been run yet
  55.             db_interaction.set_sleeps(username, sleep_timestamp[0], sleep_timestamp[1], sleep_timestamp[2], sleep_timestamp[3], sleep_timestamp[4], sleep_timestamp[5], sleep_timestamp[6])
  56.             db_interaction.set_wakes(username, wake_timestamp[0], wake_timestamp[1], wake_timestamp[2], wake_timestamp[3], wake_timestamp[4], wake_timestamp[5], wake_timestamp[6])
  57.             db_interaction.set_kcals(username, kcal[0], kcal[1], kcal[2], kcal[3], kcal[4], kcal[5], kcal[6])
  58.             session['auth'] = "authenticated"
  59.             return render_template('personal.html', user=username, password=f[1], email=f[2], id=f[3], link=link, auth="authenticated"
  60.                                                      day7="7daysAgo", day6="6daysAgo", day5="5daysAgo", day4="4daysAgo", day3="3daysAgo", day2="2daysAgo", day1="1dayAgo",
  61.                                                      cal7=kcal[6], cal6=kcal[5], cal5=kcal[4], cal4=kcal[3], cal3=kcal[2], cal2=kcal[1], cal1=kcal[0],
  62.                                                      sleep7=sleep_timestamp[6], sleep6=sleep_timestamp[5], sleep5=sleep_timestamp[4], sleep4=sleep_timestamp[3], sleep3=sleep_timestamp[2],
  63.                                                      sleep2=sleep_timestamp[1], sleep1=sleep_timestamp[0], wake7=wake_timestamp[6], wake6=wake_timestamp[5], wake5=wake_timestamp[4],
  64.                                                      wake3=wake_timestamp[2], wake2=wake_timestamp[1], wake1=wake_timestamp[0], wake4=wake_timestamp[3])
  65.         else: #algorithm ran
  66.             db_interaction.set_sleeps(username, sleep_timestamp[0], sleep_timestamp[1], sleep_timestamp[2], sleep_timestamp[3], sleep_timestamp[4], sleep_timestamp[5], sleep_timestamp[6])
  67.             db_interaction.set_wakes(username, wake_timestamp[0], wake_timestamp[1], wake_timestamp[2], wake_timestamp[3], wake_timestamp[4], wake_timestamp[5], wake_timestamp[6])
  68.             db_interaction.set_kcals(username, kcal[0], kcal[1], kcal[2], kcal[3], kcal[4], kcal[5], kcal[6])
  69.             session['auth'] = "authenticated"
  70.             session['sleep'] = sleep
  71.             session['wake'] = wake
  72.             return render_template('personal_page.html', user=username, password=f[1], email=f[2], id=f[3], link=link, auth="authenticated", sleep=sleep, wake=wake,
  73.                                                      day7="7daysAgo", day6="6daysAgo", day5="5daysAgo", day4="4daysAgo", day3="3daysAgo", day2="2daysAgo", day1="1dayAgo",
  74.                                                      cal7=kcal[6], cal6=kcal[5], cal5=kcal[4], cal4=kcal[3], cal3=kcal[2], cal2=kcal[1], cal1=kcal[0],
  75.                                                      sleep7=sleep_timestamp[6], sleep6=sleep_timestamp[5], sleep5=sleep_timestamp[4], sleep4=sleep_timestamp[3], sleep3=sleep_timestamp[2],
  76.                                                      sleep2=sleep_timestamp[1], sleep1=sleep_timestamp[0], wake7=wake_timestamp[6], wake6=wake_timestamp[5], wake5=wake_timestamp[4],
  77.                                                       wake3=wake_timestamp[2], wake2=wake_timestamp[1], wake1=wake_timestamp[0], wake4=wake_timestamp[3])
  78.  
  79. else:
  80.     db_interaction.set_sleeps(username, sleep_timestamp[0], sleep_timestamp[1], sleep_timestamp[2], sleep_timestamp[3], sleep_timestamp[4], sleep_timestamp[5], sleep_timestamp[6])
  81.     db_interaction.set_wakes(username, wake_timestamp[0], wake_timestamp[1], wake_timestamp[2], wake_timestamp[3], wake_timestamp[4], wake_timestamp[5], wake_timestamp[6])
  82.     db_interaction.set_kcals(username, kcal[0], kcal[1], kcal[2], kcal[3], kcal[4], kcal[5], kcal[6])
  83.     session['auth'] = "authenticated"
  84.     return render_template('personal.html', user=username, password=f[1], email=f[2], id=f[3], link=link, auth="authenticated"
  85.                                              day7="7daysAgo", day6="6daysAgo", day5="5daysAgo", day4="4daysAgo", day3="3daysAgo", day2="2daysAgo", day1="1dayAgo",
  86.                                              cal7=kcal[6], cal6=kcal[5], cal5=kcal[4], cal4=kcal[3], cal3=kcal[2], cal2=kcal[1], cal1=kcal[0],
  87.                                              sleep7=sleep_timestamp[6], sleep6=sleep_timestamp[5], sleep5=sleep_timestamp[4], sleep4=sleep_timestamp[3], sleep3=sleep_timestamp[2],
  88.                                              sleep2=sleep_timestamp[1], sleep1=sleep_timestamp[0], wake7=wake_timestamp[6], wake6=wake_timestamp[5], wake5=wake_timestamp[4],
  89.                                              wake3=wake_timestamp[2], wake2=wake_timestamp[1], wake1=wake_timestamp[0], wake4=wake_timestamp[3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement