Skip to content

Commit

Permalink
first try of isbn auto lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaaoBlues committed Jul 2, 2022
1 parent 1c535d5 commit 57c2ba5
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
1 change: 0 additions & 1 deletion client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import requests
from ast import literal_eval
from util import *

def send_text_scan(text):
Expand Down
2 changes: 1 addition & 1 deletion copypasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def upload():

isbn = r

store_to_history({"file_type" : "isbn", "content" : f"{isbn}", "date" :f"{time}"})
store_to_history({"file_type" : "isbn", "content" : f"{isbn}", "date" :f"{time}","isbn_lookup":identify_product(isbn)})

return jsonify({"upload_status" : "true"})

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pyautogui
pillow
waitress
webtest
beautifulsoup4
4 changes: 2 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ <h1>Last files/data sent :</h1>
//barcode type
}else if(obj.file_type == "isbn"){

search_icon = "<button type=\"button\" onclick=\"window.open('http://google.com?q="+obj.content+"','_blank')\" class=\"btn btn-primary me-2\"><i class=\"bi bi-search\"></i></button>";
search_icon = "<button type=\"button\" onclick=\"window.open('"+obj.isbn_lookup.url+"','_blank')\" class=\"btn btn-primary me-2\"><i class=\"bi bi-search\"></i></button>";

tab_element = "<tr><td><div class=\"fs-1 mb-1\"><i class=\"bi bi-upc-scan\"></i></div></td><td><div style=\"margin-top:15px;\">isbn:"+obj.content+"</div></td><td><div style=\"margin-top:15px;\">"+search_icon+copy_content_icon+delete_scan_icon+"</div></td></tr>";
tab_element = "<tr><td><div class=\"fs-1 mb-1\"><i class=\"bi bi-upc-scan\"></i></div></td><td><div style=\"margin-top:15px;\">isbn: "+obj.content+" | name: "+obj.isbn_lookup.name+"</div></td><td><div style=\"margin-top:15px;\">"+search_icon+copy_content_icon+delete_scan_icon+"</div></td></tr>";

//emails
}else if(obj.file_type == "email"){
Expand Down
38 changes: 32 additions & 6 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
from ast import literal_eval
from os import startfile
from requests import get
from json import loads
from bs4 import BeautifulSoup

#isbn = "3302740068027"
#isbn = "978209157545"
isbn = "3270220060949"

startfile("C:/")


print(literal_eval(get("https://api.github.com/repos/CopyPastaOfficial/CopyPasta/tags").text)[0]['name'])
def identify_product(isbn:str):



# edible product ?
r = get(f"http://world.openfoodfacts.org/api/v0/product/{isbn}")
r = loads(r.text)
if "product" in r.keys():
r = r["product"]

return {"name":r["product_name"]+ " - "+r["brands"] if "brands" in r.keys() else r["product_name"] ,"url":f"https://world.openfoodfacts.org/product/{isbn}"}


# book ?
r = get(f"https://www.isbnsearcher.com/books/{isbn}",headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36 Edg/103.0.1264.37"})

if r.status_code == 200:
r = BeautifulSoup(r.text,"html.parser")

return {"name":r.find("h1").get_text(),"url":f"https://www.isbnsearcher.com/books/{isbn}"}

else:
return {"name":isbn,"url":f"https://www.google.com/search?q={isbn}"}

#print(identify_product(isbn))
# amazon lookup
r = get("https://www.amazon.fr/s?k=9782091575452",headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36 Edg/103.0.1264.37"},allow_redirects=True)
30 changes: 29 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from getpass import getuser
from random import randint
from json import *
from bs4 import BeautifulSoup
from requests import get
from os import mkdir, path, remove
from xml.etree import ElementTree
Expand Down Expand Up @@ -327,4 +328,31 @@ def remove_copypasta_port_redirect():

def is_image(file_type:str):

return file_type in ["jpeg","jpg","png","ico","gif","apng","avif","gif","jfif","pjpeg","pjp","svg","webp"]
return file_type in ["jpeg","jpg","png","ico","gif","apng","avif","gif","jfif","pjpeg","pjp","svg","webp"]



def identify_product(isbn:str):



# edible product ?
r = get(f"http://world.openfoodfacts.org/api/v0/product/{isbn}")
r = loads(r.text)

if "product" in r.keys():
r = r["product"]

return {"name":r["product_name"]+ " - "+r["brands"] if "brands" in r.keys() else r["product_name"] ,"url":f"https://world.openfoodfacts.org/product/{isbn}"}


# book ?
r = get(f"https://www.isbnsearcher.com/books/{isbn}",headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36 Edg/103.0.1264.37"})

if r.status_code == 200:
r = BeautifulSoup(r.text,"html.parser")

return {"name":r.find("h1").get_text(),"url":f"https://www.isbnsearcher.com/books/{isbn}"}

else:
return {"name":isbn,"url":f"https://www.google.com/search?q={isbn}"}

0 comments on commit 57c2ba5

Please sign in to comment.