Browse Source

Implemented post and get methods to work with new database

Matteo Zeccoli Marazzini 5 years ago
parent
commit
975942668b
1 changed files with 6 additions and 6 deletions
  1. 6 6
      lcmlog-server

+ 6 - 6
lcmlog-server

@@ -84,7 +84,7 @@ def log_create(kind, date, tags, log):
 		raise FileExistsError()
 	name = hashlib.sha512((kind + date + tags).encode("utf-8")).hexdigest()
 	f = open(DIR + "/data/" + kind + "/" + name, "x")
-	log_add(kind, date, name)
+	log_add(kind, name, date, tags)
 	return f
 
 # Open existing log file with the specified mode
@@ -99,15 +99,15 @@ def log_open(kind, date, mode):
 def log_find(kind, date):
 	with open(DIR + "/data/" + kind + "/.data", "r") as f:
 		for line in f:
-			l = line.split()
-			if l[0] == date:
-				return l[1]
+			l = line.split(":")
+			if l[1] == date:
+				return l[0]
 	return 0
 
 # Add the log to the .data file
-def log_add(kind, date, name):
+def log_add(kind, name, date, tags):
 	with open(DIR + "/data/" + kind + "/.data", "a") as f:
-		f.write(date + " " + name + "\n")
+		f.write(name + ":"  + date + ":" + tags + "\n")
 
 # Print specified log on stdout
 def method_get(kind, date):