1212random .seed ()
1313
1414base_code = json .dumps ([
15- [ f" { utils .uuid (random .random (), 10 )} " , " def main(text: str) -> None:" ] ,
16- [ f"{ utils .uuid (random .random (), 10 )} " , " print(text)" ] ,
17- [ f"{ utils .uuid (random .random (), 10 )} " , "" ] ,
18- [ f"{ utils .uuid (random .random (), 10 )} " , " if __name__ == \' __main__\' :" ] ,
19- [ f"{ utils .uuid (random .random (), 10 )} " , " main(\' Hello World !\' )" ]
15+ { 'uuid' : f' { utils .uuid (random .random (), 10 )} ' , 'content' : ' def main(text: str) -> None:' } ,
16+ { 'uuid' : f"{ utils .uuid (random .random (), 10 )} " , 'content' : ' print(text)' } ,
17+ { 'uuid' : f"{ utils .uuid (random .random (), 10 )} " , 'content' : '' } ,
18+ { 'uuid' : f"{ utils .uuid (random .random (), 10 )} " , 'content' : ' if __name__ == \' __main__\' :' } ,
19+ { 'uuid' : f"{ utils .uuid (random .random (), 10 )} " , 'content' : ' main(\' Hello World !\' )' }
2020])
2121datetime_format = '%Y-%m-%d %H:%M:%S'
2222
@@ -34,16 +34,14 @@ def __init__(self, host, username, password, database, port):
3434 port = port
3535 )
3636 self .cursor = self .conn .cursor ()
37-
38-
37+
3938 def fetch_as_dict (self , query , args ):
4039 c = self .conn .cursor (dictionary = True )
4140 c .execute (query , args )
4241 return c .fetchone ()
4342
4443 def execute (self , query , args ):
4544 self .cursor .execute (query , args )
46-
4745
4846 def get_document (self , doc_id ):
4947 """Get doc in the databse with id specified
@@ -57,7 +55,6 @@ def get_document(self, doc_id):
5755 query = queries ['get_document' ][self .get_db_mode ()]
5856 return self .fetch_as_dict (query , (doc_id ,))
5957
60-
6158 def update_document (self , doc_id , text_content ):
6259 """Update the document in the db with the id specified
6360
@@ -69,7 +66,6 @@ def update_document(self, doc_id, text_content):
6966 self .execute (query , (text_content , time .strftime (datetime_format ), doc_id ))
7067 self .conn .commit ()
7168
72-
7369 def create_document (self ):
7470 """Create the document with id specified
7571
@@ -88,15 +84,13 @@ def create_document(self):
8884 self .conn .commit ()
8985 return doc_id
9086
91-
9287 def delete_old_document (self , days ):
9388 """Delete document according to days and their last_viewed_date
9489 """
9590 limit_date = (datetime .datetime .today () - datetime .timedelta (days = days )).strftime (datetime_format )
9691 query = queries ['delete_old_document' ][self .get_db_mode ()]
9792 self .execute (query , (limit_date ,))
9893
99-
10094 @classmethod
10195 def get_db_mode (cls ):
10296 return cls .DB_MODE
0 commit comments