-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker.py
81 lines (58 loc) · 2.18 KB
/
tracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import datetime
from model import db, User, Image
import requests
import os
from passlib.hash import bcrypt
from PIL import Image as pilImage
from flask import flash, session
def check_login(user, password):
""" check if a users login credetials are correct """
# query for any users with that username
active_user = db.session.query(User.password, User).filter(User.username == user,
).first()
# if there is a matching user
if active_user and bcrypt.verify(password, active_user[0]):
flash( "Login Successful")
session['user'] = active_user[1].user_id
return '/user'
# if there is not a user with that username and password combo
else:
flash("Login Failed")
return '/login'
def time_difference_now(time): # pragma: no cover
""" Find how much time has passed since a datetime in days"""
NOW = datetime.datetime.now()
diff = NOW - time
# day_seconds = diff.seconds/(24.00 * 60 * 60.00)
# days = diff.days + day_seconds
return int(diff.days)
def sort_projects_by_update(projects, time):
""" sort a list of project objects into 2 lists based on update """
need_update = []
update = []
for project in projects:
since_update = time_difference_now(project.updated_at)
if since_update > time:
need_update.append((project, since_update))
else:
update.append((project, since_update))
return need_update, update
def check_username(user):
""" check if a user is in the database """
# active_user = User.query.filter_by(username = user).first()
# if active_user:
# flash( "Login Successful")
# session['user'] = active_user.user_id
# else:
# flash("Login Failed")
def post_project_db_update(project, notes, status, image, user, progress):
""" update a project in the db and ravelry site """
project.notes = notes
project.progress = progress
if status:
project.status_id = int(status)
project.updated_at = datetime.datetime.now()
if image:
photo = Image(url=image, project_id=project.project_id)
db.session.add(photo)
db.session.commit()