Sunday, November 12, 2023

This Blog will be Written in a Language Other Than Indonesian

 


There will be a change in the language used on this blog, from Indonesian to a language other than Indonesian. In this blog, I will write about various things.

I have successfully compressed the size of a .jpeg photo file using the following software:

https://saerasoft.com/caesium/

And in one article, I will try to achieve a target of 800 words or more. What I have learned in the past two days is about the applications Snackvideo and Bigo Live. The applications SnackVideo and Bigo seem to be more lenient than TikTok in terms of regulations. As a result, there are not many violations in both of these applications. Some users who perform live streaming on Bigo have moved their live streaming activities to the Line application. Perhaps this is because the rules on the Line application are more lenient than on Bigo. This is a rule related to the issue of nudity. In the Bigo app, in some live rooms, there are live room administrators who will remove viewers who only watch without giving any gifts to the host of the live room.

Today I have successfully changed the address of my blog to .web.id. I have also successfully connected it to AdSense. I am always learning how to make the links from my blog to be on various websites. In the afternoon, I studied about writing programming code using the Python programming language. The Python programming code was run in the Docker application. I have also successfully set up Google Analytics on this blog. I have already submitted this blog to Bing Webmaster and Yandex Webmaster, so this blog is also indexed in both of those search engines.


Building Docker Image

Here is the command to build a Docker image. Type the following command in the terminal of the host computer that has Docker :

sudo docker image build -t python-flask2 /home/steven/proyekPython/latihan1

Here is the command to find out who the user is in the specified Docker image:

sudo docker run --entrypoint "" python-mariadb1  whoami

The following command will remove a Docker image that has already been built :

sudo docker image rm <nama-repository>

The following command will list all containers that have been created :

sudo docker ps -a

Instructions for deleting a container :

sudo docker container rm (ID Container)

Example :

sudo docker container rm 9c9b1210e0c0


Instructions for running a Docker image on a Lokinet network :

sudo docker run -p 0.0.0.0:8543:8543 python-flask1


command to stop a running container :

sudo docker container stop (ID Container)

Example :

sudo docker container stop b4d3e8d5fe4a


Instructions to run a docker image on multiple ports simultaneously:

sudo docker run -p 0.0.0.0:3306:3306 -p 0.0.0.0:8543:8543 -t python-mariadb1  

Here is the source code for a web project using the Python programming language in Docker, which also includes the help of the Jinja2 library, Blueprint :

At the beginning, I will write the programming code for the Docker file, this programming code can also give commands to Docker to create a templates folder.




 FROM python  
 USER 0  
 WORKDIR /home  
 # RUN cd /home  
 RUN mkdir ./templates  
 EXPOSE 3306 8543  
 RUN pip install flask  
 RUN pip install Jinja2  
 RUN pip install mariadb  
 COPY file4.py ./  
 COPY file1.html ./templates  
 CMD ["python3", "./file4.py"]  

Here is the source code for the HTML template that becomes the user interface of our program :


 <!DOCTYPE html>  
 <html lang="en">   
   <head>  
     <meta charset="utf-8">  
     <title>{{title}}</title>  
   </head>  
   <body>  
     <h1>Selamat Datang Di {{kota}}</h1>  
   </body>  
 </html>  

Here is the Python source code for running a program that can display text on a web page. With the help of Jinja templates and routing from blueprints.


 from jinja2 import Environment, FileSystemLoader  
 from flask import Flask, render_template  
 aplikasi = Flask(__name__)  
 @aplikasi.route('/')  
 def halamanPertama():  
   return render_template("file1.html",title="New Found Land",kota="Land")  
 if __name__ == '__main__':  
   aplikasi.run(host='0.0.0.0',port='8543',debug='True')  

Latihan 2

The following source code is the Docker file for Exercise 2 :


 FROM python  
 USER 0  
 WORKDIR /home  
 RUN mkdir ./latihan2  
 RUN mkdir ./latihan2/templates  
 EXPOSE 3306 8543  
 RUN pip install flask  
 RUN pip install Jinja2  
 RUN pip install mariadb  
 COPY file1.py ./latihan2  
 COPY file1.html ./latihan2/templates  
 CMD ["python3", "./latihan2/file1.py"]  

The HTML file for the following application interface:


 <!DOCTYPE html>  
 <html>  
   <head>  
   </head>  
   <body>  
     <p>Kode Data : {{kodedata}}</p>  
     <p>Tanggal Pendataan : {{tanggalpendataan}}</p>  
     <p>Bagian/Sub Bagian : {{bagiansubbagian}}</p>  
     <p>Kode Barang : {{kodebarang}}</p>  
     <p>Merek Printer : {{merekprinter}}</p>  
   </body>  
 </html>  

Here is the Python source code for creating the core application of the program we made


 import mariadb  
 import sys  
 import json  
 from jinja2 import Environment, FileSystemLoader  
 from flask import Flask, render_template  
 aplikasi = Flask(__name__)  
 try:  
   koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.9",port=3306,database="saham")  
 except mariadb.Error as e:  
   print(f"Gagal Terkoneksi Ke : {e}")  
   sys.exit(1)  
 kursor = koneksi.cursor()  
 kursor.execute("SELECT kodedata,tanggalpendataan,bagiansubbagian,kodebarang,merekprinter FROM daftartintaprinter")  
 hasil = kursor.fetchall()  
 for data in hasil:  
   kodedata = data[0]  
   tanggalpendataan = data[1].strftime("%Y-%m-%d")  
   bagiansubbagian = data[2]  
   kodebarang = data[3]  
   merekprinter = data[4]  
 f = lambda s: f"dict({','.join(f'{k}={k}' for k in s.split(','))})"  
 kamusHasil = eval(f('kodedata,tanggalpendataan,bagiansubbagian,kodebarang,merekprinter'))  
 @aplikasi.route('/')  
 def halamanUtama():  
   return render_template("file1.html", **kamusHasil)  
 if __name__ == '__main__':  
   aplikasi.run(host='0.0.0.0', port=8543, debug=True)  


The following is a link to a lesson on how data transfer can happen in Flask and Jinja :

https://pythonbasics.org/flask-template-data/

Latihan 5

The following source code is the Docker file for Exercise 5 :

 FROM python  
 USER 0  
 WORKDIR /home  
 RUN mkdir ./latihan5  
 RUN mkdir ./latihan5/templates  
 EXPOSE 3306 8543  
 RUN pip install flask  
 RUN pip install Jinja2  
 RUN pip install mariadb  
 COPY file1.py ./latihan5  
 COPY murid1.html ./latihan5/templates  
 COPY hasil1.html ./latihan5/templates  
 CMD ["python3", "./latihan5/file1.py"]  

Here, we write the code to create a simple form, which later can be used for data transfer experiments using Flask and Jinja.


murid1.html

 <!DOCTYPE html>  
 <html>  
   <head>  
   </head>  
   <body>  
     <form action = "http://1.1.3.2:8543/hasil" method = "POST">  
       <p>Nama : <input type="text" name="Nama"/></p>  
       <p><input type = "submit" value = "submit"></p>  
     </form>  
   </body>  
 </html>  

The following is the source code to receive data input from the murid1.html page and then display the input results to the hasil1.html page.


file1.py

 from flask import Flask, render_template, request  
 aplikasi = Flask(__name__)  
 @aplikasi.route('/')  
 def murid():  
   return render_template('murid1.html')  
 @aplikasi.route('/hasil',methods = ['POST','GET'])  
 def hasil():  
   if request.method == 'POST':  
     hasil = request.form  
     return render_template("hasil1.html",hasil = hasil)  
 if __name__ == '__main__':  
   aplikasi.run(host='0.0.0.0', port=8543, debug=True)  

The following is the source code to display the results of the data entry activity performed in the form on the murid1.html page.


hasil1.html

 <!DOCTYPE html>  
 <html>  
   <head>  
   </head>  
   <body>  
     <table border=1>  
       {% for key, value in hasil.items() %}  
       <tr>  
         <th>{{ key }}</th>  
         <td>{{ value }}</td>  
       </tr>  
       {% endfor %}  
     </table>  
   </body>  
 </html>  

In the following source code, we have successfully displayed the results of the input data that was performed in the HTML form in JSON format. We will use the JSON data transfer format because we will be using a RESTful API.

Latihan 6

Dockerfile

 FROM python  
 USER 0  
 WORKDIR /home  
 RUN mkdir ./latihan6  
 RUN mkdir ./latihan6/templates  
 EXPOSE 3306 8543  
 RUN pip install flask  
 RUN pip install Jinja2  
 RUN pip install mariadb  
 COPY file1.py ./latihan6  
 COPY form1.html ./latihan6/templates  
 CMD ["python3", "./latihan6/file1.py"]  

file1.py

 from flask import Flask, render_template, request, jsonify, json  
 aplikasi = Flask(__name__)  
 @aplikasi.route('/')  
 def formulirIsiData():  
   return render_template('form1.html')  
 @aplikasi.route('/tampilData',methods = ['POST'])  
 def tampilkanData():  
   if request.method == 'POST':  
     # tampilkanData = request.form  
     # nama = request.form['nama']  
     # return print (tampilkanData)  
     # di bawah ini adalah kode yang berhasil dijalankan  
     # mencetak langsung ke json yang bisa di baca oleh browser  
     # return jsonify(tampilkanData.to_dict())  
     return jsonify(nama=request.form['nama'])  
 if __name__ == '__main__':  
   aplikasi.run(host='0.0.0.0',port=8543, debug=True)  

file1.html

 <!DOCTYPE html>  
 <html>  
   <head>  
   </head>  
   <body>  
     <form action="http://1.1.3.3:8543/tampilData" method="POST">  
       <p>Nama  : <input type="text" name="nama"/></p>  
       <p>Alamat : <input type="text" name="alamat"/></p>  
       <p><input type="submit" value="submit"></p>  
     </form>  
   </body>  
 </html>  


Latihan 9

In this exercise, we successfully input data using Flask. Then, we take each data that was filled in the textbox and display it to the jinja2 template. All processes are done by clicking a button.


file1.py

 from jinja2 import Template  
 from flask import Flask,render_template,request,json,jsonify  
 aplikasi = Flask(__name__)  
 @aplikasi.route('/')  
 def formUtama():  
   return render_template("halaman1.html")  
 @aplikasi.route('/tampilData', methods = ['POST'])  
 def tampilkanData():  
     if request.method == 'POST':  
       text1 = request.form.get('text1')  
       text2 = request.form.get('text2')  
       return render_template("halaman2.html", tampilText1=text1, tampilText2=text2)  
 # source code nya ini sudah bagus untuk menerima inputan dari form  
 if __name__ == '__main__':  
   aplikasi.run(host='0.0.0.0',port=8543,debug=True)  

halaman1.html

 <!DOCTYPE html>  
 <html>  
   <head>  
     <style>  
       input[type=text], select{  
         width: 100%;  
         padding: 12px 20px;  
         margin: 8px 0;  
         display: inline-block;  
         border: 1 px solid #ccc;  
         border-radius: 4px;  
         box-sizing: border-box;  
       }  
       input[type=submit]{  
         width: 100%;  
         background-color: #4CAF50;  
         color: white;  
         padding: 14px 20px;  
         margin: 8px 0;  
         border: none;  
         border-radius: 4px;  
         cursor: pointer;  
       }  
       input[type=submit]:hover {  
         background-color: #45a049  
       }  
       div {  
         border-radius: 5px;  
         background-color: #f2f2f2;  
         padding: 20px;  
       }  
     </style>  
   </head>  
   <body>  
     <h3>Formulir Data Printer</h3>  
     <div>  
       <form action="http://1.1.3.6:8543/tampilData" method="POST" id="formPrinter" name="formPrinter">  
         <label for="text1">Text 1</label>  
         <input type="text" id="text1" name="text1" placeholder="Isikan kata 1">  
         <input type="text" id="text2" name="text2" placeholder="Isikan kata 2">  
         <input type="submit" Value="submit">  
       </form>  
     </div>  
   </body>  
 </html>  

halaman2.html

 <!DOCTYPE html>  
 <html>  
   <head>  
   </head>  
   <body>  
     <p>{{ tampilText1 }}</p>  
     <p>{{ tampilText2 }}</p>  
     <!--- source code nya ini sudah bagus untuk menampilkan hasil inputan dari form  -->  
   </body>  
 </html>