24 lines
		
	
	
		
			No EOL
		
	
	
		
			627 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			No EOL
		
	
	
		
			627 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import sqlite3
 | |
| 
 | |
| def init_db():
 | |
|     conn = sqlite3.connect('subscribers.db')
 | |
|     cursor = conn.cursor()
 | |
|     cursor.execute("""
 | |
|         CREATE TABLE IF NOT EXISTS subscribers (
 | |
|             id INTEGER PRIMARY KEY AUTOINCREMENT,
 | |
|             email TEXT UNIQUE NOT NULL
 | |
|         )
 | |
|     """)
 | |
|     conn.commit()
 | |
|     conn.close()
 | |
| 
 | |
| def add_email(email):
 | |
|     try:
 | |
|         conn = sqlite3.connect('subscribers.db')
 | |
|         cursor = conn.cursor()
 | |
|         cursor.execute("INSERT INTO subscribers (email) VALUES (?)", (email,))
 | |
|         conn.commit()
 | |
|         conn.close()
 | |
|         return True
 | |
|     except sqlite3.IntegrityError:
 | |
|         return False | 
