-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGetFeatures.py
More file actions
164 lines (157 loc) · 4.97 KB
/
Copy pathGetFeatures.py
File metadata and controls
164 lines (157 loc) · 4.97 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import re
import os as op
import VeeQuestCrawler.VeeQuestCrawler.spiders.featurecrawler as crawler
import DatabaseConnection as db
from scrapy.crawler import CrawlerProcess
import ramandsdprocessing as getramandsd
import Constants
"""process = CrawlerProcess({
'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
})
process.crawl(crawler.QuotesSpider)
process.start()"""
global phonename
phonename=""
def getPhoneFeatures():
file=open(Constants.base_file+"\\ScrapedPages\\gsmarenaFeatures\\Page.txt","r")
features={}
global rear,front
for words in file:
regex=re.search('data-spec="[a-zA-Z0-9]*">[a-zA-Z0-9 (),:~+&.\/-]*',words)
regex1=re.search('<td class="ttl"\><a href="glossary.php3\?term=camera"\>[a-zA-Z]*<\/a></td>',words)
if regex1:
temp=regex1.group(0)
if("Single" in temp or "Dual" in temp or "Triple" in temp or "Quad" in temp):
rear=temp[52:]
regex1=re.search('<td class="ttl"\><a href="glossary.php3\?term=secondary-camera"\>[a-zA-Z]*<\/a></td>',words)
if regex1:
temp=regex1.group(0)
if("Single" in temp or "Dual" in temp or "Triple" in temp or "Quad" in temp):
front=temp[62:]
if regex:
temp=regex.group(0)
temp=temp[11:]
temp=temp.split("\">")
print (temp)
features[temp[0]]=temp[1]
values=[]
cursor=db.mydb.cursor()
phoneid=cursor.rowcount+1
values.append(phoneid)
values.append(features["modelname"].lower())
phonename=features["modelname"].lower()
temp=features["year"]
if temp=="-":
values.append(0)
values.append(0)
else:
year=temp[0:4]
values.append(int(year))
month=temp[6:]
switcher = {"January":1,"February":2,"March":3,"April":4,"May":5,"June":6,"July":7,
"August":8,"September":9,"October":10,"November":11,"December":12}
values.append(switcher[month])
if features["weight"]!="-":
values.append(int(features["weight"][0:3]))
else:
values.append(0)
if features["displaysize"]!="-":
values.append(float(features["displaysize"][0:4]))
else:
values.append(0)
if features["displayresolution"] != "-":
values.append(features["displayresolution"][20:25])
else:
values.append("")
ostype = features["os"].split(" ")
if ostype[0]!="-":
values.append(ostype[0])
else:
values.append("")
if ostype[1]!="-":
values.append(ostype[1])
else:
values.append(0)
if features["chipset"]!="-":
values.append(features["chipset"])
else:
values.append("")
if features["cpu"] != "-":
values.append(features["cpu"])
else:
values.append("")
if features["gpu"] != "":
values.append(features["gpu"])
else:
values.append("")
rmp=features["cam1modules"].split(" ")
#try:
rmp=float(rmp[0])
#catch:
values.append(rmp)
if "Single" in rear:
values.append(1)
elif "Dual" in rear:
values.append(2)
elif "Triple" in rear:
values.append(3)
elif "Quad" in rear:
values.append(4)
else:
values.append(0)
fmp=features["cam2modules"].split(" ")
fmp=float(fmp[0])
values.append(fmp)
if "Single" in front:
values.append(1)
elif "Dual" in front:
values.append(2)
elif "Triple" in front:
values.append(3)
elif "Quad" in front:
values.append(4)
else:
values.append(0)
if "Fingerprint" in features["sensors"]:
values.append(True)
else:
values.append(False)
if "gyro" in features["sensors"]:
values.append(True)
else:
values.append(False)
bat=features["batdescription1"].split(" ")
for word in bat:
try:
values.append(int(word))
except ValueError:
continue
try:
pr=features["price"].split(" ")
for word in pr:
try:
values.append(int(word)*80-2000)
except ValueError:
print()
except KeyError:
values.append(0)
query="insert into phonefeatures values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
values=tuple(values)
cursor.execute(query,values)
db.mydb.commit()
variants=features["internalmemory"]
querystmt="SELECT phoneID FROM `phonefeatures` WHERE ModelName=\""+features["modelname"]+"\""
cursor.execute(querystmt)
phid = cursor.fetchone()
variants=getramandsd.getRamAndSD(phid[0],variants)
for info in variants:
query="insert into phonevariants values(%s,%s,%s)"
values=tuple(info)
cursor=db.mydb.cursor(buffered=True)
print("------------------------------------------------------------------",values)
#if len(values)==3:
cursor.execute(query,values)
db.mydb.commit()
return phonename
def getPhoneName():
return phonename