-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ebay_GetAllItemData.py
95 lines (82 loc) · 2.94 KB
/
Ebay_GetAllItemData.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
from ebaysdk.finding import Connection
from ebaysdk.shopping import Connection as shop
import datetime
from pytz import timezone
import SQLiter
import sys
cats = {}
rightNow= datetime.datetime.now()
searchTime = datetime.datetime.now(timezone('GMT')) - datetime.timedelta(hours=1)
searchTime = searchTime.strftime("%Y-%m-%dT%H:%M:%S.000Z")
s = SQLiter.sqliter()
def getCatIds():
api = shop(appid='', config_file=None)
api.execute('GetCategoryInfo', {'CategoryID':'-1', "IncludeSelector":"ChildCategories"})
CatIDs = api.response_dict().CategoryArray.Category
ids = []
for i in CatIDs[1:]:
ids.append(i.CategoryID)
cats.update({i.CategoryID:i.CategoryName})
return ids
def getSampleData(id):
try:
api = Connection(appid='', config_file=None)
response = api.execute('findCompletedItems', {
"categoryId": "{}".format(id),
"paginationInput": [
{
"pageNumber": "1"
}
],
"itemFilter": [
{
"name": "SoldItemsOnly",
"value": True
},
{
"name": "EndTimeFrom",
"value": searchTime
}
]
}
)
return response.reply.searchResult.item
except:
pass
def insertData(itemID, Title, URL, PrimaryCat, Start, End, id):
s.setupConnection()
sqlCmd = 'INSERT INTO EbayItems (ItemID, Title, URL, RootCategory, PrimaryCategory, StartTime, EndTime) VALUES ("{}", "{}", "{}", "{}", "{}", "{}", "{}");'.format(itemID, Title, URL, cats[id], PrimaryCat, Start, End)
s.insert(sqlCmd)
def insertKeywordData(itemTitle, id):
keywords=[]
badKeywords = ["#", "|", "no", "vs.", "-", "the", "a", "new", "(", ")", "of", "&", "and", "old", "by", "with",
"plus", "for", "size", "to", "vs", "versus", "tested", "in", "/", "~", ":", "w/", "+", ",", "on"]
keys = itemTitle.split()
for k in keys:
if k.lower() in badKeywords:
pass
else:
k = k.replace("(", "")
k = k.replace(")", "")
k = k.replace(",", "")
keywords.append(k.lower())
for k in keywords:
#try:
sqlCmd = """INSERT INTO keywords (keyword, category, timestamp) VALUES ("{}", "{}", "{}");""".format(k,cats[id], rightNow)
s.insert(sqlCmd)
# except:
# e = sys.exc_info()[0]
# print e
def main():
ids = getCatIds()
for id in ids:
try:
sample = getSampleData(id)
for data in sample:
insertData(data.itemId, data.title, data.viewItemURL, data.primaryCategory.categoryName, data.listingInfo.startTime, data.listingInfo.endTime, id)
insertKeywordData(data.title, id)
except:
e = sys.exc_info()[0]
print e
main()
s.close()