|
@@ -0,0 +1,53 @@
|
|
1
|
+import sqlite3
|
|
2
|
+from datetime import datetime
|
|
3
|
+
|
|
4
|
+def create_table_files():
|
|
5
|
+ conn = sqlite3.connect("files.db", detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
|
|
6
|
+ cur = conn.cursor()
|
|
7
|
+ cur.execute("CREATE TABLE files (name VARCHAR(255) PRIMARY KEY, moment DATETIME, length INT);")
|
|
8
|
+ conn.commit()
|
|
9
|
+ conn.close()
|
|
10
|
+
|
|
11
|
+def populate_table_files():
|
|
12
|
+ conn = sqlite3.connect("files.db", detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
|
|
13
|
+ cur = conn.cursor()
|
|
14
|
+ with open("files.txt", "r") as f:
|
|
15
|
+ for line in f:
|
|
16
|
+ file, fsize = line.split(" ")
|
|
17
|
+ fsize = int(fsize.rstrip())
|
|
18
|
+ if file.endswith(".ast"):
|
|
19
|
+ year, month, rem = file.split("-")
|
|
20
|
+ day = rem.split(".")[0]
|
|
21
|
+ cur.execute("INSERT INTO files VALUES (?, ?, ?);", (file, datetime(int(year), int(month), int(day), 0, 0, 0, 0), fsize))
|
|
22
|
+ print("year=%s month=%s day=%s hour=0 minut=0 length=%s" % (year, month, day, fsize))
|
|
23
|
+ else:
|
|
24
|
+ year, month, day, rem = file.split("-")
|
|
25
|
+ compact_moment = rem.split(".")[0]
|
|
26
|
+ hour = compact_moment[:2]
|
|
27
|
+ minut = compact_moment[2:]
|
|
28
|
+ cur.execute("INSERT INTO files VALUES (?, ?, ?);", (file, datetime(int(year), int(month), int(day), int(hour), int(minut), 0, 0), fsize))
|
|
29
|
+ print("year=%s month=%s day=%s hour=%s minut=%s length=%s"%(year, month, day, hour, minut, fsize))
|
|
30
|
+ f.close()
|
|
31
|
+ conn.commit()
|
|
32
|
+ conn.close()
|
|
33
|
+
|
|
34
|
+def unpopulate_table_files():
|
|
35
|
+ conn = sqlite3.connect("files.db", detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
|
|
36
|
+ cur = conn.cursor()
|
|
37
|
+ cur.execute("DELETE FROM files;")
|
|
38
|
+ conn.commit()
|
|
39
|
+ conn.close()
|
|
40
|
+
|
|
41
|
+def query_from_table_files(number=30):
|
|
42
|
+ conn = sqlite3.connect("files.db", detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
|
|
43
|
+ cur = conn.cursor()
|
|
44
|
+ cur.execute("SELECT * FROM files;")
|
|
45
|
+ rows = cur.fetchmany(number)
|
|
46
|
+ conn.close()
|
|
47
|
+ for row in rows:
|
|
48
|
+ print(row)
|
|
49
|
+
|
|
50
|
+# create_table_files()
|
|
51
|
+# populate_table_files()
|
|
52
|
+# unpopulate_table_files()
|
|
53
|
+query_from_table_files()
|