Skip to content

Commit

Permalink
Merge pull request #14 from OmarMAshour/scanning-done
Browse files Browse the repository at this point in the history
scannig works
  • Loading branch information
OmarMAshour committed Oct 23, 2022
2 parents d2921b7 + d4cf906 commit b3fea9a
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 34 deletions.
Binary file not shown.
Binary file modified coop_challenge/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified coop_challenge/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified coop_challenge/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions coop_challenge/generator/label_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def generate_html(product):


def create_label():
print(html_link)
print(html_link)
print(html_link)
print(html_link)
print(html_link)
print(html_link)
print(html_link)
print(html_link)
print(html_link)
print(html_link)
print(html_link)
pdfkit.from_file(html_link, label_output_file_path, css=css_link, options={"enable-local-file-access": ""})

return label_output_file_path
Expand Down
4 changes: 2 additions & 2 deletions coop_challenge/generator/label_template/label_template.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="/home/andrei/Desktop/BaselHack2022_Team10/coop_challenge/generator/label_template/style.css">
<link rel="stylesheet" href="/home/omar/Documents/BaselHack/BaselHack2022/coop_challenge/generator/label_template/style.css">
<meta charset="UTF-8">
<title>Label</title>
</head>
Expand Down Expand Up @@ -36,7 +36,7 @@
</tr>
<tr>
<td colspan ="2"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/Coop.svg/2000px-Coop.svg.png" width="100"></td>
<td style=font-size:20px><b>57.5 CHF</b></td>
<td style=font-size:20px><b>57 CHF</b></td>
</tr>
</table>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.1.2 on 2022-10-23 09:05

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('coop_challenge', '0004_alter_scannedwine_alcohol_and_more'),
]

operations = [
migrations.RemoveField(
model_name='scannedwine',
name='label_file',
),
migrations.RemoveField(
model_name='scannedwine',
name='pdf_file',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.1.2 on 2022-10-23 09:37

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('coop_challenge', '0005_remove_scannedwine_label_file_and_more'),
]

operations = [
migrations.RemoveField(
model_name='scannedwine',
name='goesWithText_en',
),
]
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions coop_challenge/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ScannedWine(models.Model):
maturity = models.TextField(blank = True)
goesWithText = models.TextField(blank = True)
goesWithText_de = models.TextField(blank = True)
goesWithText_en = models.TextField(blank = True)
# goesWithText_en = models.TextField(blank = True)
goesWithText_fr = models.TextField(blank = True)
goesWithText_it = models.TextField(blank = True)
servingTemperature = models.TextField(blank = True)
Expand All @@ -21,7 +21,7 @@ class ScannedWine(models.Model):
wineOrigin = models.TextField(blank = True)
yearOfVintage = models.TextField(blank = True)
json = models.TextField(blank = True)
pdf_file = models.FileField(upload_to='media/pdfs', blank = True)
label_file = models.FileField(upload_to='media/label', blank=True)
# pdf_file = models.FileField(upload_to='media/pdfs', blank = True)
# label_file = models.FileField(upload_to='media/label', blank=True)
def __str__(self) -> str:
return self.name
Binary file modified coop_challenge/output/info.pdf
Binary file not shown.
Binary file modified coop_challenge/output/label.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions coop_challenge/static/coop_challenge/js/html5-qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10015,15 +10015,15 @@ var __Html5QrcodeLibrary__;
}, t.codeScannerTitle = function() {
return "Code Scanner"
}, t.cameraPermissionTitle = function() {
return "Open camera to scan"
return "Kamera aktivieren zum Scannen"
}, t.cameraPermissionRequesting = function() {
return "Requesting camera permissions..."
}, t.noCameraFound = function() {
return "No camera found"
}, t.scanButtonStopScanningText = function() {
return "Stop Scanning"
return "Scannen beenden"
}, t.scanButtonStartScanningText = function() {
return "Open camera to scan"
return "Kamera aktivieren zum Scannen"
}, t.scanButtonScanningStarting = function() {
return "Launching Camera..."
}, t.textIfCameraScanSelected = function() {
Expand Down
2 changes: 1 addition & 1 deletion coop_challenge/templates/coop_challenge/scanner_1.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'coop_challenge/base.html' %}

{% block body %}
<script src="js/html5-qrcode.js"></script>
<!-- <script src="js/html5-qrcode.js"></script> -->
<div class="d-flex justify-content-center">
<div style="width: 60%" id="reader"></div>
</div>
Expand Down
1 change: 0 additions & 1 deletion coop_challenge/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

urlpatterns = [
path('', views.viewIndex, name='index'),
path('printlabell/', views.printLabell, name='printlabell'),
path('printlabel/<int:article>/', views.printLabel, name='printlabel'),
path('printpdf/<int:article>/', views.printPdf, name='printpdf'),
]
55 changes: 31 additions & 24 deletions coop_challenge/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from unicodedata import name
from coop_challenge.fetcher import Fetcher
from coop_challenge.generator.label_generator import tryLabel
from coop_challenge.generator.info_generator import tryInfo
from django.shortcuts import render
from requests import request
from django.http import FileResponse


from .models import ScannedWine
import json
# Create your views here.
def viewIndex(request):
# tryPDF()
Expand All @@ -14,41 +15,47 @@ def viewIndex(request):
return render(request, 'coop_challenge/scanner_1.html', {})


if __name__ == "__main__":
id = "3760126362587" # barcode
# if __name__ == "__main__":
# id = "3760126362587" # barcode

fetcher = Fetcher()
article_id = fetcher.find_article_id_by_barcode(id)
# fetcher = Fetcher()
# article_id = fetcher.find_article_id_by_barcode(id)

# article_id = "1007906010"
# # article_id = "1007906010"

json = fetcher.find_by_article_ids([article_id])
# json = fetcher.find_by_article_ids([article_id])

label_path = tryLabel(json[0].copy())
info_path = tryInfo(json[0].copy())
# label_path = tryLabel(json[0].copy())
# info_path = tryInfo(json[0].copy())

# return render(request, 'coop_challenge/base.html', {})
def printLabel(request, article):
# tryPDF()
# return FileResponse(open(tryPDF(), 'rb'), content_type='application/pdf')
print(article)
print(article)
print(article)
print(article)
print(article)
print(article)
print(article)
print(article)
return render(request, 'coop_challenge/scanner_1.html', {})
json_obj = fetchandsave(article)
label_path = tryLabel(json.loads(json_obj))
return FileResponse(open(label_path, 'rb'), content_type='application/pdf')

def printLabell(request):
# tryPDF()
# return FileResponse(open(tryPDF(), 'rb'), content_type='application/pdf')

return render(request, 'coop_challenge/scanner_1.html', {})

def printPdf(request, article):
# tryPDF()
# return FileResponse(open(tryPDF(), 'rb'), content_type='application/pdf')

return render(request, 'coop_challenge/scanner_1.html', {})
json_obj = fetchandsave(article)
label_path = tryInfo(json.loads(json_obj))
return FileResponse(open(label_path, 'rb'), content_type='application/pdf')

def fetchandsave(article):
fetcher = Fetcher()
if len(str(article)) == 13:
article = fetcher.find_article_id_by_barcode(id)
old_scanned = ScannedWine.objects.filter(article_id= article)
if len(old_scanned) == 1:
# return json.loads(old_scanned[0].json)
return old_scanned[0].json
json_str = fetcher.find_by_article_ids([article])
json_str = json_str[0]
new_scan = ScannedWine(name=json_str['name'], article_id = json_str['code'], alcohol=json_str['alcohol'], sellPrice=json_str['allPrices'][0]['sellPrice'], averageRating=json_str['averageRating'], maturity=str(json_str['enjoyFrom'])+' - ' +str(json_str['enjoyUntil']), goesWithText=json_str['goesWithText'], goesWithText_de=json_str['goesWithText_de'], goesWithText_fr=json_str['goesWithText_fr'], goesWithText_it=json_str['goesWithText_it'], servingTemperature=json_str['servingTemperature'], wineCharacter=json_str['wineCharacter'], wineMaker=json_str['wineMaker'], wineOrigin=json_str['wineOrigin'], yearOfVintage=json_str['yearOfVintage'], json=json.dumps(json_str))
new_scan.save()
return json_str
Binary file modified db.sqlite3
Binary file not shown.
Binary file added wkhtmltox_0.12.6-1.focal_amd64.deb
Binary file not shown.

0 comments on commit b3fea9a

Please sign in to comment.