-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwetterapp.py
146 lines (121 loc) · 4.65 KB
/
wetterapp.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
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
from sys import exit
import pygame
import requests
class API:
def __init__(self, stadt, apikey = "Gebe deinen eigenen ein"):
self.stadt = stadt
self.apikey = apikey
def kontrolle(self):
r = requests.get("http://api.openweathermap.org/data/2.5/weather?q={}&appid={}".format(self.stadt, self.apikey))
r = r.ok
return r
def get(self):
r = requests.get("http://api.openweathermap.org/data/2.5/weather?q={}&appid={}".format(self.stadt, self.apikey))
r = r.json()
return r
@staticmethod
def inf_sorting(r):
display_data = [r["wind"]["speed"], r["main"]["pressure"], r["main"]["humidity"], r["wind"]["deg"], r["main"]["temp"], r["main"]["feels_like"]]
return display_data
def inf_ausgabe(self, data):
windrichtung = data[3]
windspeed = str(data[0]) + " " + "m/s"
druck = str(data[1]) + "hPa"
temp = str(int(data[4] - 273.15)) + "°C"
feels_like = str(round(data[5] - 273.15)) + "°C"
luftfeucht = str(data[2]) + "%"
if windrichtung >= 0 and windrichtung <= 90:
windrichtung = "NO"
elif windrichtung == 0:
windrichtung = "N"
elif windrichtung == 90:
windrichtung = "O"
elif windrichtung >= 90 and windrichtung <= 180:
windrichtung = "SO"
elif windrichtung == 180:
windrichtung = "S"
elif windrichtung >= 180 and windrichtung <= 270:
windrichtung ="SW"
elif windrichtung == 270:
windrichtung = "W"
else:
windrichtung = "NW"
ausgabe = [self.stadt, temp, feels_like, windrichtung, windspeed, druck, luftfeucht]
return ausgabe
pygame.init()
class stuff:
def __init__(self, wo, was, scale):
self.x = wo[0]
self.y = wo[1]
self.object = pygame.image.load(was)
self.trans_obejct = pygame.transform.scale_by(self.object, (scale[0], scale[1]))
self.rect = self.object.get_rect(center = (self.x, self.y))
def draw(self):
win.blit(self.trans_obejct, self.rect)
class Text(object):
def __init__(self, wo, inhalt, art, größe, farbe):
self.text = pygame.font.Font(art, größe)
self.text_ren = self.text.render(inhalt, True, farbe)
self.text_rect = self.text_ren.get_rect(center = (wo[0], wo[1]))
def draw(self):
win.blit(self.text_ren, self.text_rect)
searchbar = stuff((260, 40), ".\Assets\search.png.png", (0.7, 0.8))
bar = stuff((450, 450), ".\Assets\Copy of box.png", (1,1))
scope = stuff((315, 35), ".\Assets\Copy of search_icon.png", (1,1))
#framerate
win = pygame.display.set_mode((900, 500))
pygame.display.set_caption("Wetterapp")
fps = pygame.time.Clock()
#bg
bg = pygame.image.load(".\Assets\Copy of logo.png").convert_alpha()
bg_trans = pygame.transform.scale_by(bg, (1.1, 1.1))
bg_rect = bg_trans.get_rect(center = (450, 200))
back = pygame.Surface((900, 500))
back.fill("White")
def sbarinput(text):
searchbar_content = Text((175, 33), text, None, 38, "#FFFFFF")
searchbar_content.draw()
def wetterausgabe(eingabe):
ausgabe1 = Text((170, 455), eingabe[1], None, 38, "Black")
ausgabe1.draw()
ausgabe2 = Text((270, 455), eingabe[3], None, 38, "Black")
ausgabe2.draw()
ausgabe3 = Text((400, 455), eingabe[4], None, 38, "Black")
ausgabe3.draw()
ausgabe4 = Text((550, 455), eingabe[5], None, 38, "Black")
ausgabe4.draw()
ausgabe5 = Text((700, 455), eingabe[6], None, 38, "Black")
ausgabe5.draw()
def keyboardInput(event,text, UIFeed):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
s = API(text)
UIFeed = s.inf_ausgabe(s.inf_sorting(s.get()))
print(UIFeed)
elif event.key == pygame.K_BACKSPACE:
text = text[:-1]
else:
text += event.unicode
if event.type == pygame.MOUSEBUTTONDOWN:
if scope.rect.collidepoint(pygame.mouse.get_pos()):
s = API(text)
UIFeed = s.inf_ausgabe(s.inf_sorting(s.get()))
return text, UIFeed
text = ""
UIFeed = None
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
text, UIFeed = keyboardInput(event, text, UIFeed)
win.blit(back, (0, 0))
searchbar.draw()
sbarinput(text)
scope.draw()
bar.draw()
if UIFeed != None:
wetterausgabe(UIFeed)
win.blit(bg_trans, bg_rect)
pygame.display.update()
fps.tick(60)