-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
95 lines (74 loc) · 3.08 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# coding: utf8
import ast
import json
import csv
from DataHandler import DataHandler
product_dict = {}
text_var = ["model", "builder", "engine", "type"]
i = 0
cr = csv.reader(open("C:/Users/Administrateur/Documents/Click&Boat/Thomas/boat24/boat24/spiders/builders.csv", "rb"))
builders = []
for row in cr:
builders.append(row[0])
builders = [b.replace("\xe9","\u00e9") for b in builders]
with open('C:/Users/Administrateur/Documents/Click&Boat/Thomas/boat24/boat24/spiders/save.json') as data_file:
for z in data_file:
z = ast.literal_eval(z)
i += 1
z["id"] = i
product_dict[i] = z
if "builder" not in z.keys():
for j in builders:
if j in z["model"]:
ur = z["model"]
ur = ur.replace("\u00e9", "é")
z["builder"] = j.replace("\u00e9", "é")
z["builder"] = j.decode("UTF-8")
z["model"] = z["model"].replace(j, '')
with open('test.json') as data_file:
data = json.load(data_file)
data_handler = DataHandler(usr=data["usr"], table=data["table"], url=data["url"], pwd=data["pwd"])
var_map = {'builder':"CONSTRUCTEUR", 'Displacement':"DEPLACEMENT", 'Beam':"MAITRE_BAU", 'Length':"LONGUEUR",
'model':"MODELE", 'type':"TYPE",
'No. of Beds':"CAPACITE_COUCHAGE", 'Max speed':"VITESSE_MAX", 'Range':"RANGE_NAV",
'Engine':"MOTEUR", 'Cruising speed':"VITESSE_CROISIERE",
'Length Waterline':"LONGUEUR_LIGNE_FLOTTAISON", 'Depth':"PROFONDEUR",
'Certified nr. of persons':"CAPACITE_AUTORISEE", 'No. of Cabins':"NOMBRE_CABINE",
'engine power': "PUISSANCE_MOTEUR", "id":"ID_MODELE"}
for z in product_dict.keys():
if "Power Boat" in product_dict[z]["type"]:
if "Rubber" in product_dict[z]["type"]:
product_dict[z]["type"] = 4
else:
product_dict[z]["type"] = 2
elif "Catamaran" in product_dict[z]["type"]:
product_dict[z]["type"] = 3
elif "Trimaran" in product_dict[z]["type"]:
product_dict[z]["type"] = 3
else:
product_dict[z]["type"] = 1
for z in product_dict.keys():
for clef in product_dict[z].keys():
if clef not in text_var:
try:
value = product_dict[z][clef]
value = value.replace('m', '')
value = value.replace('kg', '')
value = value.replace('kn', '')
value = value.replace('kn', '')
value = value.strip()
value = float(value)
product_dict[z][clef] = value
except:
pass
try:
product_dict[z][clef] = product_dict[z][clef].replace("\r\n", " ")
product_dict[z][clef] = product_dict[z][clef].replace("'", " ")
except:
pass
for key in product_dict:
try:
request = "UPDATE modeles SET LONGUEUR = %(long).9f WHERE ID_MODELE = %(id)i"%{"long": product_dict[key]["Length"], "id": product_dict[key]["id"]}
data_handler.exec_request(request)
except:
pass