-
Notifications
You must be signed in to change notification settings - Fork 0
/
eBay_price_predict.py
67 lines (52 loc) · 1.89 KB
/
eBay_price_predict.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
'''
Created on Jan 23, 2016
@author: hanhanwu
Note: have to use eBay Product AppID here, NOT the Sandbox AppID
'''
import datetime
from ebaysdk.exception import ConnectionError
from ebaysdk.finding import Connection
import KNN
import json
import optimization
def get_items(appid, search_keyword, categoryId):
results = []
try:
api = Connection(appid=appid, config_file=None)
response = api.execute('findItemsAdvanced', {'keywords': search_keyword}).json()
item_dict = json.loads(response)
items = item_dict['searchResult']['item']
for item in items:
c_id = item['primaryCategory']['categoryId']
if c_id != categoryId:
continue
autoPay = bool_to_bit(item['autoPay'])
currentPrice = float(item['sellingStatus']['currentPrice']['value'])
condition = float(item['condition']['conditionId'])
results.append({'input': (autoPay, condition), 'price': currentPrice})
except ConnectionError as e:
print(e)
print(e.response.dict())
return results
def bool_to_bit(v):
if v.lower() == 'false':
return 1
else:
return 2
def main():
appid = '[Your eBay Product AppID]' # Change this to your eBay product AppID
search_keyword = 'wine'
categoryId = '38182' # red wine
items = get_items(appid, search_keyword, categoryId)
# using un-weighted KNN
print 'using un-weighted KNN:'
print KNN.get_KNN(items, (1,1000), k = 3)
print KNN.get_KNN(items, (2,2000), k = 3)
print '*********************'
# using weighted KNN
print 'weighted KNN using Gaussian function:'
print KNN.get_weightedKNN(items, (1,1000), k = 3)
print KNN.get_weightedKNN(items, (2,1000), k = 3)
print KNN.get_weightedKNN(items, (2,2000), k = 3)
if __name__ == '__main__':
main()