pywallter/tools/databaseinit.py

51 lines
1.2 KiB
Python
Raw Normal View History

2020-11-29 02:05:19 +01:00
#!venv/bin/python
2022-07-10 15:09:03 +02:00
import sqlite3
2020-11-29 02:05:19 +01:00
import os.path
def init_db():
if os.path.isfile('base.db'):
return False
2022-07-10 15:09:03 +02:00
else:
2020-11-29 02:05:19 +01:00
conn = sqlite3.connect('base.db')
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS users(
2022-07-10 15:09:03 +02:00
Mail CHAR(80) PRIMARY KEY UNIQUE NOT NULL,
2020-11-29 02:05:19 +01:00
name TEXT,
2022-07-10 15:09:03 +02:00
alias TEXT,
xmpp TEXT,
2020-11-29 02:05:19 +01:00
passwd TEXT,
avatar TEXT,
2022-07-10 15:09:03 +02:00
nom TEXT,
2020-11-29 02:05:19 +01:00
prenom TEXT,
age TEXT,
2022-07-10 15:09:03 +02:00
website TEXT,
Token CHAR(30),
Mail_rescue TEXT )
""")
2020-11-29 02:05:19 +01:00
conn.commit()
print ('table users OK')
cursor.execute("""
CREATE TABLE IF NOT EXISTS posts(
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
title TEXT,
content TEXT,
time TEXT,
category TEXT,
author TEXT,
status TEXT
)
""")
conn.commit()
conn.close()
print ('table posts OK')
return True
2022-07-10 15:09:03 +02:00
2020-11-29 02:05:19 +01:00
def init_dir():
if os.path.isdir('users'):
return False
else:
os.makedirs('./users/')