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
43d98161
Commit
43d98161
authored
6 years ago
by
hichbra
Browse files
Options
Downloads
Patches
Plain Diff
fix fileToSql
parent
39c7be9c
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
+43
-21
43 additions, 21 deletions
PC/FileToSql.py
PC/server.py
+1
-1
1 addition, 1 deletion
PC/server.py
with
44 additions
and
22 deletions
PC/FileToSql.py
+
43
−
21
View file @
43d98161
...
...
@@ -3,26 +3,43 @@ import time
import
sys
import
os
import
csv
import
shutil
from
datetime
import
datetime
db
=
MySQLdb
.
connect
(
host
=
"
localhost
"
,
#"pil-09.univlehavre.lan",
user
=
"
firediag
"
,
passwd
=
"
firediag$!
"
,
db
=
"
firediag
"
);
log
=
open
(
"
logBDD.txt
"
,
"
w
"
)
nomCapteur
=
"
Moule A
"
try
:
db
=
MySQLdb
.
connect
(
host
=
"
localhost
"
,
#"pil-09.univlehavre.lan",
user
=
"
firediag
"
,
passwd
=
"
firediag$!
"
,
db
=
"
firediag
"
);
except
Exception
as
ex
:
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception Demarrage :
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
print
(
ex
);
log
.
close
()
sys
.
exit
(
1
)
nomCapteur
=
"
Moule A
"
# A0 / A1 / A2 / A3 / A4 / A5
tabId
=
{}
#--- Recupere les id des capteurs en base de donnees
for
i
in
range
(
0
,
6
):
requete
=
"
SELECT DISTINCT id FROM capteur WHERE nom =
'"
+
nomCapteur
+
""
+
str
(
i
)
+
"'"
cursor
=
db
.
cursor
();
cursor
.
execute
(
requete
)
idTab
=
cursor
.
fetchall
()
tabId
[
"
A
"
+
str
(
i
)]
=
int
(
idTab
[
0
][
0
])
try
:
#--- Recupere les id des capteurs en base de donnees
for
i
in
range
(
0
,
6
):
requete
=
"
SELECT DISTINCT id FROM capteur WHERE nom =
'"
+
nomCapteur
+
""
+
str
(
i
)
+
"'"
cursor
=
db
.
cursor
();
cursor
.
execute
(
requete
)
idTab
=
cursor
.
fetchall
()
tabId
[
"
A
"
+
str
(
i
)]
=
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
(
tabId
)
FOLDER
=
"
./data/
"
TRAITEES
=
"
./traitees/
"
DIR
=
os
.
listdir
(
FOLDER
)
DIR
.
sort
()
...
...
@@ -30,9 +47,9 @@ cursor = db.cursor();
#--- Parcours les fichiers, ajoute les valeurs en base et supprime le fichier
for
f
in
DIR
:
try
:
print
(
FOLDER
+
f
)
with
open
(
FOLDER
+
f
,
'
r
'
)
as
csvfile
:
print
(
FOLDER
+
f
)
with
open
(
FOLDER
+
f
,
'
r
'
)
as
csvfile
:
try
:
#--- Recupere la source du fichier
id
=
csvfile
.
readline
().
strip
().
split
(
"
:
"
)[
1
]
print
(
id
)
...
...
@@ -47,9 +64,14 @@ for f in DIR:
requete
=
"
INSERT INTO `valeur` (`temps`, `valeur`, `idCapteur`) VALUES (
'"
+
str
(
time
).
strip
()
+
"'
,
'"
+
str
(
row
[
i
+
1
]).
strip
()
+
"'
,
'"
+
str
(
tabId
[
"
A
"
+
str
(
i
)])
+
"'
)
"
cursor
.
execute
(
requete
)
#print(row)
db
.
commit
();
os
.
remove
(
FOLDER
+
f
)
except
Exception
as
e
:
db
.
rollback
();
print
(
"
rollback
"
);
print
(
e
);
except
Exception
as
ex
:
db
.
rollback
();
log
.
write
(
str
(
datetime
.
now
())
+
"
==> Exception Requete :
"
+
str
(
type
(
ex
))
+
"
(
"
+
str
(
ex
.
args
)
+
"
)
\n
"
)
print
(
"
rollback
"
);
print
(
ex
);
db
.
commit
();
#os.remove(FOLDER+f)
shutil
.
move
(
FOLDER
+
f
,
TRAITEES
+
f
)
db
.
close
();
log
.
close
()
This diff is collapsed.
Click to expand it.
PC/server.py
+
1
−
1
View file @
43d98161
...
...
@@ -6,7 +6,7 @@ from datetime import datetime
CHUNK_SIZE
=
2048
PORT
=
20000
log
=
open
(
"
log.txt
"
,
"
w
"
)
log
=
open
(
"
log
Server
.txt
"
,
"
w
"
)
file
=
None
while
True
:
...
...
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