├── mainProjct ├── __init__.py ├── .idea │ ├── misc.xml │ ├── inspectionProfiles │ │ └── profiles_settings.xml │ ├── modules.xml │ ├── MagicMirror.iml │ └── workspace.xml ├── clock.py ├── senten_load.py ├── top_date.py ├── weather.py ├── mainwindow.ui └── mainwindow.py ├── server ├── input.py └── server.py └── README.md /mainProjct/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mainProjct/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /mainProjct/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /mainProjct/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mainProjct/.idea/MagicMirror.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /mainProjct/clock.py: -------------------------------------------------------------------------------- 1 | import time 2 | def getTime(): 3 | my_time = time.localtime(time.time()) 4 | 5 | if my_time[3] < 10: 6 | hour = '0' + str(my_time[3]) 7 | else: 8 | hour = str(my_time[3]) 9 | if my_time[4] < 10: 10 | min = '0' + str(my_time[4]) 11 | else: 12 | min = str(my_time[4]) 13 | if my_time[5] < 10: 14 | second = '0' + str(my_time[5]) 15 | else: 16 | second = str(my_time[5]) 17 | 18 | return hour,min,second 19 | -------------------------------------------------------------------------------- /mainProjct/senten_load.py: -------------------------------------------------------------------------------- 1 | import socket 2 | HOST='115.159.22.181' 3 | #HOST='127.0.0.1' 4 | PORT= 6666 5 | def getSentence(): 6 | s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) #定义socket类型,网络通信,TCP 7 | s.connect((HOST,PORT)) #要连接的IP与端口 8 | while True: 9 | s.send("load".encode('utf8')) #把命令发送给对端 10 | data=s.recv(1024).decode('utf-8') #把接收的数据定义为变量 11 | print(data) #输出变量 12 | return data 13 | s.close() #关闭连接 14 | -------------------------------------------------------------------------------- /server/input.py: -------------------------------------------------------------------------------- 1 | import socket 2 | HOST='115.159.22.181' 3 | PORT= 6666 4 | def load_sentence(): 5 | s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) #定义socket类型,网络通信,TCP 6 | s.connect((HOST,PORT)) #要连接的IP与端口 7 | while True: 8 | sen = input() 9 | msg = 'newmsg/' + sen 10 | 11 | s.sendall(msg.encode('utf8')) #把命令发送给对端 12 | data=s.recv(1024).decode('utf-8') #把接收的数据定义为变量 13 | print(data) #输出变量 14 | s.close() #关闭连接 15 | 16 | load_sentence() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mirror 2 | ## With MagicMirror, use pyqt to write a similar interface. 3 | 4 |    MagicMirror项目地址:https://github.com/MichMich/MagicMirror 5 | 6 | 原项目是用JavaScript写的,我对这个了解得不多,刚学了python然后有一点Qt的基础,然后就用了pyqt来写这个。
7 | 代码界面是按照显示屏尺寸800*480写的,是微雪7寸的显示屏。
8 | 9 | 运行: 10 | 在树莓派上安装好python3以及pyqt环境之后运行:
11 | ``` 12 | sudo python3 mainwindow.py 13 | ``` 14 | 15 | ### mainProject 文件夹是主要代码区,包括了各个日期、时间、天气以及句子模块。 16 | * 顶部的日期模块有一点小问题,代码可能比较累赘,因为天气的一个API里获取了一些日期的数据,应该有更简单的办法来获取。
17 | 18 | * 天气接口一开始在阿里云找了一个接口,其实上面数据蛮全的,但是由于当时没有认真研究返回的json就换了和风天气的接口。
19 | 20 | * 句子模块是从服务器端数据库定时读取数据显示在屏幕上。 21 | 22 | ### server文件中包含了远程向服务器添加自定义语句以及服务器端接收的代码。 23 | 24 | 服务器端运行:
25 | ``` 26 | sudo python3 server.py 27 | ``` 28 | 然后通过运行input文件远程向服务器数据库中存取数据 29 | 30 | * 另外,因为自己用的是七寸的显示屏,屏幕显示的内容有限暂时弄了这个界面,弄界面蛮麻烦的,后期考虑封装一下,更好的对界面以及内容进行增添和修改。 31 | 32 | #### 各位大佬如果有什么想法或者意见,请指教一下。 33 | #### 博客地址:http://doubiiot.cn 34 | -------------------------------------------------------------------------------- /mainProjct/top_date.py: -------------------------------------------------------------------------------- 1 | import urllib, urllib.request, sys 2 | import json 3 | def getDate(): 4 | ''' 5 | host_city = 'http://jisutqybmf.market.alicloudapi.com' 6 | path_city = '/weather/city' 7 | method = 'GET' 8 | appcode = '7355c8fabd674079adf1afaadb2012f6' 9 | querys = '' 10 | bodys = {} 11 | url = host_city + path_city 12 | 13 | request_city = urllib.request.Request(url) 14 | request_city.add_header('Authorization', 'APPCODE ' + appcode) 15 | response_city = urllib.request.urlopen(request_city) 16 | content_city = response_city.read().decode('utf-8') 17 | cityinfo = json.loads(content_city) 18 | for x in cityinfo['result']: 19 | if(x['city'] == "青岛"): 20 | print(x) 21 | ''' 22 | host = 'http://jisutqybmf.market.alicloudapi.com' 23 | path = '/weather/query' 24 | method = 'GET' 25 | appcode = '7355c8fabd674079adf1afaadb2012f6' 26 | querys = 'citycode=101120201&cityid=283&ip=ip&location=location' 27 | bodys = {} 28 | url = host + path + '?' + querys 29 | 30 | request = urllib.request.Request(url) 31 | request.add_header('Authorization', 'APPCODE ' + appcode) 32 | response = urllib.request.urlopen(request) 33 | content_date = response.read().decode('utf-8') 34 | mydate = json.loads(content_date)['result'] 35 | week = mydate['week'][2] 36 | if week == "一": 37 | week = "Monday" 38 | elif week == "二": 39 | week = "Tuesday" 40 | elif week == "三": 41 | week = "Wednesday" 42 | elif week == "四": 43 | week = "Thursday" 44 | elif week == "五": 45 | week = "Friday" 46 | elif week == "六": 47 | week = "Saturday" 48 | else : 49 | week = "Sunday" 50 | month = mydate['date'][5:7] 51 | if month == "01": 52 | month = "January" 53 | elif month == "02": 54 | month = "February" 55 | elif month == "03": 56 | month = "March" 57 | elif month == "04": 58 | month = "April" 59 | elif month == "05": 60 | month = "May" 61 | elif month == "06": 62 | month = "June" 63 | elif month == "07": 64 | month = "July" 65 | elif month == "08": 66 | month = "August" 67 | elif month == "09": 68 | month = "September" 69 | elif month == "10": 70 | month = "October" 71 | elif month == "11": 72 | month = "November" 73 | elif month == "12": 74 | month = "December" 75 | spell = week + ',' + month + ' ' + mydate['date'][8:10] + ',' + mydate['date'][0:4] 76 | return spell 77 | -------------------------------------------------------------------------------- /mainProjct/weather.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | import urllib, urllib.request, sys 3 | import json 4 | 5 | def getWeather(): 6 | host = 'https://free-api.heweather.com/v5/forecast?city=CN101120201&key=4f4aa9f984ad44c2b2fdd78280b31900' 7 | host_now = 'https://free-api.heweather.com/v5/now?city=CN101120201&key=4f4aa9f984ad44c2b2fdd78280b31900' 8 | # 下载数据 9 | content1 = loadData(host) 10 | content2 = loadData(host_now) 11 | #print(content_data) 12 | dic_data = json.loads(content1)['HeWeather5'][0]['daily_forecast'] 13 | realtime_data = json.loads(content2)['HeWeather5'][0]['now']['tmp'] 14 | i = 0 15 | threeday_data = [] 16 | for key in dic_data: 17 | #print(key) 18 | i += 1 19 | if(i==1): 20 | today_data = storeData(key) 21 | threeday_data.append(today_data) 22 | elif(i==2): 23 | tmr_data = storeData(key) 24 | threeday_data.append(tmr_data) 25 | elif(i==3): 26 | dat_data = storeData(key) 27 | threeday_data.append(dat_data) 28 | threeday_data.append(realtime_data) 29 | #print(threeday_data) 30 | return threeday_data 31 | def loadData(url): 32 | request = urllib.request.Request(url) 33 | response = urllib.request.urlopen(request) 34 | content_data = response.read().decode('utf-8') 35 | return content_data 36 | def storeData(key): 37 | alldata = [] 38 | alldata.append(key['cond']['txt_d']) 39 | alldata.append(key['date']) 40 | alldata.append(key['hum']) 41 | alldata.append(key['tmp']['max']) 42 | alldata.append(key['tmp']['min']) 43 | alldata.append(key['wind']['dir']) 44 | alldata.append(key['wind']['sc']) 45 | return alldata 46 | 47 | getWeather() 48 | 49 | ''' 50 | # 解析JSON 51 | 52 | 需要的数据: 53 | city\date\week\weather\temp\temphigh\templow\humidity\winddirect\windpower 54 | 55 | weather_data = {} 56 | dic_data = json.loads(content_data)['result'] 57 | for key in dic_data: 58 | if (key == "city"): 59 | weather_data['city'] = dic_data['city'] 60 | elif(key == "date"): 61 | weather_data['date'] = dic_data['date'] 62 | elif (key == "week"): 63 | weather_data['week'] = dic_data['week'] 64 | elif (key == "weather"): 65 | weather_data['weather'] = dic_data['weather'] 66 | elif (key == "temp"): 67 | weather_data['temp'] = dic_data['temp'] 68 | elif (key == "humidity"): 69 | weather_data['humidity'] = dic_data['humidity'] 70 | elif (key == "winddirect"): 71 | weather_data['winddirect'] = dic_data['winddirect'] 72 | elif (key == "windpower"): 73 | weather_data['windpower'] = dic_data['windpower'] 74 | 75 | return weather_data 76 | ''' 77 | -------------------------------------------------------------------------------- /server/server.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import random 3 | import pymysql 4 | PORT = 6666 5 | pass_word = '123456' 6 | def InsertIntoMysql(buff): 7 | ins_succ = 0 8 | try: 9 | #create table all_sentence (id INT NOT NULL AUTO_INCREMENT,my_sentence VARCHAR(64) NOT NULL,PRIMARYY KEY(id)) 10 | # 打开数据库连接 11 | db = pymysql.connect(host='127.0.0.1',user='root',passwd=pass_word,db='mysql') 12 | # 使用 cursor() 方法创建一个游标对象 cursor 13 | cur = db.cursor() 14 | #数据库语句 15 | #cur.execute('CREATE DATABASE IF NOT EXISTS sentence')#create db 16 | cur.execute('USE sentence') 17 | #insert 18 | #INSERT INTO all_sentence values('1','123456'); 19 | cur.execute('INSERT INTO all_sentence(my_sentence) VALUES(%s)',(buff)) 20 | cur.connection.commit() 21 | ins_succ = 1 22 | except Exception as e: 23 | print(e) 24 | db.close() 25 | return ins_succ 26 | 27 | def load_sentence(): 28 | try: 29 | # 打开数据库连接 30 | db = pymysql.connect(host='127.0.0.1',user='root',passwd=pass_word,db='mysql') 31 | # 使用 cursor() 方法创建一个游标对象 cursor 32 | cur = db.cursor() 33 | cur.execute('USE sentence') 34 | #select one 35 | cur.execute('select count(*) from all_sentence') 36 | id_num = cur.fetchone() 37 | print("id_num = %s" % id_num) 38 | all_num = int(id_num[0]) 39 | print("all_num = %s" % all_num) 40 | radnum = random.randint(1, all_num) 41 | print("radnum is %s" % radnum) 42 | print(str(radnum)) 43 | try: 44 | cur.execute('SELECT * FROM all_sentence WHERE id = %s' % str(radnum)) 45 | except Exception as sql_error: 46 | print(sql_error) 47 | data = cur.fetchone() 48 | print(data) 49 | return data 50 | except Exception as e: 51 | print(e) 52 | db.close() 53 | 54 | if __name__ == "__main__": 55 | soc_server = socket.socket(socket.AF_INET,socket.SOCK_STREAM) 56 | soc_server.bind(('',PORT)) 57 | soc_server.listen(5) 58 | while True: 59 | try: 60 | coon,addr = soc_server.accept() 61 | print("%s connect success!" % str(addr[0])) 62 | data = coon.recv(1024).decode('utf-8') 63 | if data == "load": 64 | snd_msg = load_sentence() 65 | #print("snd msg is %s" % snd_msg) 66 | #print(snd_msg[1]) 67 | coon.sendall(snd_msg[1].encode('utf-8')) 68 | 69 | else: 70 | if(data.split('/', 1)[0] == 'newmsg'): 71 | msg = data.split('/', 1)[1] 72 | print(msg) 73 | if(InsertIntoMysql(msg)): 74 | print("msg : '%s' insert into mysql success!" % msg) 75 | coon.sendall("insert success".encode('utf-8')) 76 | else: 77 | coon.sendall("insert failed".encode('utf-8')) 78 | except Exception as soc_error: 79 | print(soc_error) 80 | -------------------------------------------------------------------------------- /mainProjct/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 550 10 | 800 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | background-color: rgb(0, 0, 0); 18 | 19 | 20 | 21 | 22 | 23 | 0 24 | 0 25 | 311 26 | 101 27 | 28 | 29 | 30 | 31 | 32 | 20 33 | 60 34 | 251 35 | 31 36 | 37 | 38 | 39 | 40 | 41 | 0 42 | -10 43 | 241 44 | 41 45 | 46 | 47 | 48 | 49 | 16 50 | 51 | 52 | 53 | color: rgb(255, 255, 255); 54 | 55 | 56 | LOADING..... 57 | 58 | 59 | 60 | 61 | 62 | 63 | 10 64 | 30 65 | 261 66 | 21 67 | 68 | 69 | 70 | 71 | 15 72 | 75 73 | true 74 | 75 | 76 | 77 | color: rgb(255, 255, 255); 78 | 79 | 80 | __________________________ 81 | 82 | 83 | 84 | 85 | 86 | 10 87 | 20 88 | 121 89 | 21 90 | 91 | 92 | 93 | 94 | 15 95 | 75 96 | true 97 | 98 | 99 | 100 | color: rgb(255, 255, 255); 101 | 102 | 103 | DATE TIME 104 | 105 | 106 | 107 | 108 | 109 | 110 | 0 111 | 110 112 | 311 113 | 371 114 | 115 | 116 | 117 | 118 | 119 | -10 120 | 30 121 | 321 122 | 21 123 | 124 | 125 | 126 | 127 | 15 128 | 75 129 | true 130 | 131 | 132 | 133 | color: rgb(255, 255, 255); 134 | 135 | 136 | _____________________________ 137 | 138 | 139 | 140 | 141 | 142 | 10 143 | 10 144 | 111 145 | 31 146 | 147 | 148 | 149 | 150 | 15 151 | 75 152 | true 153 | false 154 | 155 | 156 | 157 | color: rgb(255, 255, 255); 158 | 159 | 160 | WEATHER 161 | 162 | 163 | 164 | 165 | 166 | 30 167 | 200 168 | 271 169 | 161 170 | 171 | 172 | 173 | 174 | 175 | 10 176 | 20 177 | 41 178 | 31 179 | 180 | 181 | 182 | 183 | 12 184 | 75 185 | true 186 | 187 | 188 | 189 | 190 | color: rgb(255, 255, 255); 191 | 192 | 193 | .... 194 | 195 | 196 | 197 | 198 | 199 | 10 200 | 120 201 | 41 202 | 31 203 | 204 | 205 | 206 | 207 | 12 208 | 75 209 | true 210 | 211 | 212 | 213 | 214 | color: rgb(255, 255, 255); 215 | 216 | 217 | .... 218 | 219 | 220 | 221 | 222 | 223 | 10 224 | 70 225 | 41 226 | 31 227 | 228 | 229 | 230 | 231 | 12 232 | 75 233 | true 234 | 235 | 236 | 237 | 238 | color: rgb(255, 255, 255); 239 | 240 | 241 | .... 242 | 243 | 244 | 245 | 246 | 247 | 70 248 | 120 249 | 51 250 | 31 251 | 252 | 253 | 254 | 255 | 12 256 | 75 257 | true 258 | 259 | 260 | 261 | 262 | color: rgb(255, 255, 255); 263 | 264 | 265 | .... 266 | 267 | 268 | 269 | 270 | 271 | 70 272 | 70 273 | 51 274 | 31 275 | 276 | 277 | 278 | 279 | 12 280 | 75 281 | true 282 | 283 | 284 | 285 | 286 | color: rgb(255, 255, 255); 287 | 288 | 289 | .... 290 | 291 | 292 | 293 | 294 | 295 | 70 296 | 20 297 | 51 298 | 31 299 | 300 | 301 | 302 | 303 | 12 304 | 75 305 | true 306 | 307 | 308 | 309 | 310 | color: rgb(255, 255, 255); 311 | 312 | 313 | .... 314 | 315 | 316 | 317 | 318 | 319 | 140 320 | 70 321 | 41 322 | 31 323 | 324 | 325 | 326 | 327 | 12 328 | 75 329 | true 330 | 331 | 332 | 333 | 334 | color: rgb(255, 255, 255); 335 | 336 | 337 | ..° 338 | 339 | 340 | 341 | 342 | 343 | 140 344 | 20 345 | 41 346 | 31 347 | 348 | 349 | 350 | 351 | 12 352 | 75 353 | true 354 | 355 | 356 | 357 | 358 | color: rgb(255, 255, 255); 359 | 360 | 361 | ..° 362 | 363 | 364 | 365 | 366 | 367 | 140 368 | 120 369 | 41 370 | 31 371 | 372 | 373 | 374 | 375 | 12 376 | 75 377 | true 378 | 379 | 380 | 381 | 382 | color: rgb(255, 255, 255); 383 | 384 | 385 | ..° 386 | 387 | 388 | 389 | 390 | 391 | 190 392 | 120 393 | 71 394 | 31 395 | 396 | 397 | 398 | 399 | 12 400 | 75 401 | true 402 | 403 | 404 | 405 | 406 | color: rgb(255, 255, 255); 407 | 408 | 409 | ........ 410 | 411 | 412 | 413 | 414 | 415 | 190 416 | 70 417 | 71 418 | 31 419 | 420 | 421 | 422 | 423 | 12 424 | 75 425 | true 426 | 427 | 428 | 429 | 430 | color: rgb(255, 255, 255); 431 | 432 | 433 | ........ 434 | 435 | 436 | 437 | 438 | 439 | 190 440 | 20 441 | 71 442 | 31 443 | 444 | 445 | 446 | 447 | 12 448 | 75 449 | true 450 | 451 | 452 | 453 | 454 | color: rgb(255, 255, 255); 455 | 456 | 457 | ........ 458 | 459 | 460 | 461 | 462 | 463 | 464 | 10 465 | 60 466 | 291 467 | 161 468 | 469 | 470 | 471 | 472 | 473 | 30 474 | 0 475 | 181 476 | 71 477 | 478 | 479 | 480 | 481 | 文泉驿点阵正黑 482 | 38 483 | 75 484 | true 485 | 486 | 487 | 488 | color: rgb(255, 255, 255); 489 | 490 | 491 | 25° 492 | 493 | 494 | 495 | 496 | 497 | 30 498 | 60 499 | 181 500 | 41 501 | 502 | 503 | 504 | 505 | 15 506 | 75 507 | true 508 | 509 | 510 | 511 | color: rgb(255, 255, 255); 512 | style="text-align:center" 513 | 514 | 515 | 雷阵雨 516 | 517 | 518 | 519 | 520 | 521 | 200 522 | 160 523 | 41 524 | 31 525 | 526 | 527 | 528 | 529 | 12 530 | 75 531 | true 532 | 533 | 534 | 535 | 536 | color: rgb(255, 255, 255); 537 | 538 | 539 | 风力 540 | 541 | 542 | 543 | 544 | 545 | 30 546 | 100 547 | 181 548 | 41 549 | 550 | 551 | 552 | 553 | 8 554 | 75 555 | true 556 | 557 | 558 | 559 | color: rgb(255, 255, 255); 560 | 561 | 562 | 。。。/。。。 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 0 571 | 490 572 | 531 573 | 71 574 | 575 | 576 | 577 | 578 | 30 579 | 75 580 | true 581 | 582 | 583 | 584 | 585 | color: rgb(255, 255, 255); 586 | 587 | 588 | LOADING.... 589 | 590 | 591 | 592 | 593 | 594 | 595 | 0 596 | 0 597 | 550 598 | 25 599 | 600 | 601 | 602 | 603 | 604 | TopToolBarArea 605 | 606 | 607 | false 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | -------------------------------------------------------------------------------- /mainProjct/mainwindow.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'mainwindow.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.9 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | import sys 9 | from weather import getWeather 10 | from top_date import getDate 11 | from clock import getTime 12 | from senten_load import getSentence 13 | from PyQt5 import QtCore, QtGui, QtWidgets 14 | 15 | import threading 16 | class Ui_MainWindow(QtWidgets.QMainWindow): 17 | i = 0 18 | def setupUi(self, MainWindow): 19 | MainWindow.setObjectName("MainWindow") 20 | MainWindow.resize(480, 800) 21 | MainWindow.setStyleSheet("background-color: rgb(0, 0, 0);") 22 | self.centralWidget = QtWidgets.QWidget(MainWindow) 23 | self.centralWidget.setObjectName("centralWidget") 24 | self.widget_3 = QtWidgets.QWidget(self.centralWidget) 25 | self.widget_3.setGeometry(QtCore.QRect(0, 0, 295, 101)) 26 | self.widget_3.setObjectName("widget_3") 27 | self.widget_2 = QtWidgets.QWidget(self.widget_3) 28 | self.widget_2.setGeometry(QtCore.QRect(20, 60, 320, 31)) 29 | self.widget_2.setObjectName("widget_2") 30 | self.label_day = QtWidgets.QLabel(self.widget_2) 31 | self.label_day.setGeometry(QtCore.QRect(0, -12, 311, 41)) 32 | font = QtGui.QFont() 33 | font.setPointSize(16) 34 | self.label_day.setFont(font) 35 | self.label_day.setStyleSheet("color: rgb(255, 255, 255);") 36 | self.label_day.setObjectName("label_day") 37 | self.label_9 = QtWidgets.QLabel(self.widget_3) 38 | self.label_9.setGeometry(QtCore.QRect(0, 30, 350, 21)) 39 | font = QtGui.QFont() 40 | font.setPointSize(15) 41 | font.setBold(True) 42 | font.setWeight(75) 43 | self.label_9.setFont(font) 44 | self.label_9.setStyleSheet("color: rgb(255, 255, 255);") 45 | self.label_9.setObjectName("label_9") 46 | self.label_18 = QtWidgets.QLabel(self.widget_3) 47 | self.label_18.setGeometry(QtCore.QRect(10, 10, 125, 21)) 48 | font = QtGui.QFont() 49 | font.setPointSize(15) 50 | font.setBold(True) 51 | font.setWeight(75) 52 | self.label_18.setFont(font) 53 | self.label_18.setStyleSheet("color: rgb(255, 255, 255);") 54 | self.label_18.setObjectName("label_18") 55 | self.widget_4 = QtWidgets.QWidget(self.centralWidget) 56 | self.widget_4.setGeometry(QtCore.QRect(0, 110, 411, 371)) 57 | self.widget_4.setObjectName("widget_4") 58 | self.label_10 = QtWidgets.QLabel(self.widget_4) 59 | self.label_10.setGeometry(QtCore.QRect(0, 30, 321, 21)) 60 | font = QtGui.QFont() 61 | font.setPointSize(15) 62 | font.setBold(True) 63 | font.setWeight(75) 64 | self.label_10.setFont(font) 65 | self.label_10.setStyleSheet("color: rgb(255, 255, 255);") 66 | self.label_10.setObjectName("label_10") 67 | self.label_19 = QtWidgets.QLabel(self.widget_4) 68 | self.label_19.setGeometry(QtCore.QRect(10, 5, 111, 31)) 69 | font = QtGui.QFont() 70 | font.setPointSize(15) 71 | font.setBold(True) 72 | font.setUnderline(False) 73 | font.setWeight(75) 74 | self.label_19.setFont(font) 75 | self.label_19.setStyleSheet("color: rgb(255, 255, 255);") 76 | self.label_19.setObjectName("label_19") 77 | self.widget_5 = QtWidgets.QWidget(self.widget_4) 78 | self.widget_5.setGeometry(QtCore.QRect(10, 200, 400, 161)) 79 | self.widget_5.setObjectName("widget_5") 80 | self.td = QtWidgets.QLabel(self.widget_5) 81 | self.td.setGeometry(QtCore.QRect(0, 20, 81, 31)) 82 | font = QtGui.QFont() 83 | font.setPointSize(18) 84 | font.setBold(True) 85 | font.setWeight(75) 86 | self.td.setFont(font) 87 | self.td.setStyleSheet("\n" 88 | "color: rgb(255, 255, 255);") 89 | self.td.setObjectName("td") 90 | self.dat = QtWidgets.QLabel(self.widget_5) 91 | self.dat.setGeometry(QtCore.QRect(0, 120, 81, 31)) 92 | font = QtGui.QFont() 93 | font.setPointSize(18) 94 | font.setBold(True) 95 | font.setWeight(75) 96 | self.dat.setFont(font) 97 | self.dat.setStyleSheet("\n" 98 | "color: rgb(255, 255, 255);") 99 | self.dat.setObjectName("dat") 100 | self.tmr = QtWidgets.QLabel(self.widget_5) 101 | self.tmr.setGeometry(QtCore.QRect(0, 70, 81, 31)) 102 | font = QtGui.QFont() 103 | font.setPointSize(18) 104 | font.setBold(True) 105 | font.setWeight(75) 106 | self.tmr.setFont(font) 107 | self.tmr.setStyleSheet("\n" 108 | "color: rgb(255, 255, 255);") 109 | self.tmr.setObjectName("tmr") 110 | self.dat_weather = QtWidgets.QLabel(self.widget_5) 111 | self.dat_weather.setGeometry(QtCore.QRect(90, 120, 101, 31)) 112 | font = QtGui.QFont() 113 | font.setPointSize(18) 114 | font.setBold(True) 115 | font.setWeight(75) 116 | self.dat_weather.setFont(font) 117 | self.dat_weather.setStyleSheet("\n" 118 | "color: rgb(255, 255, 255);") 119 | self.dat_weather.setObjectName("dat_weather") 120 | self.tmr_weather = QtWidgets.QLabel(self.widget_5) 121 | self.tmr_weather.setGeometry(QtCore.QRect(90, 70, 111, 31)) 122 | font = QtGui.QFont() 123 | font.setPointSize(18) 124 | font.setBold(True) 125 | font.setWeight(75) 126 | self.tmr_weather.setFont(font) 127 | self.tmr_weather.setStyleSheet("\n" 128 | "color: rgb(255, 255, 255);") 129 | self.tmr_weather.setObjectName("tmr_weather") 130 | self.td_weather = QtWidgets.QLabel(self.widget_5) 131 | self.td_weather.setGeometry(QtCore.QRect(90, 20, 111, 31)) 132 | font = QtGui.QFont() 133 | font.setPointSize(18) 134 | font.setBold(True) 135 | font.setWeight(75) 136 | self.td_weather.setFont(font) 137 | self.td_weather.setStyleSheet("\n" 138 | "color: rgb(255, 255, 255);") 139 | self.td_weather.setObjectName("td_weather") 140 | self.tm_tmp = QtWidgets.QLabel(self.widget_5) 141 | self.tm_tmp.setGeometry(QtCore.QRect(220, 70, 101, 31)) 142 | font = QtGui.QFont() 143 | font.setPointSize(18) 144 | font.setBold(True) 145 | font.setWeight(75) 146 | self.tm_tmp.setFont(font) 147 | self.tm_tmp.setStyleSheet("\n" 148 | "color: rgb(255, 255, 255);") 149 | self.tm_tmp.setObjectName("tm_tmp") 150 | self.td_tmp = QtWidgets.QLabel(self.widget_5) 151 | self.td_tmp.setGeometry(QtCore.QRect(220, 20, 101, 31)) 152 | font = QtGui.QFont() 153 | font.setPointSize(18) 154 | font.setBold(True) 155 | font.setWeight(75) 156 | self.td_tmp.setFont(font) 157 | self.td_tmp.setStyleSheet("\n" 158 | "color: rgb(255, 255, 255);") 159 | self.td_tmp.setObjectName("td_tmp") 160 | self.dat_tmp = QtWidgets.QLabel(self.widget_5) 161 | self.dat_tmp.setGeometry(QtCore.QRect(220, 120, 81, 31)) 162 | font = QtGui.QFont() 163 | font.setPointSize(18) 164 | font.setBold(True) 165 | font.setWeight(75) 166 | self.dat_tmp.setFont(font) 167 | self.dat_tmp.setStyleSheet("\n" 168 | "color: rgb(255, 255, 255);") 169 | self.dat_tmp.setObjectName("dat_tmp") 170 | self.dat_wind = QtWidgets.QLabel(self.widget_5) 171 | self.dat_wind.setGeometry(QtCore.QRect(340, 120, 71, 31)) 172 | font = QtGui.QFont() 173 | font.setPointSize(18) 174 | font.setBold(True) 175 | font.setWeight(75) 176 | self.dat_wind.setFont(font) 177 | self.dat_wind.setStyleSheet("\n" 178 | "color: rgb(255, 255, 255);") 179 | self.dat_wind.setObjectName("dat_wind") 180 | self.tm_wind = QtWidgets.QLabel(self.widget_5) 181 | self.tm_wind.setGeometry(QtCore.QRect(340, 70, 71, 31)) 182 | font = QtGui.QFont() 183 | font.setPointSize(18) 184 | font.setBold(True) 185 | font.setWeight(75) 186 | self.tm_wind.setFont(font) 187 | self.tm_wind.setStyleSheet("\n" 188 | "color: rgb(255, 255, 255);") 189 | self.tm_wind.setObjectName("tm_wind") 190 | self.td_wind = QtWidgets.QLabel(self.widget_5) 191 | self.td_wind.setGeometry(QtCore.QRect(340, 20, 71, 31)) 192 | font = QtGui.QFont() 193 | font.setPointSize(18) 194 | font.setBold(True) 195 | font.setWeight(75) 196 | self.td_wind.setFont(font) 197 | self.td_wind.setStyleSheet("\n" 198 | "color: rgb(255, 255, 255);") 199 | self.td_wind.setObjectName("td_wind") 200 | self.widget = QtWidgets.QWidget(self.widget_4) 201 | self.widget.setGeometry(QtCore.QRect(10, 60, 400, 161)) 202 | self.widget.setObjectName("widget") 203 | self.td_temp = QtWidgets.QLabel(self.widget) 204 | self.td_temp.setGeometry(QtCore.QRect(110, 0, 180, 51)) 205 | font = QtGui.QFont() 206 | font.setFamily("文泉驿点阵正黑") 207 | font.setPointSize(38) 208 | font.setBold(True) 209 | font.setWeight(75) 210 | self.td_temp.setFont(font) 211 | self.td_temp.setStyleSheet("color: rgb(255, 255, 255);") 212 | self.td_temp.setObjectName("td_temp") 213 | self.today_weather = QtWidgets.QLabel(self.widget) 214 | self.today_weather.setGeometry(QtCore.QRect(110, 60, 181, 41)) 215 | font = QtGui.QFont() 216 | font.setPointSize(18) 217 | font.setBold(True) 218 | font.setWeight(75) 219 | self.today_weather.setFont(font) 220 | self.today_weather.setStyleSheet("color: rgb(255, 255, 255);\n" 221 | "style=\"text-align:center\"") 222 | self.today_weather.setObjectName("today_weather") 223 | self.today_wind_3 = QtWidgets.QLabel(self.widget) 224 | self.today_wind_3.setGeometry(QtCore.QRect(200, 160, 41, 31)) 225 | font = QtGui.QFont() 226 | font.setPointSize(12) 227 | font.setBold(True) 228 | font.setWeight(75) 229 | self.today_wind_3.setFont(font) 230 | self.today_wind_3.setStyleSheet("\n" 231 | "color: rgb(255, 255, 255);") 232 | self.today_wind_3.setObjectName("today_wind_3") 233 | self.today_weather_2 = QtWidgets.QLabel(self.widget) 234 | self.today_weather_2.setGeometry(QtCore.QRect(110, 110, 181, 41)) 235 | font = QtGui.QFont() 236 | font.setPointSize(15) 237 | font.setBold(True) 238 | font.setWeight(75) 239 | self.today_weather_2.setFont(font) 240 | self.today_weather_2.setStyleSheet("color: rgb(255, 255, 255);") 241 | self.today_weather_2.setObjectName("today_weather_2") 242 | self.sayhello = QtWidgets.QLabel(self.centralWidget) 243 | self.sayhello.setGeometry(QtCore.QRect(0, 600, 480, 71)) 244 | font = QtGui.QFont() 245 | font.setPointSize(25) 246 | font.setBold(True) 247 | font.setWeight(75) 248 | self.sayhello.setFont(font) 249 | self.sayhello.setStyleSheet("\n" 250 | "color: rgb(255, 255, 255);") 251 | self.sayhello.setObjectName("sayhello") 252 | MainWindow.setCentralWidget(self.centralWidget) 253 | self.menuBar = QtWidgets.QMenuBar(MainWindow) 254 | self.menuBar.setGeometry(QtCore.QRect(0, 0, 550, 25)) 255 | self.menuBar.setObjectName("menuBar") 256 | MainWindow.setMenuBar(self.menuBar) 257 | self.mainToolBar = QtWidgets.QToolBar(MainWindow) 258 | self.mainToolBar.setObjectName("mainToolBar") 259 | MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar) 260 | self.statusBar = QtWidgets.QStatusBar(MainWindow) 261 | self.statusBar.setObjectName("statusBar") 262 | MainWindow.setStatusBar(self.statusBar) 263 | 264 | self.widget_6 = QtWidgets.QWidget(self.centralWidget) 265 | self.widget_6.setGeometry(QtCore.QRect(340, 0, 201, 101)) 266 | self.widget_6.setObjectName("widget_6") 267 | self.houandmin = QtWidgets.QLabel(self.widget_6) 268 | self.houandmin.setGeometry(QtCore.QRect(0, 40, 150, 45)) 269 | font = QtGui.QFont() 270 | font.setPointSize(35) 271 | self.houandmin.setFont(font) 272 | self.houandmin.setStyleSheet("color: rgb(255, 255, 255);") 273 | self.houandmin.setObjectName("houandmin") 274 | self.second = QtWidgets.QLabel(self.widget_6) 275 | self.second.setGeometry(QtCore.QRect(115, 40, 31, 31)) 276 | font = QtGui.QFont() 277 | font.setPointSize(15) 278 | self.second.setFont(font) 279 | self.second.setStyleSheet("color: rgb(255, 255, 255);") 280 | self.second.setObjectName("second") 281 | 282 | self.clock = QtWidgets.QLabel() 283 | self.clock.setGeometry(QtCore.QRect(320, 20, 150, 100)) 284 | font = QtGui.QFont() 285 | font.setPointSize(12) 286 | font.setBold(True) 287 | font.setWeight(75) 288 | self.clock.setFont(font) 289 | self.clock.setStyleSheet("\n" 290 | "color: rgb(255, 255, 255);") 291 | self.clock.setObjectName("clock") 292 | 293 | self.retranslateUi(MainWindow) 294 | QtCore.QMetaObject.connectSlotsByName(MainWindow) 295 | 296 | def retranslateUi(self, MainWindow): 297 | _translate = QtCore.QCoreApplication.translate 298 | MainWindow.setWindowTitle(_translate("MainWindow", "MagicMirror")) 299 | self.label_day.setText(_translate("MainWindow", "LOADING.....")) 300 | self.label_9.setText(_translate("MainWindow", "-------------------------------------")) 301 | self.label_18.setText(_translate("MainWindow", "DATE TIME")) 302 | self.label_10.setText(_translate("MainWindow", "-----------------------------------------------------------")) 303 | self.label_19.setText(_translate("MainWindow", "WEATHER")) 304 | self.td.setText(_translate("MainWindow", "....")) 305 | self.dat.setText(_translate("MainWindow", "....")) 306 | self.tmr.setText(_translate("MainWindow", "....")) 307 | self.dat_weather.setText(_translate("MainWindow", "....")) 308 | self.tmr_weather.setText(_translate("MainWindow", "....")) 309 | self.td_weather.setText(_translate("MainWindow", "....")) 310 | self.tm_tmp.setText(_translate("MainWindow", "..°")) 311 | self.td_tmp.setText(_translate("MainWindow", "..°")) 312 | self.dat_tmp.setText(_translate("MainWindow", "..°")) 313 | self.dat_wind.setText(_translate("MainWindow", "........")) 314 | self.tm_wind.setText(_translate("MainWindow", "........")) 315 | self.td_wind.setText(_translate("MainWindow", "........")) 316 | self.td_temp.setText(_translate("MainWindow", " .. ")) 317 | self.today_weather.setText(_translate("MainWindow", "......")) 318 | self.today_wind_3.setText(_translate("MainWindow", "风力")) 319 | self.today_weather_2.setText(_translate("MainWindow", "。。。/。。。")) 320 | self.sayhello.setText(_translate("MainWindow", "LOADING....")) 321 | self.houandmin.setText(_translate("MainWindow", "12:50")) 322 | self.second.setText(_translate("MainWindow", "35")) 323 | 324 | def __init__(self): 325 | super(Ui_MainWindow, self).__init__() 326 | self.setupUi(self) 327 | self.retranslateUi(self) 328 | #aligncenter 329 | self.today_weather.setAlignment(QtCore.Qt.AlignCenter) 330 | self.td_temp.setAlignment(QtCore.Qt.AlignCenter) 331 | self.today_weather_2.setAlignment(QtCore.Qt.AlignCenter) 332 | self.sayhello.setAlignment(QtCore.Qt.AlignCenter) 333 | self.td_weather.setAlignment(QtCore.Qt.AlignCenter) 334 | self.tmr_weather.setAlignment(QtCore.Qt.AlignCenter) 335 | self.dat_weather.setAlignment(QtCore.Qt.AlignCenter) 336 | #timer 337 | self.update_info() 338 | self.update_second() 339 | self.update_sentence() 340 | 341 | def update_second(self): 342 | _translate = QtCore.QCoreApplication.translate 343 | hour_time, min_time, sec_time = getTime() 344 | ahead_time = hour_time + ':' + min_time 345 | self.second.setText(_translate("MainWindow",sec_time)) 346 | self.houandmin.setText(_translate("MainWindow",ahead_time)) 347 | timer2 = threading.Timer(1, self.update_second) 348 | timer2.start() 349 | 350 | def update_sentence(self): 351 | _translate = QtCore.QCoreApplication.translate 352 | sent = getSentence() 353 | self.sayhello.setText(_translate("MainWindow", sent)) 354 | timer3 = threading.Timer(5, self.update_sentence) 355 | timer3.start() 356 | 357 | def update_info(self): 358 | _translate = QtCore.QCoreApplication.translate 359 | # data weather 360 | # August 16, Wednesday 361 | weather_data = getWeather() 362 | now_tmp = " " + weather_data[-1] + "° " 363 | rangeoftemp = " " + weather_data[0][4] + "°/ " + weather_data[0][3] + "°" 364 | self.td_temp.setText(_translate("MainWindow", now_tmp)) 365 | self.today_weather.setText(_translate("MainWindow", weather_data[0][0])) 366 | self.today_weather_2.setText(_translate("MainWindow", rangeoftemp)) 367 | self.td.setText(_translate("MainWindow", weather_data[0][1][5:19])) 368 | self.tmr.setText(_translate("MainWindow", weather_data[1][1][5:19])) 369 | self.dat.setText(_translate("MainWindow", weather_data[2][1][5:19])) 370 | 371 | self.td_weather.setText(_translate("MainWindow", weather_data[0][0])) 372 | self.td_tmp.setText(_translate("MainWindow", weather_data[0][4] + "/" + weather_data[0][3] + "°")) 373 | self.td_wind.setText(_translate("MainWindow", weather_data[0][2] + "%")) 374 | 375 | self.tmr_weather.setText(_translate("MainWindow", weather_data[1][0])) 376 | self.tm_tmp.setText(_translate("MainWindow", weather_data[1][4] + "/" + weather_data[1][3] + "°")) 377 | self.tm_wind.setText(_translate("MainWindow", weather_data[1][2] + "%")) 378 | 379 | self.dat_weather.setText(_translate("MainWindow", weather_data[2][0])) 380 | self.dat_tmp.setText(_translate("MainWindow", weather_data[2][4] + "/" + weather_data[2][3] + "°")) 381 | self.dat_wind.setText(_translate("MainWindow", weather_data[2][2] + "%")) 382 | 383 | day_information = getDate() 384 | self.label_day.setText(_translate("MainWindow", day_information)) 385 | 386 | timer1 = threading.Timer(14400,self.update_info) 387 | timer1.start() 388 | 389 | if __name__ == "__main__": 390 | app = QtWidgets.QApplication(sys.argv) 391 | win = Ui_MainWindow() 392 | win.show() 393 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /mainProjct/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 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 | 57 | 58 | 59 | 60 | td_wind 61 | tm_tmp 62 | dat_tmp 63 | dat_wind 64 | tmr_weather 65 | tmr_weat 66 | label_18 67 | label_10 68 | label_9 69 | widget_5 70 | clo 71 | clock 72 | widget_6 73 | second 74 | label_day 75 | widget_3 76 | houandmin 77 | dat_weather 78 | sayhello 79 | MainWindow 80 | 81 | 82 | 83 | 100 | 101 | 102 | 103 | 104 | true 105 | DEFINITION_ORDER 106 | 107 | 108 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 135 | 136 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 162 | 163 | 164 | 165 | 183 | 184 | 202 | 203 | 221 | 222 | 240 | 241 | 259 | 260 | 278 | 279 | 291 | 292 | 311 | 312 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 347 | 348 | 349 | 350 | 1502855357552 351 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 384 | 385 | 387 | 388 | 389 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | --------------------------------------------------------------------------------