Example #1
0
 def connect_database(self):
     """ Connect to Database or Create database folders and file if file not exist
     """
     if os.path.exists(os.path.join(DATABASE_PATH, "WithSJ_Database")):
         conn = connect_database()
         self.config_database(conn)
     else:
         os.mkdir(os.path.join(DATABASE_PATH, "WithSJ_Database"))
         self.connect_database()
         print("Database successfully created")
Example #2
0
 def get_blogid(self, h_link=hex(randint(0, 32))[2:]):
     blogid = self.title.replace(" ", "+") + "+" + h_link
     conn = connect_database()
     cur = conn.cursor()
     cur.execute("SELECT * FROM Blogs WHERE BlogID = :blogid",
                 {"blogid": blogid})
     data = cur.fetchone()
     if data == None:
         return blogid
     else:
         h_link = hex(randint(0, 32 * 2))[2:]
         self.get_blogid(h_link)
Example #3
0
 def upload(self):
     conn = connect_database()
     conn.execute(
         """
     INSERT INTO Portfolio(Title,Date,Post)
     VALUES(:title,:date,:post)
     """, {
             "title": self.title,
             "date": self.date,
             "post": self.post
         })
     conn.commit()
     conn.close()
Example #4
0
 def data(self):
     conn = connect_database()
     cur = conn.cursor()
     cur.execute("""SELECT * FROM Blogs WHERE BlogID = :blogid""",
                 {"blogid": self.Blog_ID})
     data = cur.fetchone()
     data_dict = {
         "title": data[0],
         "date": data[1],
         "post": data[2],
         "blogid": data[3]
     }
     del data
     return data_dict
Example #5
0
 def data(self):
     """Get all data from blogs table"""
     conn = connect_database()
     cur = conn.cursor()
     cur.execute("SELECT * FROM Blogs ORDER BY Date DESC")
     data_dic_list = list()
     data_dict = dict()
     data_list = cur.fetchall()
     for data in data_list:
         data_dict["title"] = data[0]
         data_dict["date"] = data[1]
         data_dict["post"] = BeautifulSoup(data[2]).get_text()
         data_dict["blogid"] = data[3]
         data_dic_list.append(data_dict)
         data_dict = dict()
     del data_dict, data_list
     return data_dic_list
Example #6
0
    def upload(self):
        rand_link = hex(randint(0, 32))[2:]
        get_blogid = self.get_blogid(h_link=rand_link)

        if self.image != None:
            self.image.save(app.root_path + "/static/images/" + get_blogid)

        conn = connect_database()
        conn.execute(
            """
        INSERT INTO Blogs(Title,Date,Post,BlogID)
        VALUES(:title,:date,:post,:blogid)
        """, {
                "title": self.title,
                "date": self.date,
                "post": self.post,
                "blogid": get_blogid
            })
        conn.commit()
        conn.close()
Example #7
0
 def data(self):
     """Get all data from portfolio table"""
     conn = connect_database()
     cur = conn.cursor()
     cur.execute("SELECT * FROM Portfolio")
     return cur.fetchall()