Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mikes zhang
001
提交
b0a27ca9
0
001
项目概览
mikes zhang
/
001
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
0
001
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
b0a27ca9
编写于
12月 01, 2018
作者:
J
Jim Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
got first pass at thermometer working
上级
7f03af25
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
162 addition
and
0 deletion
+162
-0
jima-rpi/thermometer.py
jima-rpi/thermometer.py
+162
-0
未找到文件。
jima-rpi/thermometer.py
0 → 100755
浏览文件 @
b0a27ca9
#!/usr/bin/env python3
import
argparse
import
datetime
import
json
import
logging
import
os
import
tkinter
as
tk
import
urllib.request
class
Application
(
tk
.
Frame
):
def
__init__
(
self
):
self
.
parse_command_line
()
logger
.
warning
(
"In init"
)
root
=
tk
.
Tk
()
root
.
iconify
()
root
.
configure
(
background
=
"black"
)
# root.overrideredirect(True)
root
.
geometry
(
"{0}x{1}+0+0"
.
format
(
root
.
winfo_screenwidth
(),
root
.
winfo_screenheight
()))
toplevel
=
tk
.
Toplevel
(
root
)
toplevel
.
configure
(
background
=
"black"
)
toplevel
.
overrideredirect
(
1
)
# Remove border
self
.
frame
=
tk
.
Frame
(
toplevel
)
self
.
frame
.
configure
(
background
=
"black"
)
# JHA TODO move this info parser?
if
self
.
create_close
:
close
=
tk
.
Button
(
self
.
frame
,
text
=
"Close Window"
,
command
=
lambda
:
root
.
destroy
()
)
close
.
pack
(
fill
=
tk
.
BOTH
,
expand
=
1
)
big_font
=
(
"Times"
,
"96"
,
"bold"
)
med_font
=
(
"Times"
,
"64"
,
"bold"
)
self
.
time
=
tk
.
Text
(
self
.
frame
,
height
=
1
,
width
=
10
,
font
=
big_font
,
bg
=
"black"
,
fg
=
"grey"
,
borderwidth
=
0
,
highlightthickness
=
0
,
)
self
.
temp
=
tk
.
Text
(
self
.
frame
,
height
=
1
,
width
=
15
,
font
=
med_font
,
bg
=
"black"
,
fg
=
"grey"
,
borderwidth
=
0
,
highlightthickness
=
0
,
)
self
.
blank
=
tk
.
Text
(
self
.
frame
,
height
=
1
,
width
=
10
,
font
=
big_font
,
bg
=
"black"
,
fg
=
"grey"
,
borderwidth
=
0
,
highlightthickness
=
0
,
)
self
.
time
.
pack
()
self
.
temp
.
pack
()
self
.
blank
.
pack
()
self
.
frame
.
pack
()
self
.
update_temp
()
self
.
update_time
()
self
.
frame
.
mainloop
()
def
update_time
(
self
):
time_str
=
datetime
.
datetime
.
now
().
strftime
(
"%I:%M"
)
self
.
time
.
delete
(
"1.0"
,
tk
.
END
)
self
.
time
.
insert
(
tk
.
END
,
time_str
)
self
.
frame
.
after
(
1000
,
self
.
update_time
)
def
update_temp
(
self
):
response
=
urllib
.
request
.
urlopen
(
self
.
url
)
json_string
=
response
.
read
()
response
.
close
()
parsed_json
=
json
.
loads
(
json_string
.
decode
(
"utf-8"
))
temp_f
=
parsed_json
[
"current_observation"
][
"temp_f"
]
wind
=
parsed_json
[
"current_observation"
][
"wind_mph"
]
temp_str
=
"{0}F"
.
format
(
temp_f
)
if
wind
>
30
:
temp_str
+=
" Very"
if
wind
>
10
:
temp_str
+=
" Windy!"
self
.
temp
.
delete
(
"1.0"
,
tk
.
END
)
self
.
temp
.
insert
(
tk
.
END
,
temp_str
)
self
.
frame
.
after
(
30000
,
self
.
update_temp
)
def
parse_command_line
(
self
):
""" Manage command line options """
parser
=
argparse
.
ArgumentParser
(
description
=
"Thermometer Script"
)
parser
.
add_argument
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
help
=
"print debug output while processing"
,
)
parser
.
add_argument
(
"-z"
,
"--zipcode"
,
action
=
"store"
,
default
=
os
.
environ
.
get
(
"ZIPCODE"
,
None
),
help
=
"zipcode of weather report "
"(env var: 'ZIPCODE')"
,
)
parser
.
add_argument
(
"-k"
,
"--key"
,
action
=
"store"
,
default
=
os
.
environ
.
get
(
"TEMPERATURE_KEY"
,
None
),
help
=
"wunderground key "
"(env var: 'TEMPERATURE_KEY')"
,
)
parser
.
add_argument
(
"-b"
,
"--button"
,
action
=
"store_true"
,
help
=
"create a close button for testing"
,
)
args
=
parser
.
parse_args
()
if
not
args
.
zipcode
or
not
args
.
key
:
exit
(
parser
.
print_help
())
self
.
create_close
=
args
.
button
self
.
url
=
(
"http://api.wunderground.com/api/{0}/conditions/q/"
"{1}.json"
.
format
(
args
.
key
,
args
.
zipcode
)
)
# Create handlers
if
args
.
verbose
:
c_handler
=
logging
.
StreamHandler
()
c_handler
.
setLevel
(
logging
.
WARNING
)
c_format
=
logging
.
Formatter
(
"%(name)s - %(levelname)s"
" - %(message)s"
)
c_handler
.
setFormatter
(
c_format
)
logger
.
addHandler
(
c_handler
)
f_handler
=
logging
.
FileHandler
(
"temperature.log"
)
f_handler
.
setLevel
(
logging
.
ERROR
)
f_format
=
logging
.
Formatter
(
"%(asctime)s - %(name)s - %(levelname)s"
" - %(message)s"
)
f_handler
.
setFormatter
(
f_format
)
logger
.
addHandler
(
f_handler
)
logger
.
warning
(
"Configured to read temperature from:"
)
logger
.
warning
(
self
.
url
)
return
args
if
__name__
==
"__main__"
:
# Create a global logger
logger
=
logging
.
getLogger
(
__name__
)
app
=
Application
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录