# data[].attributes.body
https://feedu-my.sharepoint.com/:x:/g/personal/lannt78_fe_edu_vn/Efov8zKXi6dMlOtvpL8hdnAByuX25oxsJdiyi_PvRCoVnA?CID=e77cf81a-0a51-8526-29b6-8bfbd034f876

# data[].attributes.body
https://zalo.me/g/eqskql107

# data[].attributes.attachment_link.title
Zalo - Nhắn Gửi Yêu Thương (Nhắn tin thoại - Trò chuyện nhóm ...)

# data[].attributes.attachment_link.readable_text
# # B��i 1
# while True:
#     try:
#         n = int(input("n = "))
#         if 1 <= n <= 10:
#             tong = 0
#             for i in range(1, n+1):
#                 tong += i
#             print(tong)
#             break
#         else:
#             print("1 <= n <= 10")
#             continue
#     except ValueError:
#         print("n l�� s��� nguy��n")
#         continue


# B��i 2
import tkinter
window = tkinter.Tk()
window.title('LUCKY NUMBER')
window.config(bg='cyan')
font = ('Arial', 16, 'bold')
#
input_label = tkinter.Label(window, text='Nh���p s��� c���a b���n (1-9): ', font=font)
input_label.config(bg='blue', fg='white')
input_label.grid(row=0, column=0)
#
input_entry = tkinter.Entry(window, font=font)
input_entry.config(fg='red')
input_entry.grid(row=0, column=1)
#
result_label = tkinter.Label(window, text='K���t qu���...', font=font)
result_label.config(bg='black', fg='yellow', width=30, wraplength=500)
result_label.grid(row=1, column=0, columnspan=2)
#
import random
from tkinter import messagebox
def get_lucky():
    try :
        lucky_number = random.randint(1, 9)
        your_number = int(input_entry.get())
        result_text = 'S��� may m���n l��: ' + str(lucky_number) + '\n'
        if your_number == lucky_number:
            result_text += 'Xin ch��c m���ng! B���n l�� ng�����i may m���n.'
        else:
            result_text += 'Ch��c b���n may m���n l���n sau...!'
        result_label['text'] = result_text
    except Exception as ex:
        messagebox.showerror('H��� th���ng', 'C�� l���i x���y ra: ' + str(ex))
result_button = tkinter.Button(window, text='Th��� v���n may', font=font)
result_button.config(bg='green', fg='white', command=get_lucky)
result_button.grid(row=2, column=0, columnspan=2)
#
window.mainloop()



















# data[].attributes.attachment_link.readable_text
* {
    font-family: 'Courier New', Courier, monospace;
    padding: 0 5px;
    text-align: center;
}
.container {
    width: 300px;
    height: auto;
    border: 1px solid red;
    padding: 5px;
}
.thumb img {
    width: 80%;
}
.product-name {
    font-weight: bold;
    color: #0447b3;
}
.description {
    font-style: italic;
    font-weight: 600;
}
.new-price {
    font-weight: bold;
    color: #00f521;
}
.old-price {
    font-weight: bold;
    color: darkred;
    text-decoration: line-through;
}
.discount {
    font-weight: bold;
    color: red;
}
.banner {
    background: url("images/banner.jpg");
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    width: 100%;
    min-height: 300px;
    align-content: center;
}
.banner p {
    color: white;
    background: black;
    font-size: 16pt;
    font-weight: bold;
}
.banner p.title {
    background: #0447b3;
}
.banner p.slogan {
    background: #00987e;
}
.banner img {
    width: 100px;
}
.btn-detail {
    background: #0447b3;
    color: white;
    padding: 10px;
    border: none;
    border-radius: 10px;
}
.btn-detail:hover {
    box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
}

# data[].attributes.attachment_link.readable_text
import requests, tkinter
from bs4 import BeautifulSoup
from PIL import ImageTk # pip install pillow
from tkinter import messagebox
from urllib.request import urlopen, Request
url = 'https://game24h.vn/'
headers = {'User-Agent':'Mozilla'}
response = requests.get(url, headers=headers)
print('response:', response)
html_data = BeautifulSoup(response.text, features='html.parser')
# �����c d��� li���u tr��n web
logo_link = html_data.find('div', {'class':'logo-home'})['style']
logo_link = logo_link.split('(')[1]
logo_link = logo_link.split(')')[0]
print('logo_link:', logo_link)
#
web_title = html_data.find('title').text
print('web_title:', web_title)
#
best_game_image = html_data.find('div', {'class':'gameHayNhatTitle'}).find('img')['src']
best_game_image = url + best_game_image
print('best_game_image:', best_game_image)
#
game_names = []
game_images = []
game_plays = []
game_links = [] # game_catagorys
game_intros = []
#
game_tags = html_data.find('div', {'class':'gameHayNhat'})
game_tags = game_tags.find_all('div', {'class':'gameItem'})
print('game_tags:', len(game_tags))
for tag in game_tags:
    #
    link = tag.find('div', {'class':'gameItemImg'}).find('a')['href']
    game_links.append(link)
    #
    game_thumb = tag.find('div', {'class':'gameItemImg'}).find('a').find('img')['src']
    game_images.append(game_thumb)
    #
    name = tag.find('div', {'class':'gameItemName-g'}).find('a').text
    game_names.append(name)
    #
    play = tag.find('div', {'class':'gameItemName-g'}).text
    play = play.split(':')[1]
    game_plays.append(play)
    #
    detail_tag = tag.find('div', {'class':'gameItemImg'}).find('a')['onmouseover']
    detail_tag = detail_tag.strip("Tip('")
    detail_tag = detail_tag.strip("')")
    detail_tag = detail_tag.split('M�� t���: ')[-1]
    intro = detail_tag.split('<')[0]
    game_intros.append(intro)
print('game_images:', game_images[0], len(game_images))
print('game_names:', game_names[0], len(game_names))
print('game_plays:', game_plays[0], len(game_plays))
print('game_intros:', game_intros[0], len(game_intros))
print('game_links:', game_links[0], len(game_links))
# Thi���t k��� giao di���n trong tkinter
window = tkinter.Tk()
window.title(web_title)
font = ('Arial', 14, 'bold', 'italic')
#
title_label = tkinter.Label(window, text=web_title, font=font)
title_label.config(bg='green', fg='yellow')
title_label.grid(row=0, column=1)
#
req = Request(logo_link, headers=headers)
logo_raw = urlopen(req).read()
logo_data = ImageTk.PhotoImage(data=logo_raw)
logo_label = tkinter.Label(window, image=logo_data)
logo_label.grid(row=1, column=1)
#
req = Request(best_game_image, headers=headers)
best_game_raw = urlopen(req).read()
best_game_data = ImageTk.PhotoImage(data=best_game_raw)
best_game_label = tkinter.Label(window, image=best_game_data)
best_game_label.grid(row=2, column=1)
#
game_index = 0
name_label = tkinter.Label(window, text=game_names[game_index], font=font)
name_label.config(bg='#0266b8', fg='white')
name_label.grid(row=3, column=1)
#
req = Request(game_images[game_index].replace(' ', '%20'), headers=headers)
game_image_raw = urlopen(req).read()
game_image_data = ImageTk.PhotoImage(data=game_image_raw)
game_image_label = tkinter.Label(window, image=game_image_data)
game_image_label.grid(row=4, column=1)
#
intro_label = tkinter.Label(window, text=game_intros[game_index], font=font)
intro_label.config(fg='blue', wraplength=500)
intro_label.grid(row=5, column=1)
#
import webbrowser
def open_game():
    title = 'H��� th���ng'
    content = 'B���n mu���n m��� game "' + game_names[game_index] + '" kh��ng?'
    result = messagebox.askyesno(title, content)
    if result == True:
        webbrowser.open(game_links[game_index])
play_button = tkinter.Button(window, text='Ch��i ngay!!!', font=font)
play_button.config(bg='red', fg='white', command=open_game)
play_button.grid(row=6, column=1)
#
window.mainloop()






# data[].attributes.attachment_link.title
1. L2_Module1 _ Tuần 01+02+03_Giới thiệu về Web Scraping

# data[].attributes.attachment_link.title
L2 _ Module 1 _ De thi ket thuc hoc phan_Ver2

# data[].attributes.attachment_link.readable_text
from bs4 import BeautifulSoup # �����c d��� li���u web
from PIL import ImageTk # Hi���n th��� h��nh ���nh
from gtts import gTTS # Chuy���n v��n b���n th��nh gi���ng n��i
from tkinter import messagebox, scrolledtext # H���p tho���i th��ng b��o
from urllib.request import urlopen # �����c ���nh qua link
import requests, os, tkinter, webbrowser # C��c th�� vi���n c���n thi���t kh��c
url = 'https://game24h.vn'
headers = {'User-Agent':'Chrome'}
response = requests.get(url, headers=headers)
print('response:', response)
html_data = BeautifulSoup(response.text, features='html.parser')
#
web_title = html_data.find('title').text
print('web_title:', web_title)
list_gamer_tags = html_data.find_all('div', {'class':'xepHangItem'})
print('list_gamer_tags len =', len(list_gamer_tags))
#
list_image_raws = []
list_image_tks = []
list_gamer_avatars = []
list_gamer_names = []
list_gamer_exps = []
list_gamer_links = []
#
for tag in list_gamer_tags:
    avatar = tag.find('div', {'class':'gameItemLRImg'}).find('img')['src']
    list_gamer_avatars.append(avatar)
    #
    link = tag.find('div', {'class':'gameItemLRImg'}).find('a')['href']
    link = url + link
    list_gamer_links.append(link)
    #
    name = tag.find('div', {'class':'gameItemLRName-o'}).find('a').text
    list_gamer_names.append(name)
    #
    exp = tag.find('div', {'class':'gameItemLRName-o'}).text.split(': ')[-1]
    list_gamer_exps.append(exp)
print('list_gamer_avatars:', list_gamer_avatars[0], '; len =', len(list_gamer_avatars))
print('list_gamer_links:', list_gamer_links[0], '; len =', len(list_gamer_links))
print('list_gamer_names:', list_gamer_names[0], '; len =', len(list_gamer_names))
print('list_gamer_exps:', list_gamer_exps[0], '; len =', len(list_gamer_exps))
# T��nh ��i���m exp max, min, average, sum
max_exp = 0
min_exp = int(list_gamer_exps[0])
sum_exp = 0
for num in list_gamer_exps:
    num = int(num)
    if num > max_exp:
        max_exp = num
    if num < min_exp:
        min_exp = num
    sum_exp += num  
print(f'max_exp = {max_exp}, min_exp = {min_exp}, sum_exp = {sum_exp}')
average_exp = sum_exp / len(list_gamer_exps)
print('average_exp =', average_exp)
# Thi���t k��� giao di���n tkinter
window = tkinter.Tk()
window.title(web_title)
font = ('Arial', 10, 'bold')
#
title_label = tkinter.Label(window, text=web_title, font=font, bg='darkred', fg='white')
title_label.grid(row=0, column=0, columnspan=6)
#
from urllib.request import Request
for i in range(len(list_gamer_names)):
    img_link = 'https://static.game24h.vn/upload/images/default.jpg'
    img_req = Request(img_link, headers=headers)
    avatar_raw = urlopen(img_req).read()
    list_image_raws.append(avatar_raw)
    avatar_tk = ImageTk.PhotoImage(data=list_image_raws[i])
    list_image_tks.append(avatar_tk)

def gamer_detail(index):
    text = 'T��i kho���n: ' + list_gamer_names[index] + '\n'
    text += '��i���m kinh nghi���m: ' + list_gamer_exps[index] + '\n'
    messagebox.showinfo('H��� th���ng', text)
    req = requests.get(list_gamer_links[index], headers=headers)
    gamer_html = BeautifulSoup(req.text, features='html.parser')
    detail_title = gamer_html.find('title').text
    print('detail_title:', detail_title)
position = 0
for i in range(1, 11, 2):
    avatar_label_1 = tkinter.Label(window, image=list_image_tks[position])
    avatar_label_1.grid(row=i, column=0, rowspan=2)
    name_button_1 = tkinter.Button(window, text=list_gamer_names[position], font=font)
    name_button_1.config(bg='blue', fg='white', command=lambda index=position: gamer_detail(index))
    name_button_1.grid(row=i, column=1)
    exp_text = 'Exp: ' + list_gamer_exps[position]
    exp_label_1 = tkinter.Label(window, text=exp_text, font=font)
    exp_label_1.config(bg='orange', fg='white')
    exp_label_1.grid(row=i+1, column=1)
    position += 1
    #
    avatar_label_2 = tkinter.Label(window, image=list_image_tks[position])
    avatar_label_2.grid(row=i, column=2, rowspan=2)
    name_button_2 = tkinter.Button(window, text=list_gamer_names[position], font=font)
    name_button_2.config(bg='blue', fg='white', command=lambda index=position: gamer_detail(index))
    name_button_2.grid(row=i, column=3)
    exp_text = 'Exp: ' + list_gamer_exps[position]
    exp_label_2 = tkinter.Label(window, text=exp_text, font=font)
    exp_label_2.config(bg='orange', fg='white')
    exp_label_2.grid(row=i+1, column=3)
    position += 1
window.mainloop()











