---
# System prepended metadata

title: Nadaljevanje vaj

---

* > Preverjanje davčne in izpis v drugi podstran2.html
* > main.py
```python=
from flask import Flask, render_template, request, jsonify
from tinydb import Query, TinyDB
import requests
import pprint #lepši print v consolu
import random
import math

app = Flask('app')
db = TinyDB('baza.json')

#Imedict=

@app.route('/')
def index():
  return render_template("index.html")


@app.route('/podstran1')
def podstran1():
  return render_template("podstran1.html") #,dict=Imedict

@app.route("/dobi")
def dobi():
  lastnik = request.args['lastnik']
  ime=request.args["ime"]
  davcna = request.args["davcna"]
  url=f"https://api.vatcomply.com/vat?vat_number={davcna}"
  zahteva=requests.get(url).json()
  pprint.pprint(zahteva)
               
  if not zahteva.get('valid', False):
    return jsonify({"error": "Davčna številka ni pravilna"}), 400
  
  naslov = zahteva['address']
  ime1 = zahteva['name']
  drzava = zahteva['country_code']
  
  
  firmaTable= db.table('baza')

  obstaja = firmaTable.search(Query().davcna == davcna)

  if obstaja:
    firmaTable.update({"Ime": ime, "Naslov": naslov, "drzava": drzava}, Query().davcna == davcna)
    message = "Zapis posodobljen"
  else:
    firmaTable.insert({"Ime": ime, "Naslov": naslov, "drzava": drzava, "davcna": davcna})
    message = "Zapis vstavljen"
    
  return jsonify({"Ime": ime, "Naslov": naslov, "drzava": drzava, "message": message})

@app.route('/podstran2')
def podstran2():
    return render_template("podstran2.html")

@app.route('/seznamFirm')
def seznamFirm():
    return vseFirme()

def vseFirme():
    db = TinyDB('baza.json')
    firmaTable = db.table('baza')

    htmlTable = "<table>"
    htmlTable += "<tr><th>Ime</th><th>Naslov</th><th>Država</th></tr>"
    for firma in firmaTable.all():
        htmlTable += f"<tr><td>{firma['Ime']}</td><td>{firma['Naslov']}</td><td>{firma['drzava']}</td></tr>"
    htmlTable += "</table>"

    return htmlTable

app.run(host='0.0.0.0', port=8080, debug=True)
```
* > index.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>INDEX</h1>
  <a href="/podstran1">podstran 1</a><br>
  <a href="/podstran2">podstran 2</a>
</body>
</html>
```
* > podstran1.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
  <title>Document</title>
</head>
<body>
  <a href="/">nazaj</a>
  <h1>PODSTRAN 1</h1>
  <!--Vnos-->
  <input type="text" id="lastnik" placeholder="Lastnik podjetja">
  <input type="text" id="ime" placeholder="Ime podjetja">
  <input type="VAT" id="davcna" placeholder="Davčna številka">
  <button onclick="dobi()">Dobi vse</button>
  <p id="izpis"></p>
  <script>
    function dobi() {
      let ime=document.getElementById("ime").value;
      let davcna=document.getElementById("davcna").value;
      let lastnik=document.getElementById("lastnik").value;
        $.ajax ({
          url: "/dobi",
          data: {
            "lastnik": lastnik,
            "ime" : ime,
            "davcna" : davcna
          },
          success: function(result){
            console.log("dela");
              $('#izpis').text(`Ime: ${result.Ime}, Naslov: ${result.Naslov}, Država: ${result.drzava}, Sporočilo: ${result.message}`);
            },
          error: function(xhr) {
            let errorMessage = xhr.responseJSON ? xhr.responseJSON.error : "Prišlo je do napake";
            $('#izpis').text(errorMessage);
          }
      })
    }
  </script>
</body>
</html>
```
* > podstran2.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Seznam Firm</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
<body>
    <a href="/">nazaj</a>
    <h1>Seznam Firm</h1>
    <div id="firmaTable"></div>
    <script>
        $(document).ready(function(){
            $.ajax({
                url: "/seznamFirm",
                success: function(data) {
                    $('#firmaTable').html(data);
                },
                error: function() {
                    $('#firmaTable').html('<p>Failed to load data.</p>');
                }
            });
        });
    </script>
</body>
</html>
```
* > Preverjanje starosti za nakup vstopnic, shranjevanje v DB, vsa polja moraji biti obvezna
* > main.py
```python=
from flask import Flask, render_template, request, jsonify
from tinydb import Query, TinyDB
import requests
import pprint #lepši print v consolu
import random
import math

app = Flask('app')
db = TinyDB('baza.json')

koncerti= {
    "Tomorrowland": {
        "Location": "Belgija",
        "date": "19 - 28 Julij",
        "yearLimit": 18,
        "price": 50,
        "currency": "EUR"
    },
    "Sziget Festival 2024": {
        "Location": "Óbudai-sziget, Madžarska",
        "date": "7 - 12 Avgust",
        "yearLimit": 16,
        "price": 12,
        "currency": "EUR"
    },
    "Mysteryland 2024": {
        "Location": "Floriade, Nizozemska",
        "date": "12 - 14 Julij",
        "yearLimit": 18,
        "price": 120,
        "currency": "EUR"
    },
    "Exit Festival 2024": {
        "Location": "Petrovaradin Fortress, Srbija",
        "date": "10 - 14 Avgust",
        "yearLimit": 16,
        "price": 70,
        "currency": "EUR"
    },
    "Ultra Europe 2024": {
        "Location": "Split, Hrvaška",
        "date": "12 - 14 Julij",
        "yearLimit": 16,
        "price": 70,
        "currency": "EUR"
    },
    "Untold Festival 2024": {  
        "Location": "Cluj-Napoca, Romunija",
        "date": "8 - 11 Avgust",
        "yearLimit": 20,
        "price": 5,
        "currency": "EUR"
    },
    "Balaton Sound 2024": {
        "Location": "Zamardi, Madžarska",
        "date": "3 - 7 Julij",
        "yearLimit": 14,
        "price": 150,
        "currency": "EUR"  
    }
}

@app.route('/')
def index():
  return render_template("index.html")


@app.route('/podstran1')
def podstran1():
  return render_template("podstran1.html", dict=koncerti) 

@app.route("/dobi")
def dobi():
  ime=request.args["ime"]
  email=request.args["email"]
  starost=request.args["starost"]
  starost1 = int(starost)
  koncert=request.args["koncert"]
  stevilo=request.args["stevilo"]
  
  if not all([ime, email, starost, koncert, stevilo]):
    return jsonify({"error": "Manjkajo obvezni podatki!"}), 400

  inf = koncerti[koncert]
  limit = inf['yearLimit']
  limit1 = int(limit)
  cena = inf['price']
  cena1 = int(cena) * int(stevilo)
  if starost1 < limit1:
    izpis1 = f"Nisi dovolj star za nakup vstopnice. Za nakup vstopnice moraš biti star {limit}."
    return jsonify({"izpis1": izpis1}), 400
  else:
    tableVstopnic = db.table('baza')
    tableVstopnic.insert({"ime":ime, "email":email, "starost":starost, "koncert":koncert, "stevilo vstopnic":stevilo})
    izpis = f"Ime: {ime}, email: {email}, starost: {starost}, koncert: {koncert}, Število vstopnic: {stevilo}, Cena vstopnic: {cena1}EUR"
  return jsonify({'izpis':izpis})

@app.route('/podstran2')
def podstran2():
  return render_template("podstran2.html")

app.run(host='0.0.0.0', port=8080, debug=True)
```
* > index.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>INDEX</h1>
  <a href="/podstran1">podstran 1</a><br>
  <a href="/podstran2">podstran 2</a>
</body>
</html>
```
* > podstran1.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
 <title>Document</title>
</head>
<body>
 <a href="/">nazaj</a>
 <h1>PODSTRAN 2</h1>
 <input type="text" id="ime" placeholder="Ime">
  <input type="text" id="email" placeholder="email">
  <input type="text" id="starost" placeholder="Starost">
  <input type="text" id="stevilo" placeholder="Število vstopnic">
 <select id="koncert" placeholder="Koncert">
   {% for i in dict %}
   <option>{{ i }}</option>
   {% endfor %}
 </select>
 <button onclick="dobi()">Pretvori</button>
 <p id="izpis"></p>
 <p id="izpis1"></p>
 <script>
   function dobi(){
     let ime = document.getElementById('ime').value;
     let email = document.getElementById('email').value;
     let starost = document.getElementById('starost').value;
     let koncert = document.getElementById('koncert').value;
     let stevilo = document.getElementById('stevilo').value;
       
     if (!ime || !email || !starost || !koncert || !stevilo) {
       alert('Vsa polja so obvezna!');
       return;
      }
       
     $.ajax({
       url: '/dobi',
       data: {
         "ime": ime,
         "email": email,
         "starost": starost,
         "koncert": koncert,
         "stevilo" : stevilo
       },
       success: function (result) {
         console.log("dela");
         $('#error-msg').text('');
         $("#izpis").text(result.izpis);
       },
       error: function(result){
         $("#izpis1").text(result.responseJSON.izpis1)
       }
     })
   }
 </script>
</body>
</html
```
* > God of Highschool dobi quote in sliko ter izpis v bazo
* > main.py
```python=
from flask import Flask, render_template, request, jsonify
from tinydb import Query, TinyDB
import requests
import pprint #lepši print v consolu
import random
import math

app = Flask('app')
db = TinyDB('baza.json')

quotes = {
  "Jin Mori": {
    "image": "https://steamuserimages-a.akamaihd.net/ugc/1622941809420013843/68723104529B819DF69BE28758D99992BF34D61C/?imw=512&&ima=fit&impolicy=Letterbox&imcolor=%23000000&letterbox=false",
    "quotes": [
      "I just wanted to protect my friends.",
      "Even if the world is against me, I will fight.",
      "Power without justice is just violence.",
      "I’ve lost so much, but I must keep going.",
      "The weight of my past mistakes is crushing.",
      "I fight for those who can’t.",
      "Sometimes, I wish I could go back and change everything.",
      "Every battle leaves me emptier.",
      "Strength without purpose is meaningless.",
      "Why must I always lose those I care about?"
    ]
  },
  "Han Daewi": {
    "image": "https://i.pinimg.com/originals/22/da/9b/22da9bdad677ec5b13894240b15d7a67.jpg",
    "quotes": [
      "I have to become stronger, to protect those I care about.",
      "I don't care about winning or losing, as long as I can save my friend.",
      "The pain of losing someone precious never fades.",
      "Every punch I throw is filled with regret.",
      "I carry the burden of my friend's dreams.",
      "I can’t forgive myself for being weak.",
      "Every day is a struggle against despair.",
      "My strength comes from my suffering.",
      "I’m haunted by the faces of those I couldn’t save.",
      "The fight is endless, and so is the pain."
    ]
  },
  "Yoo Mira": {
    "image": "https://comicvine.gamespot.com/a/uploads/original/11143/111432035/7584046-4539665359-340.png",
    "quotes": [
      "I want to become stronger so I don't lose anyone else.",
      "Sacrifices are necessary to achieve my goals, even if it means sacrificing myself.",
      "I carry the weight of my family's legacy on my shoulders.",
      "Every day is a battle against my fears.",
      "I can’t escape the shadows of my past.",
      "Every swing of my sword is filled with sorrow.",
      "I fight to honor those who have fallen.",
      "My heart is a battlefield of lost hopes.",
      "Strength is my only refuge from despair.",
      "I wish I could lay down my sword and rest."
    ]
  },
  "Park Ilpyo": {
    "image": "https://i.pinimg.com/474x/38/ee/40/38ee40b6706a57a2b002406b233c3fb6.jpg",
    "quotes": [
      "I will never forgive those who hurt my friends.",
      "I fight not for revenge, but for justice.",
      "Even if I lose everything, I will keep fighting.",
      "My path is filled with thorns of regret.",
      "The pain of betrayal is a wound that never heals.",
      "Every victory feels hollow.",
      "I wear my scars as a reminder of my failures.",
      "I fight to protect, but who will protect me?",
      "Every battle takes a piece of my soul.",
      "I am a warrior bound by sorrow."
    ]
  },
  "Jegal Taek": {
    "image": "https://i.pinimg.com/originals/37/f3/5c/37f35cb8e6ee5e567bed84be58d03121.jpg",
    "quotes": [
      "Strength is the only thing that matters in this world.",
      "I have been betrayed and abandoned, and I will make them all pay.",
      "The world is cruel, and only the strong survive.",
      "I trust no one, for trust leads to pain.",
      "My heart is a fortress of bitterness.",
      "Every ally is a potential enemy.",
      "The loneliness of power is overwhelming.",
      "Revenge is my only solace.",
      "I am haunted by the ghosts of my past.",
      "Even in victory, I find no peace."
    ]
  },
  "Park Mujin": {
    "image": "https://i.pinimg.com/originals/4f/25/b6/4f25b6852d4dbfd0374d16e6377c640a.jpg",
    "quotes": [
      "I have seen the depths of human cruelty and despair.",
      "The burden of leadership is heavy and lonely.",
      "To create a better future, sacrifices must be made.",
      "Every decision weighs heavily on my soul.",
      "I must bear the pain of others' suffering.",
      "The path to justice is paved with sorrow.",
      "I carry the hopes and dreams of many.",
      "Leadership is a mantle of endless grief.",
      "I fight for a future I may never see.",
      "Every choice is a step deeper into the abyss."
    ]
  },
  "Q (Gang Manseok)": {
    "image": "https://i.pinimg.com/originals/29/5b/26/295b26c1ccd1d069e4566f1c9c9e8740.jpg",
    "quotes": [
      "I have lost my way, but I will find it again.",
      "Even if I am broken, I will keep fighting.",
      "The scars of the past will never heal.",
      "My strength is forged from my pain.",
      "I am a shadow of my former self.",
      "Every battle is a reminder of my failures.",
      "I fight to reclaim my lost honor.",
      "My journey is one of redemption and regret.",
      "I bear the weight of my past mistakes.",
      "In the darkness, I search for a glimmer of hope."
    ]
  },
  "R (Baek Seungchul)": {
    "image": "https://i.pinimg.com/474x/10/e5/7e/10e57e180895db1ceb487e079f7a8af5.jpg",
    "quotes": [
      "I have lost everything I once held dear.",
      "Revenge consumes me, but it is all I have left.",
      "In this world, only pain and suffering are eternal.",
      "I am a prisoner of my own rage.",
      "Every moment is a battle against despair.",
      "I am haunted by the memories of my loved ones.",
      "My heart is a vessel of sorrow.",
      "I seek vengeance, but it brings no peace.",
      "The past is a wound that never heals.",
      "I walk a path of darkness and regret."
    ]
  },
  "Na Bongchim": {
    "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSq8lWt9iemurcALbZYi4g1Go6Z6fXQJNKMfQ&s",
    "quotes": [
      "I have lived a long life filled with regret.",
      "The burden of my mistakes weighs heavily on my heart.",
      "Redemption is a long and painful journey.",
      "Every day is a struggle to atone for my sins.",
      "I carry the weight of my failures.",
      "My wisdom is born from sorrow.",
      "I fight to protect the future from my past.",
      "My heart aches with the memories of lost friends.",
      "Even in old age, the pain remains.",
      "I seek peace, but find only turmoil."
    ]
  },
  "Jin Taejin": {
    "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTFUxFIGHKDfBi-9Ha11k1XD6VrfgqVry9sJA&s",
    "quotes": [
      "I fight to protect, even if it means sacrificing myself.",
      "The world is a harsh place, and sometimes we must make difficult choices.",
      "The legacy of a warrior is built on sacrifice and honor.",
      "Every battle leaves scars, both seen and unseen.",
      "I have lost much, but I must keep moving forward.",
      "My strength comes from the pain of loss.",
      "I fight for those who cannot fight for themselves.",
      "The burden of leadership is a heavy one.",
      "Every decision I make carries the weight of lives.",
      "I seek to create a world where others can find peace."
    ]
  }
}


@app.route('/')
def index():
  return render_template("index.html")


@app.route('/podstran1')
def podstran1():
  return render_template("podstran1.html", dict=quotes) 

@app.route("/dobi")
def dobi():
  mori =request.args["jin"]
  jinMori = quotes[mori]
  img = jinMori['image']
  quote = random.choice(jinMori['quotes'])
  pprint.pprint(quote)
  izpis = f"{mori} - {quote}"
  db.insert({'character': mori, 'quote': quote, 'image': img})

  return jsonify({'izpis':izpis, 'slika':img})

@app.route('/podstran2')
def podstran2():
    saved_quotes = db.all()
    return render_template("podstran2.html", saved_quotes=saved_quotes)

app.run(host='0.0.0.0', port=8080, debug=True)

```
* > index.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>INDEX</h1>
  <a href="/podstran1">God of Highschool</a><br>
  <a href="/podstran2">Database print</a>
</body>
</html>
```
* > podstran1.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
  <title>Document</title>
</head>
<body>
  <a href="/">nazaj</a>
  <h1>God Of Highschool Quotes</h1>
  <select id="jin" placeholder="Ime">
    {% for i in dict %}
    <option>{{ i }}</option>
    {% endfor %}
  </select>
  <button onclick="dobi()">Get quote</button>
  <p id="izpis"></p>
  <div id="slika"></div> 
  <script>
    function dobi(){
      let jin = document.getElementById('jin').value;
      $.ajax({
        url: '/dobi',
        data: {
          "jin": jin
        },
        success: function (result) {
          console.log("dela");
          $("#izpis").text(result.izpis);
          $("#slika").html('<img src="' + result.slika + '" alt="Image" />');
        }
      })
    }
  </script>
</body>
</html>
```
* > podstran2.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Saved Quotes</title>
</head>
<body>
  <a href="/">Back</a>
  <h1>Saved Quotes</h1>
  {% for i in saved_quotes %}
    <div>
      <p>{{ i.character }} - {{ i.quote }}</p>
      <img src="{{ i.image }}" alt="Image">
    </div>
  {% endfor %}
</body>
</html>
```
* > Dobi random cat fact
* > main.py
```python=
from flask import Flask, render_template, request, jsonify
from tinydb import Query, TinyDB
import requests
import pprint #lepši print v consolu
import random
import math

app = Flask('app')
db = TinyDB('baza.json')

#Imedict=

@app.route('/')
def index():
  return render_template("index.html")


@app.route('/podstran1')
def podstran1():
  url="https://catfact.ninja/fact?max_length=140"
  zahteva=requests.get(url).json()
  values = zahteva['fact']
  pprint.pprint(zahteva)
  
  return render_template("podstran1.html", values=values)

app.run(host='0.0.0.0', port=8080, debug=True)
```
* > index.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>INDEX</h1>
  <a href="/podstran1">Dobi dejstva</a><br>
</body>
</html>
```
* > podstran1.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
  <title>Document</title>
</head>
<body>
  <a href="/">nazaj</a>
  <h1>PODSTRAN 1</h1>
  <p>Random Cat Facts</p>
  <p> {{ values }} </p>
</body>
</html>
```
* > Povprečna poraba goriva glede na kilometer in na avto
* > main.py
```python=
from flask import Flask, render_template, request, jsonify
from tinydb import Query, TinyDB
import requests
import pprint #lepši print v consolu
import random
import math

app = Flask('app')
db = TinyDB('baza.json')

cars = {
    "Audi A4": {"fuel": 50, "poraba": 0.08},
    "BMW 320": {"fuel": 60, "poraba": 0.09},
    "Mercedes C200": {"fuel": 55, "poraba": 0.085},
    "Volkswagen Golf": {"fuel": 45, "poraba": 0.075},
    "Toyota Corolla": {"fuel": 48, "poraba": 0.07},
    "Honda Civic": {"fuel": 52, "poraba": 0.073},
    "Ford Focus": {"fuel": 53, "poraba": 0.076},
    "Chevrolet Cruze": {"fuel": 47, "poraba": 0.08},
    "Nissan Altima": {"fuel": 49, "poraba": 0.082},
    "Hyundai Elantra": {"fuel": 51, "poraba": 0.074}
}

@app.route('/')
def index():
  return render_template("index.html")


@app.route('/podstran1')
def podstran1():
  return render_template("podstran1.html", dict=cars)

@app.route("/dobiPorabo")
def dobiPorabo():
  km=int(request.args["km"])
  avti=request.args["avti"]

  inf = cars[avti]
  poraba = inf['fuel']
  povpPoraba =  inf['poraba']
  
  povprecnaPoraba = round(km * povpPoraba)

  cena = povprecnaPoraba * 1.46
  
  izpis = f"Za {km}km bo {avti} s porabo {poraba}l uporabil {povprecnaPoraba} L goriva in za to bo plačal {cena} EUR."
  return jsonify({'izpis':izpis})

@app.route('/podstran2')
def podstran2():
  return render_template("podstran2.html")

app.run(host='0.0.0.0', port=8080, debug=True)
```
* > index.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>INDEX</h1>
  <a href="/podstran1">Cena goriva</a><br>
</body>
</html>
```
* > podstran1.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
  <title>Document</title>
</head>
<body>
  <a href="/">nazaj</a>
  <h1>Cena</h1>
  <input type="text" id="km" placeholder="Število kilometrov">
  <select id="avti" placeholder="avti">
    {% for i in dict %}
    <option>{{ i }}</option>
    {% endfor %}
  </select>
  <button onclick="dobiPorabo()">Dobi porabo</button>
  <p id="izpis"></p>
  <script>
    function dobiPorabo(){
      let km = document.getElementById('km').value;
      let avti = document.getElementById('avti').value;
      $.ajax({
        url: '/dobiPorabo',
        data: {
          "km": km,
          "avti": avti
        },
        success: function (result) {
          console.log("dela");
          $("#izpis").text(result.izpis);
        }
      })
    }
  </script>
</body>
</html>
```
* > Avtor in napisane knjige
* > main.py
```python=
from flask import Flask, render_template, request, jsonify
from tinydb import Query, TinyDB
import requests
import pprint #lepši print v consolu
import random
import math

app = Flask('app')
db = TinyDB('baza.json')

books = {
    "1984": {"author": "George Orwell", "pages": 328},
    "To Kill a Mockingbird": {"author": "Harper Lee", "pages": 281},
    "Pride and Prejudice": {"author": "Jane Austen", "pages": 279},
    "The Great Gatsby": {"author": "F. Scott Fitzgerald", "pages": 180},
    "Moby-Dick": {"author": "Herman Melville", "pages": 635},
    "War and Peace": {"author": "Leo Tolstoy", "pages": 1225},
    "The Catcher in the Rye": {"author": "J.D. Salinger", "pages": 214},
    "The Hobbit": {"author": "J.R.R. Tolkien", "pages": 310},
    "Fahrenheit 451": {"author": "Ray Bradbury", "pages": 194},
    "Jane Eyre": {"author": "Charlotte Brontë", "pages": 500}
}

@app.route('/')
def index():
  return render_template("index.html")


@app.route('/podstran1')
def podstran1():
  return render_template("podstran1.html", dict=books)

@app.route("/dobi")
def dobi():
  knjige=request.args["knjige"]
  inf = books[knjige]
  pprint.pprint(inf)
  avtor = inf['author']
  strani = inf['pages']

  izpis = f"Knjiga: {knjige}, ki jo je napisal {avtor} ima {strani} strani"
  
  return jsonify({'izpis':izpis})

@app.route('/podstran2')
def podstran2():
  return render_template("podstran2.html")

app.run(host='0.0.0.0', port=8080, debug=True)
```
* > index.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>INDEX</h1>
  <a href="/podstran1">Knjige</a><br>
</body>
</html>
```
* > podstran1.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
  <title>Document</title>
</head>
<body>
  <a href="/">nazaj</a>
  <h1>Dobi knjige</h1>
  <select id="knjige" placeholder="ime">
    {% for i in dict %}
    <option>{{ i }}</option>
    {% endfor %}
  </select>
  <button onclick="dobi()">Pretvori</button>
  <p id="izpis"></p>
  <script>
    function dobi(){
      let knjige = document.getElementById('knjige').value;
      $.ajax({
        url: '/dobi',
        data: {
          "knjige": knjige
        },
        success: function (result) {
          console.log("dela");
          $("#izpis").text(result.izpis);
        }
      })
    }
  </script>
</body>
</html>
```
* > Dropdown z imeni mest in izpisom
* > main.py
```python=
from flask import Flask, render_template, request, jsonify
from tinydb import Query, TinyDB
import requests
import pprint #lepši print v consolu
import random
import math

app = Flask('app')
db = TinyDB('baza.json')

cities = {
    "New York": {"country": "USA", "population": 8419000},
    "Tokyo": {"country": "Japan", "population": 13929286},
    "London": {"country": "UK", "population": 8982000},
    "Paris": {"country": "France", "population": 2141000},
    "Berlin": {"country": "Germany", "population": 3769000},
    "Moscow": {"country": "Russia", "population": 12506468},
    "Beijing": {"country": "China", "population": 21540000},
    "Sydney": {"country": "Australia", "population": 5312000},
    "São Paulo": {"country": "Brazil", "population": 12300000},
    "Mumbai": {"country": "India", "population": 20185064}
}

@app.route('/')
def index():
  return render_template("index.html")


@app.route('/podstran1')
def podstran1():
  return render_template("podstran1.html",dict=cities)

@app.route("/dobi")
def dobi():
  mesta=request.args["mesta"]
  inf = cities[mesta]
  drzava = inf['country']
  pop = inf['population']
  
  url=f"https://api.openweathermap.org/data/2.5/weather?q={mesta}&appid=210e4dd31d93f214b4066e8c4947a2c8"
  zahteva=requests.get(url).json()
  pprint.pprint(zahteva)
  temp = zahteva['main']['temp']
  vreme = zahteva['weather'][0]['description'] 

  izpis = f"Ime mesta: {mesta}, Država: {drzava}, Populacija: {pop}, Trenutno vreme: {vreme}, Trenutna temperatura: {temp}."

  tableMest = db.table('baza')
  tableMest.insert({"mesta":mesta, "drzava":drzava, "Populacija":pop, "Temperatura":temp, "vreme":vreme})

  return jsonify({'izpis':izpis})

@app.route('/podstran2')
def podstran2():
    return render_template("podstran2.html")

@app.route('/seznamMest')
def seznamMest():
    return vsaMesta()

def vsaMesta():
    tableMest = db.table('baza')

    htmlTable = "<table>"
    htmlTable += "<tr><th>Ime mesta</th><th>Ime države</th><th>Populacija</th><th>Temperatura</th><th>Vreme</th></tr>"
    for mesta in tableMest.all():
        htmlTable += f"<tr><td>{mesta['mesta']}</td><td>{mesta['drzava']}</td><td>{mesta['Populacija']}</td><td>{mesta['Temperatura']}</td><td>{mesta['vreme']}</td></tr>"
    htmlTable += "</table>"

    return htmlTable

app.run(host='0.0.0.0', port=8080, debug=True)
```
* > index.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>INDEX</h1>
  <a href="/podstran1">Mesta</a><br>
</body>
</html>
```
* > podstran1.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
  <title>Document</title>
</head>
<body>
  <a href="/">nazaj</a>
  <h1>Mesta</h1>
  <select id="mesta" placeholder="Ime mesta">
    {% for i in dict %}
    <option>{{ i }}</option>
    {% endfor %}
  </select>
  <button onclick="dobi()">Dobi info</button>
  <p id="izpis"></p>
  <script>
    function dobi(){
      let  mesta = document.getElementById('mesta').value;
      $.ajax({
        url: '/dobi',
        data: {
          "mesta": mesta
        },
        success: function (result) {
          console.log("dela");
          $("#izpis").text(result.izpis);
        }
      })
    }
  </script>
</body>
</html>
```
* > podstran2.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
  <title>Ocene</title>
</head>
<body>
  <a href="/">nazaj</a><br>
  <h1>Mesta izpis</h1>
  <div id="tableMest"></div>
  <script>
    $(document).ready(function() {
        $.ajax({
            url: "/seznamMest",
            success: function(data) {
                $('#tableMest').html(data);
            }
        });
    });
  </script>
</body>
</html>
```
* > Ali je punca dosti stra za Vas? If stavki
* > main.py
```python=
from flask import Flask, render_template, request, jsonify
from tinydb import Query, TinyDB
import requests
import pprint #lepši print v consolu
import random
import math

app = Flask('app')
db = TinyDB('baza.json')

ljudje1 = {
    "Adam Johnson": {
        "age": 29,
        "info": "Software engineer from San Francisco who loves hiking and photography.",
        "title":"Photographer"
    },
    "Brian Smith": {
        "age": 34,
        "info": "Marketing manager from New York with a passion for cooking and travel.",
        "title":"Fisher"
    },
    "Charles Lee": {
        "age": 41,
        "info": "Graphic designer from Austin, enjoys painting and playing the guitar.",
        "title":"Musician"
    },
    "Daniel Brown": {
        "age": 23,
        "info": "Recent college graduate working in finance in Chicago, avid basketball fan.",
        "title":"Cool"
    },
    "Edward Wilson": {
        "age": 37,
        "info": "Teacher from Denver who loves reading and volunteering at animal shelters.",
        "title":"Santa"
    },
    "Frank Harris": {
        "age": 28,
        "info": "Entrepreneur from Miami, enjoys surfing and startups.",
        "title": "Pedo"
    },
    "George Miller": {
        "age": 31,
        "info": "Architect from Seattle who loves urban sketching and gardening.",
        "title":"SweetHeart"
    },
    "Henry Clark": {
        "age": 45,
        "info": "Doctor from Boston, passionate about medical research and running marathons.",
        "title": "Pedo"
    },
    "Isaac Lewis": {
        "age": 15,
        "info": "High school student from Washington D.C., enjoys playing soccer and video games.",
        "title":"gamer"
    },
    "Jack Robinson": {
        "age": 39,
        "info": "Lawyer from Los Angeles, enjoys playing tennis and attending concerts.",
        "title": "Pedo"
    },
    "Kevin Walker": {
        "age": 33,
        "info": "Social worker from Houston, loves knitting and organizing community events.",
        "title":"Comunicative"
    },
    "Liam Martinez": {
        "age": 26,
        "info": "Software developer from San Diego, enjoys video games and mountain biking.",
        "title":"Lil Gang"
    },
    "Michael Thompson": {
        "age": 12,
        "info": "Middle school student from Phoenix, loves playing basketball and reading comics.",
        "title":"Monkey"
    },
    "Nathan Scott": {
        "age": 18,
        "info": "College freshman from Atlanta, enjoys coding and playing the guitar.",
        "title":"Gay"
    },
    "Oliver Adams": {
        "age": 22,
        "info": "Intern from Dallas, passionate about photography and music production.",
        "title":"GG"
    }
}



@app.route('/')
def index():
  return render_template("index.html")


@app.route('/podstran1')
def podstran1():
  return render_template("podstran1.html", dict=ljudje1) 

@app.route("/dobi")
def dobi():
  ime=request.args["ime"]
  st=int(request.args["st"])
  lj=request.args["lj"]
  
  inf = ljudje1[lj]
  pprint.pprint(inf)

  starost = inf['age']
  pprint.pprint(starost)
  dovoljena = round(starost / 2 + 7)
  pprint.pprint(dovoljena)
  tit = inf['title']
  pprint.pprint(tit)
  if tit == 'Pedo' and st < 16:
    izpis2 = f"Punca je za vas premlada, saj je stara {st} ampak vem da Vas to ne zanima saj ste PEDOFIL!!. Uživajte :)"
    return jsonify({'izpis':izpis2})
  if st < dovoljena:
    izpis = f"Ta punca: {ime} je za Vas premlada in ne bi bilo moralno vredu. Punca je stara {st}. Za Vas bi bilo primerno, da je stara {dovoljena}."
    return jsonify({'izpis':izpis})
  else:
    izpis1 = f"Ta punca: {ime} je primerne starosti in si z njo lahko v razmerju, saj si ti sam star {starost} ona pa {st}."
    return jsonify({'izpis':izpis1})
app.run(host='0.0.0.0', port=8080, debug=True)
```
* > index.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>INDEX</h1>
  <a href="/podstran1">Dovoljna starost?</a><br>
</body>
</html>
```
* > podstran1.html
```html=
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
  <title>Document</title>
</head>
<body>
  <a href="/">nazaj</a>
  <h1>Dovoljna starost??</h1>
  <input type="text" id="ime" placeholder="Ime dekleta">
  <input type="text" id="st" placeholder="Starost dekleta">
  <select id="lj" placeholder="ime">
    {% for i in dict %}
    <option>{{ i }}</option>
    {% endfor %}
  </select>
  <button onclick="dobi()">Pretvori</button>
  <p id="izpis"></p>
  <script>
    function dobi(){
      let ime = document.getElementById('ime').value;
      let st = document.getElementById('st').value;
      let lj = document.getElementById('lj').value;
      $.ajax({
        url: '/dobi',
        data: {
          "ime": ime,
          "st": st,
          "lj":lj
        },
        success: function (result) {
          console.log("dela");
          $("#izpis").text(result.izpis);
          $("#izpis").text(result.izpis1);
          $("#izpis").text(result.izpis2);
        }
      })
    }
  </script>
</body>
</html>
```