-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWeatherApp_2.py
More file actions
319 lines (305 loc) · 12.8 KB
/
WeatherApp_2.py
File metadata and controls
319 lines (305 loc) · 12.8 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Gui.ui'
#
# Created by: PyQt5 UI code generator 5.11.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
import requests
import os
import gmplot
import json
urlp1='https://api.openweathermap.org/data/2.5/weather?'
urlCity='q='
urlp2='&APPID=' #Place your Obtained openweathermap API Key Here next to 'APPID='. It is like 5b1625e2a9a935be9c3f96b63e556cc7
urlCordP1='lat={'
urlCordP2='}&lon={'
def reqData(city):
print("Requesting data",city)
url=urlp1+urlCity+city+urlp2
response=requests.get(url)
data=response.json()
return data
class Ui_Dialog(object):
def func(self):
try:
print("Weather Selected")
city=self.lineEdit.text()
if(city=='City'):
self.textBrowser.setText("Please enter City Name")
self.textBrowser_2.setText("")
self.textBrowser_3.setText("")
return
getData=reqData(city)
self.textBrowser.setText(city)
self.textBrowser_2.setText(str(int(float((getData['main'])['temp'])-273.15)))
self.textBrowser_3.setText((getData['weather'][0])['main']+","+(getData['weather'][0])['description'])
except Exception as e:
print(e)
self.textBrowser.setText("There was some error!!!")
self.textBrowser_2.setText("")
self.textBrowser_3.setText("")
def func2(self):
try:
print("Loc Weather Selected")
locReq=requests.get('https://ipinfo.io/city/?token=') # Place Your Obtained IpInfo API key here next to 'token='. It is like 8f5570cbc2cc02
latLng=requests.get('https://ipinfo.io/loc/?token=') # Place Your Obtained IpInfo API key here next to 'token='. It is like 8f5570cbc2cc02
latLng=latLng.text.strip()
[var1,var2]=latLng.split(',')
global lat
lat=var1
global lng
lng=var2
self.lcdNumber.display(lat)
self.lcdNumber_2.display(lng)
cityData=locReq.text.strip()
getData=reqData(cityData)
self.textBrowser.setText(cityData)
self.textBrowser_2.setText(str(int(float((getData['main'])['temp'])-273.15)))
self.textBrowser_3.setText((getData['weather'][0])['main']+","+(getData['weather'][0])['description'])
except Exception as e:
print(e)
def func3(self):
try:
print(lat,lng)
gmap1=gmplot.GoogleMapPlotter(float(lat),float(lng),16)
gmap1.marker(float(lat),float(lng))
gmap1.draw('D:\\maps123.html')
os.system('D:\\maps123.html')
except:
self.textBrowser.setText("First Locate yourself")
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(1373, 868)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(15)
font.setStyleStrategy(QtGui.QFont.PreferDefault)
Dialog.setFont(font)
Dialog.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
Dialog.setAutoFillBackground(False)
Dialog.setStyleSheet("QDialog{background-image:url(C:/Users/Harshit Agrawal/Desktop/Weather/Background_2.jpg)}")
self.label = QtWidgets.QLabel(Dialog)
self.label.setEnabled(True)
self.label.setGeometry(QtCore.QRect(10, 30, 1361, 111))
font = QtGui.QFont()
font.setFamily("Monotype Corsiva")
font.setPointSize(32)
font.setBold(True)
font.setItalic(True)
font.setUnderline(False)
font.setWeight(75)
font.setKerning(True)
font.setStyleStrategy(QtGui.QFont.PreferDefault)
self.label.setFont(font)
self.label.setAutoFillBackground(False)
self.label.setStyleSheet("")
self.label.setFrameShape(QtWidgets.QFrame.NoFrame)
self.label.setFrameShadow(QtWidgets.QFrame.Raised)
self.label.setTextFormat(QtCore.Qt.AutoText)
self.label.setScaledContents(False)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setWordWrap(True)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(110, 160, 241, 61))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setStyleSheet("")
self.label_2.setFrameShape(QtWidgets.QFrame.NoFrame)
self.label_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.label_2.setTextFormat(QtCore.Qt.PlainText)
self.label_2.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.label_2.setWordWrap(True)
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(370, 170, 281, 51))
font = QtGui.QFont()
font.setPointSize(16)
self.lineEdit.setFont(font)
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(112, 300, 251, 61))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(14)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setCheckable(False)
self.pushButton.setAutoRepeat(False)
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(570, 300, 251, 61))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.pushButton_2.setFont(font)
self.pushButton_2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.pushButton_2.setAutoDefault(True)
self.pushButton_2.setDefault(False)
self.pushButton_2.setFlat(False)
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(Dialog)
self.pushButton_3.setGeometry(QtCore.QRect(1010, 300, 251, 61))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.pushButton_3.setFont(font)
self.pushButton_3.setObjectName("pushButton_3")
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(114, 449, 221, 51))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
self.label_3.setFont(font)
self.label_3.setStyleSheet("")
self.label_3.setTextFormat(QtCore.Qt.RichText)
self.label_3.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(110, 555, 221, 51))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setStyleSheet("")
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(Dialog)
self.label_5.setGeometry(QtCore.QRect(110, 670, 291, 51))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
self.label_5.setFont(font)
self.label_5.setStyleSheet("")
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(Dialog)
self.label_6.setGeometry(QtCore.QRect(840, 450, 171, 51))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
self.label_6.setFont(font)
self.label_6.setStyleSheet("")
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(Dialog)
self.label_7.setGeometry(QtCore.QRect(840, 560, 171, 51))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
self.label_7.setFont(font)
self.label_7.setStyleSheet("")
self.label_7.setObjectName("label_7")
self.lcdNumber = QtWidgets.QLCDNumber(Dialog)
self.lcdNumber.setGeometry(QtCore.QRect(1020, 452, 241, 41))
font = QtGui.QFont()
font.setPointSize(16)
font.setItalic(False)
self.lcdNumber.setFont(font)
self.lcdNumber.setFrameShape(QtWidgets.QFrame.WinPanel)
self.lcdNumber.setFrameShadow(QtWidgets.QFrame.Sunken)
self.lcdNumber.setSmallDecimalPoint(False)
self.lcdNumber.setProperty("value",0.0000)
self.lcdNumber.setObjectName("lcdNumber")
self.lcdNumber_2 = QtWidgets.QLCDNumber(Dialog)
self.lcdNumber_2.setGeometry(QtCore.QRect(1020, 562, 241, 41))
font = QtGui.QFont()
font.setPointSize(16)
self.lcdNumber_2.setFont(font)
self.lcdNumber_2.setFrameShape(QtWidgets.QFrame.WinPanel)
self.lcdNumber_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.lcdNumber_2.setSmallDecimalPoint(False)
self.lcdNumber_2.setProperty("value",0.0000)
self.lcdNumber_2.setObjectName("lcdNumber_2")
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(370, 450, 281, 51))
font = QtGui.QFont()
font.setPointSize(16)
self.textBrowser.setFont(font)
self.textBrowser.setFrameShape(QtWidgets.QFrame.WinPanel)
self.textBrowser.setFrameShadow(QtWidgets.QFrame.Sunken)
self.textBrowser.setUndoRedoEnabled(False)
self.textBrowser.setObjectName("textBrowser")
self.textBrowser_2 = QtWidgets.QTextBrowser(Dialog)
self.textBrowser_2.setGeometry(QtCore.QRect(370, 560, 281, 51))
font = QtGui.QFont()
font.setPointSize(16)
self.textBrowser_2.setFont(font)
self.textBrowser_2.setFrameShape(QtWidgets.QFrame.WinPanel)
self.textBrowser_2.setObjectName("textBrowser_2")
self.textBrowser_3 = QtWidgets.QTextBrowser(Dialog)
self.textBrowser_3.setGeometry(QtCore.QRect(400, 670, 441, 51))
font = QtGui.QFont()
font.setPointSize(16)
self.textBrowser_3.setFont(font)
self.textBrowser_3.setFrameShape(QtWidgets.QFrame.WinPanel)
self.textBrowser_3.setObjectName("textBrowser_3")
self.label.raise_()
self.lineEdit.raise_()
self.pushButton.raise_()
self.pushButton_2.raise_()
self.pushButton_3.raise_()
self.label_3.raise_()
self.label_4.raise_()
self.label_5.raise_()
self.label_6.raise_()
self.label_7.raise_()
self.label_2.raise_()
self.lcdNumber.raise_()
self.lcdNumber_2.raise_()
self.textBrowser.raise_()
self.textBrowser_2.raise_()
self.textBrowser_3.raise_()
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.pushButton.clicked.connect(self.func)
self.pushButton_2.clicked.connect(self.func2)
self.pushButton_3.clicked.connect(self.func3)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Weather Application"))
self.label.setText(_translate("Dialog", "ARE YOU HERE FOR WEATHER INFORMATION ?"))
self.label_2.setText(_translate("Dialog", "Enter the City"))
self.pushButton.setText(_translate("Dialog", "Weather of \n"
"Entered City"))
self.pushButton_2.setText(_translate("Dialog", "Weather of\n"
"My Location"))
self.pushButton_3.setText(_translate("Dialog", "Get my location\n"
"on Map"))
self.label_3.setText(_translate("Dialog", "Name of City"))
self.label_4.setText(_translate("Dialog", "Temperature"))
self.label_5.setText(_translate("Dialog", "Weather Condition"))
self.label_6.setText(_translate("Dialog", "Latitude"))
self.label_7.setText(_translate("Dialog", "Longitude"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())