Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Astreos_Arduino
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hicham Brahimi
Astreos_Arduino
Commits
92f5460b
Commit
92f5460b
authored
5 years ago
by
hichbra
Browse files
Options
Downloads
Patches
Plain Diff
Update fileTosql
parent
ac7582b6
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PC/FileToSql.py
+48
-40
48 additions, 40 deletions
PC/FileToSql.py
PC/server.py
+1
-0
1 addition, 0 deletions
PC/server.py
with
49 additions
and
40 deletions
PC/FileToSql.py
+
48
−
40
View file @
92f5460b
...
@@ -30,26 +30,22 @@ def formatTopicCorrect(topic):
...
@@ -30,26 +30,22 @@ def formatTopicCorrect(topic):
except
:
except
:
return
False
return
False
def
initBDD
():
log
=
open
(
"
logBDD.txt
"
,
"
w
"
)
try
:
db
=
MySQLdb
.
connect
(
host
=
"
localhost
"
,
#"pil-09.univlehavre.lan",
# ================ CONNECTION BDD ================== #
user
=
"
firediag
"
,
try
:
passwd
=
"
firediag$!
"
,
db
=
MySQLdb
.
connect
(
host
=
"
localhost
"
,
#"pil-09.univlehavre.lan",
db
=
"
firediag
"
);
user
=
"
firediag
"
,
return
db
passwd
=
"
firediag$!
"
,
except
Exception
as
ex
:
db
=
"
firediag
"
);
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception Demarrage :
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
except
Exception
as
ex
:
print
(
ex
);
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception Demarrage :
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
log
.
close
()
print
(
ex
);
sys
.
exit
(
1
)
log
.
close
()
sys
.
exit
(
1
)
def
recuperationTopic
(
db
):
topics
=
[]
# ================ RECUPERATION TOPIC ================= #
topics
=
[]
try
:
#--- Recupere les topic des capteurs en base de donnees
#--- Recupere les topic des capteurs en base de donnees
requete
=
"
SELECT DISTINCT topic FROM capteur
"
requete
=
"
SELECT DISTINCT topic FROM capteur
"
cursor
=
db
.
cursor
();
cursor
=
db
.
cursor
();
...
@@ -58,20 +54,12 @@ try:
...
@@ -58,20 +54,12 @@ try:
# On filtre les mauvais topics (qui ne peuvent pas etre split par /)
# On filtre les mauvais topics (qui ne peuvent pas etre split par /)
if
formatTopicCorrect
(
row
[
0
]):
if
formatTopicCorrect
(
row
[
0
]):
topics
.
append
(
row
[
0
])
topics
.
append
(
row
[
0
])
except
Exception
as
ex
:
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception Init :
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
print
(
ex
);
log
.
close
()
sys
.
exit
(
1
)
print
(
"
Topics :
"
,
topics
)
return
topics
# ================ RECUPERATION ID ================= #
def
recuperationId
(
db
):
tabId
=
{}
tabId
=
{}
try
:
#--- Recupere les id des capteurs en fonction des topics
#--- Recupere les id des capteurs en fonction des topics
for
topic
in
topics
:
for
topic
in
topics
:
requete
=
"
SELECT DISTINCT id FROM capteur WHERE topic =
'"
+
topic
+
"'"
requete
=
"
SELECT DISTINCT id FROM capteur WHERE topic =
'"
+
topic
+
"'"
...
@@ -79,22 +67,39 @@ try:
...
@@ -79,22 +67,39 @@ try:
cursor
.
execute
(
requete
)
cursor
.
execute
(
requete
)
idTab
=
cursor
.
fetchall
()
idTab
=
cursor
.
fetchall
()
tabId
[
topic
]
=
int
(
idTab
[
0
][
0
])
tabId
[
topic
]
=
int
(
idTab
[
0
][
0
])
except
Exception
as
ex
:
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception Init :
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
print
(
ex
);
log
.
close
()
sys
.
exit
(
1
)
print
(
"
Id :
"
,
tabId
)
return
tabId
log
=
open
(
"
logBDD.txt
"
,
"
w
"
)
FOLDER
=
"
./data/
"
TRAITEES
=
"
./traitees/
"
# ================ CONNECTION BDD ================== #
db
=
initBDD
()
# ================ File ==> SQL ================= #
# ================ File ==> SQL ================= #
while
(
True
):
while
(
True
):
FOLDER
=
"
./data/
"
topics
=
[]
TRAITEES
=
"
./traitees/
"
tabId
=
{}
DIR
=
os
.
listdir
(
FOLDER
)
DIR
=
os
.
listdir
(
FOLDER
)
DIR
.
sort
()
DIR
.
sort
()
try
:
# ================ RECUPERATION TOPIC ================= #
topics
=
recuperationTopic
(
db
)
# ================ RECUPERATION ID ================= #
tabId
=
recuperationId
(
db
)
print
(
"
Id :
"
,
tabId
)
except
:
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception Init :
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
print
(
ex
);
db
=
initBDD
()
continue
cursor
=
db
.
cursor
();
cursor
=
db
.
cursor
();
#--- Parcours les fichiers, ajoute les valeurs en base et supprime le fichier
#--- Parcours les fichiers, ajoute les valeurs en base et supprime le fichier
...
@@ -129,7 +134,10 @@ while(True):
...
@@ -129,7 +134,10 @@ while(True):
sys
.
exit
(
0
)
sys
.
exit
(
0
)
except
Exception
as
ex
:
except
Exception
as
ex
:
db
.
rollback
();
try
:
db
.
rollback
();
except
:
db
=
initBDD
()
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception Requete :
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception Requete :
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
print
(
"
rollback
"
);
print
(
"
rollback
"
);
print
(
ex
);
print
(
ex
);
...
...
This diff is collapsed.
Click to expand it.
PC/server.py
+
1
−
0
View file @
92f5460b
...
@@ -53,3 +53,4 @@ while True:
...
@@ -53,3 +53,4 @@ while True:
except
Exception
as
ex
:
except
Exception
as
ex
:
print
(
"
Exception
"
,
type
(
ex
))
print
(
"
Exception
"
,
type
(
ex
))
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment