-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·59 lines (43 loc) · 1.85 KB
/
test.py
File metadata and controls
executable file
·59 lines (43 loc) · 1.85 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
#!/usr/bin/env python3
import os
from eansearch import EANSearch
# API token for ean-search.org account
# https://www.ean-search.org/ean-database-api.html
apiToken = os.environ['EAN_SEARCH_API_TOKEN']
ean = "5099750442227" # Thriller
#ean = "5099750442228" # error
#ean = "195949821844" # 12-digit UPC
#ean = "5-099750442227" # extra char
eansearch = EANSearch(apiToken)
name = eansearch.barcodeLookup(ean)
if eansearch.error():
print("API error:", eansearch.error())
exit(1)
print(ean + " is ", name if name is not None else "unknown")
# more detailed result, preferably in English (1)
product = eansearch.barcodeSearch(ean, 1)
print(ean, "is", product["name"].encode("utf-8"), "from category", product["categoryName"], "(Google ID", product["googleCategoryId"], ") issued in", product["issuingCountry"])
isbn = "1119578884"
title = eansearch.isbnLookup(isbn)
print(isbn, " is ", title)
ok = eansearch.verifyChecksum(ean)
print(ean, " is ", "OK" if ok else "Not OK")
eanList = eansearch.productSearch('iPod')
for product in eanList:
print(product["ean"], " is ", product["name"].encode("utf-8"))
eanList = eansearch.similarProductSearch('iPod with extra features')
for product in eanList:
print(product["ean"], " is ", product["name"].encode("utf-8"))
eanList = eansearch.categorySearch(45, 'thriller')
for product in eanList:
print(product["ean"], " is ", product["name"].encode("utf-8"))
eanList = eansearch.barcodePrefixSearch('4007249146')
for product in eanList:
print(product["ean"], " is ", product["name"].encode("utf-8"))
country = eansearch.issuingCountryLookup("5099750442227")
print(ean + " was issued in " + country)
barcode = eansearch.barcodeImage("5099750442227", 300, 200)
print("HTML: <img src=\"data:image/png;base64," + barcode + "\">")
#import base64
#print (base64.b64decode(barcode))
print(str(eansearch.creditsRemaining()) + " credits remaining")