/
main.py
145 lines (104 loc) · 3.28 KB
/
main.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
from apis.weather_api import get_current_weather, get_hourly_weather
from texture.gradient_color import gradient
from datetime import datetime
from kivymd.app import MDApp
from plyer import gps
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.clock import Clock
kv ='''
ScreenManager:
MainUI:
<MainUI>:
name: 'MainUI'
RelativeLayout:
canvas:
Color:
rgba: .95,.95,1,1
Rectangle:
size: self.size
pos: self.pos
RelativeLayout:
size_hint: 1, 1
canvas.before:
Color:
rgba: 1,1,1,1
RoundedRectangle:
radius:[15,15,15,15]
size: self.size
MDLabel:
text: "Today"
font_name: 'fonts/Gilroy-light.otf'
font_size: '23dp'
pos_hint: {'center_x' : .9, 'center_y' : .8}
AsyncImage:
source: app.current_weather()[3]
pos_hint: {'center_x' : .3, 'center_y' : .64}
MDLabel:
text: str(app.current_weather()[1])
font_size: '44dp'
font_name: 'fonts/Gilroy-ExtraBold.otf'
pos_hint: {'center_x' : .97, 'center_y' : .65}
MDLabel:
text: '°c'
font_size: '22dp'
font_name: 'fonts/Gilroy-ExtraBold.otf'
color: .8,.8,.8,1
pos_hint: {'x' : .6, 'center_y' : .668}
MDLabel:
text: app.current_weather()[2]
font_name: 'fonts/Gilroy-light.otf'
font_size: '18dp'
pos_hint: {'center_x' : .97, 'center_y' : .6}
AsyncImage:
source: 'https://res.cloudinary.com/di539zorg/image/upload/c_scale,w_64/v1604029712/Weather%20App/wind.png'
pos_hint: {'center_x' : .5, 'center_y' : .45}
MDLabel:
text: str(app.current_weather()[4])+'[color=#cccccc][size=10sp]m/s[/size][/color]'
markup: True
font_name: 'fonts/Gilroy-light.otf'
font_size: '18dp'
pos_hint: {'center_x' : .95, 'center_y' : .4}
AsyncImage:
source: 'https://res.cloudinary.com/di539zorg/image/upload/c_scale,w_64/v1604029712/Weather%20App/uv.png'
pos_hint: {'center_x' : .8, 'center_y' : .45}
MDLabel:
text: app.current_weather()[5]
markup: True
font_name: 'fonts/Gilroy-light.otf'
font_size: '15dp'
pos_hint: {'x': .72, 'center_y' : .4}
AsyncImage:
source: 'https://res.cloudinary.com/di539zorg/image/upload/c_scale,w_64/v1604029712/Weather%20App/humidity.png'
pos_hint: {'center_x' : .2, 'center_y' : .45}
MDLabel:
text: str(app.current_weather()[6])+'[color=#cccccc][size=10sp]%[/size][/color]'
markup: True
font_name: 'fonts/Gilroy-light.otf'
font_size: '18dp'
pos_hint: {'x': .15, 'center_y' : .4}
'''
class MainUI(Screen):
pass
sm = ScreenManager()
sm.add_widget(MainUI(name = 'MainUI'))
class Weatherapp(MDApp):
def build(self):
self.screen = Screen()
main = Builder.load_string(kv)
self.screen.add_widget(main)
return self.screen
def theme_color(self):
return 0.6, 0.8, 1, 1
def time_now(self):
now = datetime.now()
return str(now.strftime("%I:%M %p"))
def current_weather(self):
lat = 23.76
lon = 86
return get_current_weather(lat, lon)
def texture(self):
return gradient().create([[255, 204, 204, 255], [255, 204, 204, 255], [179, 179, 255, 255], [179, 179, 255, 255]], 'Top-Bottom')
Weatherapp().run()