Repository navigation
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·82 lines (62 loc) · 2.39 KB
/
Copy pathtest.py
File metadata and controls
executable file
·82 lines (62 loc) · 2.39 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
#!/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())
if "402" in eansearch.error():
print("Usage limit reached")
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)
if product is not None:
print(ean, "is", product["name"], "from category", product["categoryName"], "(Google ID", product["googleCategoryId"], ") issued in", product["issuingCountry"])
else:
print(ean, "not found:", eansearch.error())
isbn = "1119578884"
title = eansearch.isbnLookup(isbn)
print(isbn, " is ", title)
asin = "B00000J1V5"
ean = eansearch.findEanForAsin(asin)
print("ASIN ", asin, " is EAN ", ean)
ean = "0722868396643"
asin = eansearch.findAsinForEan(ean)
print("EAN ", ean, " is ASIN ", asin)
isbn13 = "9780815346333"
lccn = eansearch.findLccnForEan(isbn13)
print("ISBN-13 ", isbn13, " is LCCN ", lccn)
lccn = "2020691629"
ean = eansearch.findEanForLccn(lccn)
print("LCCN ", lccn, " is EAN ", ean)
ean = "5099750442227" # Thriller
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"])
eanList = eansearch.similarProductSearch('iPod with extra features')
for product in eanList:
print(product["ean"], " is ", product["name"])
eanList = eansearch.categorySearch(45, 'thriller')
for product in eanList:
print(product["ean"], " is ", product["name"])
eanList = eansearch.barcodePrefixSearch('4007249146')
for product in eanList:
print(product["ean"], " is ", product["name"])
country = eansearch.issuingCountryLookup("5099750442227")
print(ean + " was issued in " + (country if country is not None else "unknown"))
barcode = eansearch.barcodeImage("5099750442227", 300, 200)
if barcode is not None:
print("HTML: <img src=\"data:image/png;base64," + barcode + "\">")
#import base64
#print (base64.b64decode(barcode))
print(str(eansearch.creditsRemaining()) + " credits remaining")