#encoding: utf-8

importpygameimporttimeimportweatherAPIimportSystemInfofrom datetime importdatetime#显示图片函数

defShowPicture(picturepath,x0,y0):

background=pygame.image.load(picturepath)

background.convert_alpha()

window.blit(background,(x0,y0))return

defShowCircle():

pygame.draw.circle(window,pygame.Color(255,255,255),(width/2,height/2),radius,fill)return

#划线函数,起始坐标,终点坐标

defShowLine(x0,y0,x1,y1):

pygame.draw.line(window,pygame.Color(255,255,255),(x0,y0),(x1,y1),fill)returnYellow=(255,255,0)

Red=(255,0,0)

LightBlue=(190,190,255)

Green=(0,255,0)

Black=(0,0,0)

White=(255,255,255)#画框函数

defShowRec(x0,y0,x1,y1,color,fill):

pygame.draw.rect(window,color,(x0,y0,x1,y1),fill)return

#字符串显示函数

defShowStr(mystring,x0,y0,size):

font=pygame.font.Font('gkai00mp.ttf',size,bold=1)

textSuface=font.render(mystring,1,pygame.Color(255,255,255))

window.blit(textSuface,(x0,y0))return

defShowStr2(mystring,x0,y0,size):

font=pygame.font.Font('gkai00mp.ttf',size,bold=1)

textSuface=font.render(mystring,1,pygame.Color(255,255,0))

window.blit(textSuface,(x0,y0))return

defShowStr3(mystring,x0,y0,size):

font=pygame.font.Font('gkai00mp.ttf',size,bold=1)

textSuface=font.render(mystring,1,pygame.Color(0,255,0))

window.blit(textSuface,(x0,y0))return

#背景参数设置

width=1280height=800fill=1

#初始化背景

pygame.init()

window=pygame.display.set_mode((width,height),pygame.FULLSCREEN)#全屏#window=pygame.display.set_mode((width,height))#不全屏

window.fill(pygame.Color(0,0,0))#back=pygame.image.load(r"/home/pi/ccj/c.jpg") #图片位置

loop=0

last_ip= ip = ''updatingtime=""Title_X=width

WeatherValidation=FalsewhileTrue:#window.blit(back,(0,0)) #对齐的坐标

window.fill(pygame.Color(0,0,0)) #背景色0为黑

#ShowPicture("a_3.gif",20,450)

#draw grids

#ShowStr(u"时间",10,20,80)

ShowRec(10,10,width-20,height-80,White,1) #画一个大框

ShowLine(10,height/5,width-10,height/5)

ShowLine(10,height/5*3,width-10,height/5*3)

ShowLine(width/2,height/5,width/2,height-70)

ShowLine(width/4,height/5*3,width/4,height-70)

ShowLine(width/4*3,height/5*3,width/4*3,height-70)#time show

mylocaltime=time.localtime()

myclock=time.strftime("%H:%M:%S",mylocaltime)#13:15:03 2017-04-21

ShowStr(myclock,0,0,180)

mydate=time.strftime("%Y-%m-%d",mylocaltime)#2017-04-21

ShowStr(mydate,810,5,90)

mytime=time.strftime("%A",mylocaltime)#Thursday

ShowStr(mytime,830,90,85)

name= "自动化实验室欢迎您"ShowStr2(name,width/2+10,height/5*2-140,52)

ip= SystemInfo.get_ip('wlan0')#ip = SystemInfo.get_ip('eth0')

cpu_usage =SystemInfo.getCPUuse()

ShowStr(ip,width/2+100,height/5*2-90,48)

ShowStr("ip:",width/2+10,height/5*2-90,52)#netspeed show

NetInfoOld=SystemInfo.net_stat()

time.sleep(1)

NetInfoNew=SystemInfo.net_stat()

DownloadSpeed=(NetInfoNew[0]["ReceiveBytes"]-NetInfoOld[0]["ReceiveBytes"])/1048576 #last second total flow -current second total flow

UploadSpeed=(NetInfoNew[0]["TransmitBytes"]-NetInfoOld[0]["TransmitBytes"])/1048576ShowRec(width/2+20,height/5*2-40,DownloadSpeed/10*600+20,48,Green,0)

ShowRec(width/2+20,height/5*2+10,UploadSpeed/10*600+20,48,LightBlue,0)

ShowStr("↓:"+str("%3.2f"%(DownloadSpeed))+"MB/s",width/2+20,height/5*2-40,48)

ShowStr("↑:"+str("%3.2f"%(UploadSpeed))+"MB/s",width/2+20,height/5*2+10,48)#cpu_usage show

ShowRec(width/2+20,height/5*2+60,cpu_usage/100*600+60,48,Yellow,0)

ShowStr("CPU usage:"+str("%2d"%cpu_usage)+"%",width/2+20,height/5*2+110,48)if loop % 60==0 :

future= datetime.strptime('2019-1-1 00:00:00','%Y-%m-%d %H:%M:%S')#当前时间

now =datetime.now()#求时间差

delta = future -now

hour= delta.seconds/60/60minute= delta.seconds/60seconds= delta.seconds - hour*60*60 - minute*60

#print_now=now.strftime('%Y-%m-%d %H:%M:%S')

#print("今天是:",print_now)

#print("距离 2019-02-01 \"work\" 还剩下:%d天"%delta.days)

#print(delta.days,hour, minute, seconds)

ShowStr2("倒计时:%dH (%dMin)"%(hour,minute),width/4*2+width/32+20,height/5*3+height/30+235,45)##########################本地信息获取完成#######################################

#print ("↓:"+str("%3.1f"%(DownloadSpeed))+"MB/s")

#print ("↑:"+str("%3.1f"%(UploadSpeed))+"MB/s")

#print("CPU usage:"+str("%2d"%cpu_usage)+"%")

#########weather show####################################

if loop % 10800==0 : #update per 3 hours

jsonArr=weatherAPI.GetWeatherInfo()if jsonArr!=None : #记录请求数据时间

updatingtime=time.strftime("%H:%M:%S",mylocaltime)if jsonArr["status"]!="1":print (jsonArr["msg"])

WeatherValidation=Falseelse:

result=jsonArr["forecasts"][0]

WeatherValidation=True#print (result["city"],result["weather"],result["temp"],result["temphigh"],result["templow"])

if WeatherValidation==True:#AQI=result["aqi"]

#index=result["index"]

#index0=index[0]

#daily=result["daily"]

#day1=daily[1]#明天天气预报

#day2=daily[2]#明天天气预报

#day3=daily[3]#明天天气预报

#day4=daily[4]#明天天气预报

### #室外温湿度

#ShowPicture("pictures/"+result["img"]+".png",width/16,height/5+150)

ShowStr("武汉市",width/32,height/5+10,60)

ShowStr(result["city"],width/32,height/5+80,60)

ShowStr(result["casts"][0]["dayweather"],width/32-25,height/5*2+50,120)

ShowStr(result["casts"][0]["daytemp"]+"℃",width/4,height/5,160)

ShowStr("气温最低:"+result["casts"][0]["nighttemp"] +"℃",width/4-10,height/5*2-20,48)

ShowStr("接下来转:"+result["casts"][0]["nightweather"],width/4-10,height/5*2+50,48)#ShowStr("zhesgii",width/2+20,height/5+10,120)

ShowStr("风力:"+result["casts"][0]["daypower"]+"级",width/4-10,height/5*2+110,48)### #空气质量

#ShowStr("PM2.5:",width/2+280,height/5+120,32)

#ShowStr(AQI["pm2_5"],width/2+400,height/5-20,200)

#ShowStr("空气质量:"+AQI["quality"],width/2+240,height/5*2-40,32)

ShowPicture("pictures/"+result["casts"][0]["dayweather"]+".png",width/32+60,height/5+145)#if Title_X<=-100:

#Title_X=width

#else:

#Title_X=Title_X-40

#ShowStr(index0["detail"],Title_X,height-50,40)

##未来几天天气预报

ShowStr("明天:"+result["casts"][1]["date"],width/32,height/5*3+height/30-10,30)

ShowStr(result["casts"][1]["dayweather"],width/32,height/5*3+height/30+30,50)

ShowStr(result["casts"][2]["daytemp"]+"℃",width/32,height/5*3+height/30+80,70)

ShowStr("气温Min:"+result["casts"][1]["nighttemp"] +"℃",width/32-10,height/5*3+height/30+140,45)

ShowStr("未来转:"+result["casts"][1]["nightweather"],width/32-10,height/5*3+height/30+180,45)

ShowPicture("pictures/"+result["casts"][1]["dayweather"]+".png",width/32+170,height/5*3+height/30+45)#ShowPicture("pictures/"+day1["day"]["img"]+".png",width/32,height/5*3+height/10)

###

ShowStr("后天:"+result["casts"][2]["date"],width/4+width/32,height/5*3+height/30-10,30)

ShowStr(result["casts"][2]["dayweather"],width/4+width/32,height/5*3+height/30+30,50)

ShowStr(result["casts"][2]["daytemp"]+"℃",width/4+width/32,height/5*3+height/30+80,70)

ShowStr("气温Min:"+result["casts"][2]["nighttemp"] +"℃",width/4+width/32-10,height/5*3+height/30+140,45)

ShowStr("未来转:"+result["casts"][2]["nightweather"],width/4+width/32-10,height/5*3+height/30+180,45)

ShowPicture("pictures/"+result["casts"][2]["dayweather"]+".png",width/4+width/32+170,height/5*3+height/30+45)#ShowStr(day2["day"]["weather"],width/4+width/32,height/5*3+height/5-40,100)

#ShowStr(day2["day"]["windpower"],width/4+width/32+70,height/5*3+height/10,64)

#ShowStr(day2["night"]["templow"]+"~"+day2["day"]["temphigh"]+"℃",width/4+width/32,height-130,64)

#ShowPicture("pictures/"+day2["day"]["img"]+".png",width/4+width/32,height/5*3+height/10)

###

ShowStr("大后天:"+result["casts"][3]["date"],width/4*2+width/32-25,height/5*3+height/30-10,30)

ShowStr(result["casts"][3]["dayweather"],width/4*2+width/32-25,height/5*3+height/30+30,50)

ShowStr(result["casts"][3]["daytemp"]+"℃",width/4*2+width/32-25,height/5*3+height/30+80,70)

ShowStr("气温Min:"+result["casts"][3]["nighttemp"] +"℃",width/4*2+width/32-25,height/5*3+height/30+140,45)

ShowStr("未来转:"+result["casts"][3]["nightweather"],width/4*2+width/32-25,height/5*3+height/30+180,45)

ShowPicture("pictures/"+result["casts"][3]["dayweather"]+".png",width/4*2+width/32-25+170,height/5*3+height/30+45)#ShowStr(day3["day"]["weather"],width/4*2+width/32,height/5*3+height/5-40,100)

#ShowStr(day3["day"]["windpower"],width/4*2+width/32+70,height/5*3+height/10,64)

#ShowStr(day3["night"]["templow"]+"~"+day2["day"]["temphigh"]+"℃",width/4*2+width/32,height-130,64)

#ShowPicture("pictures/"+day3["day"]["img"]+".png",width/4*2+width/32,height/5*3+height/10)

###

ShowPicture("pictures/cj.png",width/4*3+width/32,height/5*3+height/30-15)#ShowStr(day4["day"]["weather"],width/4*3+width/32,height/5*3+height/5-40,100)

#ShowStr(day4["day"]["windpower"],width/4*3+width/32+70,height/5*3+height/10,64)

#ShowStr(day4["night"]["templow"]+"~"+day2["day"]["temphigh"]+"℃",width/4*3+width/32,height-130,64)

#ShowPicture("pictures/"+day4["day"]["img"]+".png",width/4*3+width/32,height/5*3+height/10)

##记录请求数据时间

ShowStr3("Last update:"+updatingtime,width/4*3+15,height/5*3,30)

ShowStr2("这里是滚动字幕显示区,加循环可实现动态效果",width/32-25,height/5*3+height/30+235,45)#update

pygame.display.update()

loop+=1

#全屏

#for event in pygame.event.get():

#if event.type==pygame.KEYDOWN:

#running=False

pygame.quit()

python 天气预报地图_在树莓派上用 python 做一个炫酷的天气预报相关推荐

  1. python实现动态壁纸_流弊了!竟然用Python做一个炫酷的小姐姐动态壁纸

    原标题:流弊了!竟然用Python做一个炫酷的小姐姐动态壁纸 公众号关注 " 菜鸟学Python" 设为 "星标",每天带你玩转Python! (女神IU,图片 ...

  2. 在树莓派上进行python编程_在树莓派上用Python控制LED

    所需材料 一个已经安装配置好了的树莓派 连接控制树莓派所用的其他必须设备 200Ω电阻 x 8 led x 8 面包板及连接线若干 电路连接 电路图 按照电路图所示,在面包板上进行连接. 编写程序 安 ...

  3. 树莓派能直接运行python程序_在树莓派上运行python脚本 - python

    我正在研究rapiberry pi 3大约3个月,开始使用它时遇到了问题. 我找不到在树莓派打开时在其上运行python脚本的有效,安全的方法(没有监视器,鼠标和键盘).此刻,我在/ etc / pr ...

  4. 树莓派实验室python人脸识别_在树莓派上实现人脸识别

    原标题:在树莓派上实现人脸识别 本文为 AI 研习社编译的技术博客,原标题 Facial Recognition & Identification On Raspberry Pi,作者为 Ad ...

  5. python oled库_在树莓派上使用 SSD1306 OLED 屏幕

    树莓派在许多使用场景下并不需要接一台专用显示器,如需要查看树莓派上的一些信息可以通过手机.电脑登录到树莓派上操作,但总归不够便利. 下面介绍两款 OLED 小屏(均为 SSD1306 芯片驱动)可以直 ...

  6. 流弊了!竟然用Python做一个炫酷的小姐姐动态壁纸!

    (女神IU,图片来自网络) 最近小编在浏览网页的时候,发现一个网页的背景是动态显示的,非常的炫酷.正好小编最近犯花痴,心仪的女神是韩国的小美女IU, 清纯可爱的小姐姐--关键中文歌还唱的很好. 于是码 ...

  7. 像360悬浮窗那样,用WindowManager做一个炫酷的悬浮迷你音乐盒(上)

    *本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 记得上一篇讲的是用RotateDrawable实现网易云音乐唱片机效果,而今天我要讲的是如何用WindowManager去实现一个 ...

  8. python 天气预报地图_实现地图天气预报的显示

    概述:很多时候,会用到地图与天气预报的相结合显示,本文结合web天气插件,实现地图天气预报的结合现实. 1.天气预报插件 搜了半天,终于找到了比较好的天气预报插件,网址为:http://www.tia ...

  9. python控制电机_利用树莓派控制步进电机——Python语言

    步进电机的优点在于它能够被精确定位,正向或反向一次性转动"一步",并且也能够连续转动. #!/usr/bin/env python ######################## ...

最新文章

  1. 牛X,试用了下 GitHub 上 2 万 Star 的第一抢票神器,3 秒钟抢到!
  2. java错误代码1061_java.sql.SQLException
  3. 四十二、文件的物理结构(下)
  4. iframe的sandbox使用
  5. 阿里P7工作总结:Spring MVC的工作原理,看完受益匪浅
  6. 遇到虚拟系统内存问题怎么办?Hypervisor帮你除bug
  7. 【C#】特性标签中的属性解释
  8. 搭建nfs共享存储服务之一nfs服务端搭建
  9. 爬虫 spider05——使用httpclient发送get请求、post请求
  10. 利用VOIP电话通信服务,他骗得18亿美元
  11. ubuntu下vscode使用cmake编译运行c++配置文件
  12. 计算机组成原理笔记第十章笔记整理
  13. 微课|Python快速判断垃圾邮件
  14. Vnc安装rhel6服务器
  15. 记录一下安装eclipse中的windows-builder组件时的一些问题
  16. Spring tool suite4 安装及配置
  17. APS生产计划排程(Production Planning and Scheduling)
  18. 英语魔法师之语法俱乐部 | 笔记2 | 初级句型—简单句 | Chapter1—基本句型及补语
  19. 蓝桥杯练习------python字符串逆序
  20. How to Backdoor Federated Learning

热门文章

  1. 已经发车的票还能取出来吗_高铁票在车已经开了,但我没上车也没有取票的情况下,还能取出票吗?...
  2. php 连接 mysql主从_php 连接主从数据库
  3. 服务器系统怎么分配,服务器系统盘分配多大内存
  4. solr 查询字段唯一值_《Solr实战》之一
  5. 卸载pytorch_Pytorch中的hook的使用详解
  6. 下载kolla_Kolla部署实验手册
  7. 基于Nexys4 DDR的弹球游戏实现
  8. java 调用tomcat api,Tomcat采用双向认证https协议通过JavaAPI调用(一)配置SSL
  9. manjaro双系统 windows_Win10和Manjaro双系统安装记录
  10. 有趣的php实例,8个必备的PHP功能实例代码