-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_carinfo.py
105 lines (91 loc) · 2.63 KB
/
import_carinfo.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
96
97
98
99
100
101
102
103
104
105
# -*- coding: utf-8 -*-
__author__ = "dzt"
__date__ = "2019/4/18"
import requests
import json
from time import sleep
from datetime import datetime
import traceback
headers = {'content-type': 'application/json'}
def import_brand():
f = open("CarInfo.txt")
lines = f.readlines()
l = []
for line in lines:
try:
car_brand = line.replace('\n', '').split(" ")[0].decode('utf-8')
print(car_brand)
if car_brand in l:
continue
l.append(car_brand)
body = {
"car_brand": car_brand
}
res = requests.post("http://www.dogebug.online:9000/fuelcal/carBrand/", data=json.dumps(body), headers=headers)
print(res)
except:
traceback.print_exc()
sleep(1)
pass
f.close()
print(len(l))
def import_series():
f = open("CarInfo.txt")
lines = f.readlines()
l = []
for line in lines:
try:
car_brand = line.replace('\n', '').split(" ")[0].decode('utf-8')
car_series = line.replace('\n', '').split(" ")[1].decode('utf-8')
print(car_series)
if car_series in l:
continue
l.append(car_series)
body = {
"car_brand": car_brand,
"car_series": car_series
}
res = requests.post("http://www.dogebug.online:9000/fuelcal/carSeries/", data=json.dumps(body), headers=headers)
print(res)
except:
traceback.print_exc()
sleep(1)
pass
f.close()
print(len(l))
def import_model():
f = open("CarInfo.txt")
lines = f.readlines()
l = []
for line in lines:
try:
car_series = line.replace('\n', '').split(" ")[1].decode('utf-8')
car_models = line.replace('\n', '').split(" ")[2:]
car_model = ""
for i in car_models:
car_model += i+" "
print(car_model)
l.append(car_model)
body = {
"car_series": car_series,
"car_model": car_model
}
res = requests.post("http://www.dogebug.online:9000/fuelcal/carModel/", data=json.dumps(body), headers=headers)
print(res)
except:
traceback.print_exc()
sleep(1)
pass
f.close()
print(len(l))
if __name__ == '__main__':
time1 = datetime.now()
print(time1)
import_brand()
sleep(1)
import_series()
sleep(1)
import_model()
time2 = datetime.now()
print(time2)
print(str(time2-time1))