Ejemplo n.º 1
0
 def getBanEnd(self, asRelative=False):
     d = self.getDetail("ban_end")
     if asRelative:
         d = [d, ctimes.stamp2german(d), ctimes.stamp2relative(d, True)]
     else:
         d = [d, ctimes.stamp2german(d), ctimes.stamp2relative(d)]
     return d
Ejemplo n.º 2
0
 def getTopbarAwards(self):
     if self.id == -3: return []
     try:
         con = lite.connect('databases/pilearn.db')
         con.row_factory = lite.Row
         cur = con.cursor()
         cur.execute(
             "SELECT * FROM (SELECT \"reputation\" AS type, SUM(amount) AS data, given_date, message AS label, Null AS class, recognized FROM reputation WHERE user_id=? GROUP BY given_date/3600, label, recognized HAVING data!=0 UNION ALL SELECT \"badge\" AS type, badge_associations.data AS data, badge_associations.given_date, badges.name AS label, badges.class AS class, badge_associations.recognized AS recognized FROM badges, badge_associations WHERE userid=? AND badge_associations.badgeid=badges.id) ORDER BY given_date DESC LIMIT 50",
             (self.id, self.id))
         all = cur.fetchall()
         if all is None:
             return []
         allnew = []
         for i in all:
             i = dict(i)
             d = i["given_date"]
             i["parsed_date"] = [
                 d,
                 ctimes.stamp2german(d),
                 ctimes.stamp2shortrelative(d, False)
             ]
             allnew.append(i)
         return allnew
     except lite.Error as e:
         print(e)
         return []
     finally:
         if con:
             con.close()
Ejemplo n.º 3
0
 def getReputationChanges(self):
     if self.id == -3: return []
     try:
         con = lite.connect('databases/pilearn.db')
         con.row_factory = lite.Row
         cur = con.cursor()
         cur.execute(
             "SELECT *, Sum(amount) AS total_amount FROM reputation WHERE user_id=? GROUP BY given_date/3600, message HAVING total_amount!=0 ORDER BY given_date DESC, id DESC",
             (self.id, ))
         all = cur.fetchall()
         if all is None:
             return []
         allnew = []
         for i in all:
             i = dict(i)
             i["amount"] = i["total_amount"]
             d = i["given_date"]
             i["parsed_date"] = [
                 d,
                 ctimes.stamp2german(d),
                 ctimes.stamp2shortrelative(d, False)
             ]
             allnew.append(i)
         return allnew
     except lite.Error as e:
         return []
     finally:
         if con:
             con.close()
Ejemplo n.º 4
0
 def getCreationDate(self):
     dt = self.getDetail("proposal_date")
     return [
         dt,
         ctimes.stamp2german(dt),
         ctimes.stamp2shortrelative(dt, False)
     ]
Ejemplo n.º 5
0
 def getCreationTime(self):
     t = self.getDetail("proposal_time")
     return [
         t,
         ctimes.stamp2german(t),
         ctimes.stamp2relative(t),
         ctimes.stamp2shortrelative(t)
     ]
Ejemplo n.º 6
0
 def getRoleTable(cls, role):
     try:
         con = lite.connect('databases/pilearn.db')
         con.row_factory = lite.Row
         cur = con.cursor()
         cur.execute("SELECT * FROM role_table WHERE role=?", (role, ))
         data = cur.fetchall()
         DATA = []
         for d in data:
             DATA.append({
                 "id":
                 d["id"],
                 "user":
                 User.from_id(d["user_id"]),
                 "role":
                 d["role"],
                 "scope_comment":
                 d["scope_comment"],
                 "active":
                 bool(d["active"]),
                 "shown":
                 bool(d["shown"]),
                 "appointment_date": [
                     d["appointment_date"],
                     ctimes.stamp2german(d["appointment_date"]),
                     ctimes.stamp2relative(d["appointment_date"])
                 ],
                 "election_link":
                 d["election_link"],
                 "resignation_date": [
                     d["resignation_date"],
                     ctimes.stamp2german(d["resignation_date"]),
                     ctimes.stamp2relative(d["resignation_date"])
                 ],
                 "comment":
                 d["comment"]
             })
         return DATA
     except lite.Error as e:
         return []
     finally:
         if con:
             con.close()
Ejemplo n.º 7
0
 def getReviewBanEnd(self, queue, asRelative=False):
     try:
         con = lite.connect('databases/pilearn.db')
         con.row_factory = lite.Row
         cur = con.cursor()
         cur.execute(
             "SELECT * FROM reviewbans WHERE user_id=? AND invalidated=0 AND end_date>? AND queue=?",
             (self.id, time.time(), queue))
         d = cur.fetchone()["end_date"]
         if asRelative:
             d = [d, ctimes.stamp2german(d), ctimes.stamp2relative(d)]
         return d
     except lite.Error as e:
         raise False
     finally:
         if con:
             con.close()
Ejemplo n.º 8
0
 def getAnnotations(self, order="id"):
     try:
         con = lite.connect('databases/pilearn.db')
         con.row_factory = lite.Row
         cur = con.cursor()
         reverse = False
         if order.endswith("_reverse"):
             reverse = True
             order = order[:-8]
         if order not in ["id", "time", "creator_id", "type"]:
             order = "id"
         elif order == "time":
             order = "creation_date"
         cur.execute(
             "SELECT * FROM annotations WHERE user_id=? ORDER BY " + order +
             " " + ('ASC' if reverse else 'DESC') + ", id DESC",
             (self.id, ))
         d = cur.fetchall()
         data = []
         for d_ in d:
             data.append({
                 "id":
                 d_["id"],
                 "deleted":
                 bool(d_["is_hidden"]),
                 "user_id":
                 d_["user_id"],
                 "creator":
                 User.from_id(d_["creator_id"]),
                 "relative_date":
                 ctimes.stamp2shortrelative(d_["creation_date"]),
                 "absolute_date":
                 ctimes.stamp2german(d_["creation_date"]),
                 "content":
                 d_["content"],
                 "type":
                 d_["type"]
             })
         return data
     except lite.Error as e:
         #raise lite.Error from e
         raise e
     finally:
         if con:
             con.close()
Ejemplo n.º 9
0
 def getSubmissionTime(self):
     dt = int(self.getDetail("submission_time"))
     return [dt, ctimes.stamp2german(dt), ctimes.stamp2shortrelative(dt, False)]