-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.py
executable file
·114 lines (94 loc) · 2.94 KB
/
query.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
106
107
108
109
110
111
112
113
114
import urllib as ur
import json
import sys
import random
base_url = "http://api.autoidlabs.ch"
def load(y,x):
iurl = '%s/%s/%s' % (base_url, y, x)
f = ur.urlopen(iurl)
data = f.read()
return json.loads(data)
OneArg = lambda y: lambda x: load(y, x)
ProductsRating = OneArg('rating')
ProductsLikes = OneArg('likes')
ProductsArticles = OneArg('prodarticles')
CategoriesInfo = OneArg('categories')
ArticlesDetail = OneArg('articles')
def ProductsInfo(product_ean, n):
"""
Product Info
product_ean = "7617027539036"
n = "0"
"""
productinfo_url = '%s/products/%s?n=%s' % (base_url, product_ean, n)
f = ur.urlopen(productinfo_url)
productout = json.loads(f.read())
return productout
def ProductsAvail():
#Availability
store_id = "0150116"
avail_url = base_url + "/availability/" + product_ean + "?store_id=" + store_id
f = ur.urlopen(avail_url)
print(f.read())
def ProductsDetails(article_id):
#Article Details
#article_id = "10000"
article_url = base_url + "/articles/" + str(article_id)
f = ur.urlopen(article_url)
print(f.read())
def ProductsDiscounts():
#Discounts
discounts_url = base_url + "/discounts"
f = ur.urlopen(discounts_url)
print(f.read())
def ProductsSearch():
#Search
text = "wasser"
search_url = base_url + "/search?text=" + text
f = ur.urlopen(search_url)
print(f.read())
def AllCategories():
categories_url = base_url + "/categories"
f = ur.urlopen(categories_url)
cateout = json.loads(f.read())
return cateout
def AllLeaves(cat):
if 'catMbrs' not in cat:
yield cat
else:
for subcat in cat['catMbrs']:
for mbrs in AllLeaves(subcat):
yield mbrs
def AllLeafCategories():
all_cat = AllCategories()
return AllLeaves(all_cat)
def Brands():
brands_url = base_url + "/brands?search="
brands_product_url = base_url + "/brandproducts/"
term = "Lindt"
#f = ur.urlopen(brands_url + "{" + term + "}")
brand_id = "17"
f = ur.urlopen(brands_product_url + brand_id )
print(f.read())
def transaction(customer_id):
"""
Example:
u'quantNorm': 1, u'pricePerUnit': 0.99, u'migrosEan': u'7617027659239', u'receiptId': u'1714034704', u'id': 106, u'rDate': u'2014-10-01T00:00Z', u'custId': 115883, u'price': 0.99}, {u'quantNorm': 1, u'pricePerUnit': 2.19, u'migrosEan': u'7613269310006', u'receiptId': u'1718833507', u'id': 3629, u'rDate': u'2014-10-05T00:00Z', u'custId': 115883, u'price': 2.19}
"""
#customer_id = "115883"
posdata_url = '%s/pos/%s' % (base_url, customer_id)
f = ur.urlopen(posdata_url)
posout = json.loads(f.read())
return posout
def all_customer_id():
cusid_url = '%s/customerids' % base_url
f = ur.urlopen(cusid_url)
cus_return = f.read()
return cus_return[1:-1].split(',')
def main():
Products()
#Categories()
#Brands()
#PoS()
if __name__ == "__main__":
pass