-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_pokemon_api.py
84 lines (60 loc) · 2.63 KB
/
gui_pokemon_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import sys
import aiohttp
import asyncio
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QHBoxLayout, QVBoxLayout, QLabel, QWidget, \
QLineEdit, QTextEdit, QComboBox, QMessageBox
# Subclass QMainWindow to customize your application's main window
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.selectedTag = None
self.threshold = 20
self.setWindowTitle("A GUI Application for Pokemon Details")
self.resize(1200, 800)
self.scrapData = None
self.soup = None
# Styles
self.buttonStyles = "background-color:#CCCCCC; padding: 8px; border-radius: 5px;"
self.searchInput = QHBoxLayout()
self.urlLabel = QLabel()
self.urlLabel.setText('Enter the Url to Get Pokemon Details :')
self.urlLabel.setStyleSheet("font-weight: 700; font-size: 18px;")
self.searchInput.addWidget(self.urlLabel)
self.urlTextField = QLineEdit()
self.urlTextField.setStyleSheet("padding: 8px;")
self.searchInput.addWidget(self.urlTextField)
self.bottomContent = QHBoxLayout()
self.getResultBtn = QPushButton('Get Pokemon Data')
self.getResultBtn.setStyleSheet(self.buttonStyles)
self.getResultBtn.clicked.connect(self.getAPIResponse)
self.bottomContent.addWidget(self.getResultBtn)
self.scrapResultField = QTextEdit()
self.scrapResultField.setStyleSheet("background-color:white; padding: 16px;")
self.pageLayout = QVBoxLayout()
self.pageLayout.addLayout(self.searchInput)
self.pageLayout.addWidget(self.scrapResultField)
self.pageLayout.addLayout(self.bottomContent)
widget = QWidget()
widget.setLayout(self.pageLayout)
self.setCentralWidget(widget)
def openInfoDialog(self, message):
dlg = QMessageBox(self)
dlg.setWindowTitle("Info!")
dlg.setText(message)
dlg.exec()
async def getApiData(self):
async with aiohttp.ClientSession() as session:
pokemon_url = self.urlTextField.text()
if not pokemon_url.startswith("https://pokeapi.co/api/v2/pokemon"):
self.openInfoDialog('Url is not valid')
else:
self.scrapResultField.setText('Loading...')
async with session.get(pokemon_url) as resp:
pokemon = await resp.json()
self.scrapResultField.setText(str(pokemon))
def getAPIResponse(self):
asyncio.run(self.getApiData())
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()