44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
from flask import Flask
|
|
import sqlite3
|
|
import time
|
|
import re
|
|
|
|
app = Flask( 'pywallter' )
|
|
app.config.from_pyfile('config.py')
|
|
|
|
|
|
########################### Variables Globales #################################
|
|
extensionimg = app.config.get('EXT_IMG')
|
|
DATABASE = app.config.get('DATABASE')
|
|
|
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
|
cursor.execute("""SELECT title, creation_date, last_updated FROM Blog_posts """ )
|
|
list_posts=cursor.fetchall()
|
|
for post in list_posts:
|
|
title=post[0]
|
|
tmp = re.sub(r'[^a-zA-Z0-9 ]', '', title.rstrip())
|
|
title_id = tmp.replace(' ', '-')
|
|
newDatePost = ""
|
|
newDateUdatedPost = ""
|
|
if post[1] != '':
|
|
try:
|
|
date_post = time.strptime(post[1], '%d/%m/%Y %H:%M:%S')
|
|
except:
|
|
print(title +'-- Posted at: '+ post[1] + ' Not modified: The date is not in the old format')
|
|
newDatePost = post[1]
|
|
else:
|
|
newDatePost = time.strftime("%Y-%m-%d %H:%M:%S", date_post)
|
|
if post[2] != '':
|
|
try:
|
|
last_updated_post = time.strptime(post[2], '%d/%m/%Y %H:%M:%S')
|
|
except:
|
|
print(title + '-- Updated at '+ post[2] + ' Not modified: The date is not in the old format')
|
|
newDateUpdatedPost = post[2]
|
|
else:
|
|
newDateUpdatedPost = time.strftime("%Y-%m-%d %H:%M:%S", last_updated_post)
|
|
|
|
cursor.execute("""UPDATE Blog_posts set creation_date=?, last_updated=?, title_id=? WHERE title=?""", (newDatePost, newDateUpdatedPost, title_id, title))
|
|
|
|
conn.commit()
|