def addOfficielle(mbrecasconfirme, mbregueris, mbresoustraitement, mbremort): db = connexion.connect(getDbPath.getConnectPath()) result = [] for r in db.query( # just for example "SELECT officielleid, mbrecasconfirme, mbregueris, mbresoustraitement, mbremort " "FROM officielle ORDER BY officielleid desc").dictresult(): result.append(r) res = result if (res == []): print("Insertion de donnée ..........") db.insert('officielle', mbrecasconfirme=mbrecasconfirme, mbregueris=mbregueris, mbresoustraitement=mbresoustraitement, mbremort=mbremort) else: if (int(res[0]['mbrecasconfirme']) == int(mbrecasconfirme) and int(res[0]['mbregueris']) == int(mbregueris) and int( res[0]['mbresoustraitement']) == int(mbresoustraitement) and int(res[0]['mbremort']) == int(mbremort)): print("pas d'évolution des statistiques ") else: print("Stat évoluées") print("Insertion de donnée ..........") db.insert('officielle', mbrecasconfirme=mbrecasconfirme, mbregueris=mbregueris, mbresoustraitement=mbresoustraitement, mbremort=mbremort)
def addMapdb(longitude, latitude, mapdate, numerotel): db = connexion.connect(getDbPath.getConnectPath()) db.insert('mapdb', longitude=longitude, latitude=latitude, mapdate=mapdate, numerotel=numerotel)
def getOne(): db = connexion.connect(getDbPath.getConnectPath()) result = [] for r in db.query( # just for example "SELECT officielleid, mbrecasconfirme, mbregueris, mbresoustraitement, mbremort " "FROM officielle ORDER BY officielleid desc").dictresult(): result.append(r) return result
def getAllActualite(): # print(getDbPath.getConnectPath()) db=connexion.connect(getDbPath.getConnectPath()) result = [] for r in db.query( # just for example "SELECT tableactualiteid, actualite, id_date " "FROM tableactualite ORDER BY tableactualiteid asc" ).dictresult(): result.append(r) return result
def getAllMapdb(): db = connexion.connect(getDbPath.getConnectPath()) result = [] for r in db.query( # just for example "SELECT mapdbid, longitude, latitude, mapdate, numerotel, traite " "FROM mapdb " "where traite='f' " "ORDER BY mapdbid desc ").dictresult(): result.append(r) return result
import sys import os from pg import DB sys.path.append(os.path.join(os.path.dirname(sys.path[0]))) import table.my_connexion as connexion full_path = os.path.realpath(__file__) path, filename = os.path.split(full_path) path = path + "/connectParameters.json" sys.path.append(os.path.join(os.path.dirname(sys.path[0]), 'common_utils')) import getDbPath as getDbPath db = connexion.connect(getDbPath.getConnectPath()) #Return all tables def allTable(): return db.get_tables() #Creation des tables def createTable(): # db.query("DROP DATABASE IF EXISTS acvidimsp") # db.query("create database acvidimsp") # db.query("truncate TABLE entete CASCADE") #mapDb db.query( "create table if not exists mapDb " "(mapDbid serial primary key, longitude varchar, latitude varchar, " "mapdate varchar, numeroTel varchar"
def scrappingActualiteAndSave(): threading.Timer(5.0, scrappingActualiteAndSave).start() actualite = [] actualite_date = [] URL = 'https://www.gouv.bj/coronavirus/flashinfos/' page = requests.get(URL) soup = BeautifulSoup(page.content, 'html.parser') results = soup.find_all("h3", class_="adapt error regular bottom-10") results_day = soup.find_all("div", class_="flex row space middle") for result in results: if None in (result): continue actualite.append(result.text.strip()) for result in results_day: if None in (result): continue actualite_date.append(result.text.strip().split("\n")[0]) #print(actualite_date) db=connexion.connect(getDbPath.getConnectPath()) result = [] r=db.query("SELECT count(actualite) FROM tableactualite").dictresult() res = int(r[0]['count']) #print(actualite) # print((actualite_date)) if (res == 0): i = 0 while (i<len(actualite_date)): print("Insertion de donnée ..........") db.insert('tableactualite', actualite=str(echapper(actualite[i])),id_date= str((findAndReplaceDate(actualite_date[i])))) i = i+1 # print("Insertion de donnée ..........") # # print("Insertion de donnée ..........") # c.execute("INSERT INTO tableactualite (actualite,id_date) \ # VALUES ('" + str(echapper(actualite[i])) + # "' ,'" + str(actualite_date[i])+"')") # i = i +1 # conn.commit() else: if(int(res)==len(actualite_date)): print("pas d'évolution des informations") #print(actualite_date) if(int(res) < len(actualite_date) ): taille = len(actualite_date) taille = taille -int(res) print(taille) i = 0 while (i<taille ): print("Insertion de donnée à partir d'index.........."+ str(i)) db.insert('tableactualite', actualite=str(echapper(actualite[i])),id_date= str(findAndReplaceDate(actualite_date[i]))) i = i +1 return actualite_date