[highwind] --- conky

仅供存放个人的配置文件,不要在本版发问。
回复
头像
highwind
帖子: 1362
注册时间: 2008-09-05 23:31
系统: LinuxMint17
送出感谢: 35 次
接收感谢: 10 次

[highwind] --- conky

#1

帖子 highwind » 2014-03-09 22:06

代码: 全选

# Conky settings #
background yes
update_interval 1
double_buffer yes
no_buffers yes
imlib_cache_size 10

# Window specifications #
gap_x 50
gap_y 30
minimum_size 256 5
maximum_width 256
own_window yes
own_window_type dock  # other options are: override/normal/desktop/panel
own_window_transparent yes
own_window_colour FFFFFF
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
border_inner_margin 0
border_outer_margin 0
#alignment middle_middle
own_window_argb_visual yes
own_window_argb_value 0

# Graphics settings #
draw_shades no
default_shade_color AAAAAA
draw_outline no
default_outline_color AAAAAA
draw_borders no
draw_graph_borders no
default_graph_size 26 80
show_graph_scale no
show_graph_range no

# Text settings #
use_xft yes
xftalpha 0
xftfont Droid Sans:size=10
text_buffer_size 256
override_utf8_locale yes

# Useful shortenings #
short_units yes
pad_percents 2
top_name_width 7

# Color scheme #
default_color FFFFFF
color1 FFA500
color2 FFFFFF
color3 87CEEB

TEXT
\

# Clock + calendar #
${font Droid Sans Mono :size=32}${color1}${alignc}${time %H:%M}${color}${font}
${font Droid Sans :size=12}${color2}${alignc}${time %A, %F}${color}${font}
${font Droid Sans :size=8}${color2}${alignc}${nodename}(${machine})___${kernel}${color}${font}
\
# Note #
${hr 3}
${voffset 6}${font size=10}${color1}${alignc}Note:${color}${font}
${font WenQuanYi Zen Hei:size=12}${color3}${execp cat /home/highwind/Documents/.ToDoList.txt | sed 's#^#${goto 16}#'}${color}${font}

${hr 3}
\

# Cpu, memory, processes, swap info and load graph 利用voffset整合了文字和图形,但是随之而来的是背景的下移,暂时隐去背景折衷#
${goto 16}${color2}${cpubar cpu0 25,224}
${voffset -35}${goto 20}${color1}${font DejaVu Sans Mono:size=15}CPU${font}${goto 200}${voffset -3}${font DejaVu Sans Mono:size=12}${cpu cpu0}%${font}
${voffset 5}${goto 36}${color2}Name${goto 118}CPU${goto 198}MEM${color}
${goto 36}${top name 1}${goto 112}${top cpu 1}${goto 192}${top mem 1}
${goto 36}${top name 2}${goto 112}${top cpu 2}${goto 192}${top mem 2}
${goto 36}${top name 3}${goto 112}${top cpu 3}${goto 192}${top mem 3}${font}${color}

${goto 16}${color2}${membar 25,224}
${voffset -35}${goto 20}${color1}${font DejaVu Sans Mono:size=15}MEM${font}${goto 200}${voffset -3}${font DejaVu Sans Mono:size=12}${memperc}%${font}
${voffset 5}${goto 36}${color2}Name${goto 118}CPU${goto 198}MEM${color}
${goto 36}${top_mem name 1}${goto 112}${top_mem cpu 1}${goto 192}${top_mem mem 1}
${goto 36}${top_mem name 2}${goto 112}${top_mem cpu 2}${goto 192}${top_mem mem 2}
${goto 36}${top_mem name 3}${goto 112}${top_mem cpu 3}${goto 192}${top_mem mem 3}${font}${color}
\

# The network section #
${goto 20}${color1}Up:${color}${color2}${goto 80}${upspeed wlan0}${color1}${goto 140}Down:${color}${color2}${goto 200}${downspeed wlan0}${color}
${goto 16}${color3}${upspeedgraph wlan0 18,100}${goto 140}${downspeedgraph wlan0 18,100}${color}
${goto 20}${color1}Sent:${color2}${goto 80}${totalup wlan0}${color1}${goto 140}Received: ${color2}${goto 200}${totaldown wlan0}${color}

代码: 全选

${execp cat /home/highwind/Documents/.ToDoList.txt | sed 's#^#${goto 16}#'} 
详解:viewtopic.php?f=94&t=456297
头像
highwind
帖子: 1362
注册时间: 2008-09-05 23:31
系统: LinuxMint17
送出感谢: 35 次
接收感谢: 10 次

Re: [highwind] --- conky

#2

帖子 highwind » 2014-03-11 10:15

cat还是改用nl比较合适,这样就自动列表了。 :em06
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
送出感谢: 8 次
接收感谢: 63 次
联系:

Re: [highwind] --- conky

#3

帖子 月下叹逍遥 » 2014-03-11 10:59

:em11
心似浮云常自在,意如流水任东西。
此事背后一定有个天大的咪咪
广告:
1、走过路过,不要错过,dropbox网盘2.25G大放送
py大法好,退C保平安
java多妖孽,VB本异端
日诵一千遍,快活似神仙
jinjiachen
帖子: 2095
注册时间: 2012-12-16 15:43
系统: debian
送出感谢: 9 次
接收感谢: 27 次

Re: [highwind] --- conky

#4

帖子 jinjiachen » 2014-03-11 11:04

:em09
头像
highwind
帖子: 1362
注册时间: 2008-09-05 23:31
系统: LinuxMint17
送出感谢: 35 次
接收感谢: 10 次

Re: [highwind] --- conky

#5

帖子 highwind » 2014-04-23 1:57

代码: 全选

#!/usr/bin/env python3
import urllib.request
from lxml.cssselect import CSSSelector as CSS
import lxml.html

#输入想显示的城市名称和雅虎天气的URL地址
City1 = {'name':'深圳',
         'url':"https://weather.yahoo.com/china/guangdong/shenzhen-2161853/"
        }


class City:
    def __init__(self,city):
        self.name=city['name']
        self.url=city['url']
        self.FOREDAY = 5
        return

# 导入地址并下载网页存入本地
    def FILE(self):
        self.html_page = urllib.request.urlopen(self.url).read()
        self.file_name = '~/.conky/'+self.name+'_weather.log'
        file = open(self.file_name, 'wb')
        file.write(self.html_page)
        file.close()
        return

    def TREE(self):
        self.FILE()
        self.tree=lxml.html.parse(self.file_name)
        return

    def NOW_INFO(self):
        self.TREE()
        sel_now_cond = CSS("div#lead-bd div.cond")    #
        self.now_cond = sel_now_cond(self.tree)[0].text

        sel_now_temp_cur = CSS("span.c span.num")
        self.now_temp_cur = sel_now_temp_cur(self.tree)[0].text + "°C"

        sel_now_temp_hi = CSS("span.hi-lo span.hi.c")
        self.now_temp_hi = sel_now_temp_hi(self.tree)[0].text + "C"

        sel_now_temp_lo = CSS("span.hi-lo span.lo.c")
        self.now_temp_lo = sel_now_temp_lo(self.tree)[0].text + "C"

        return

    def FORE_INFO(self):
        self.TREE()

        sel_fore_day = CSS("ul.forecast li.condition span.name")
        elem_fore_day = sel_fore_day(self.tree)
        self.fore_day = []

        sel_fore_cond = CSS("ul.forecast li.condition")
        elem_fore_cond = sel_fore_cond(self.tree)
        self.fore_cond_day = []

        sel_fore_temp_hi = CSS("ul.forecast li.condition span.temperature span.hi-c")
        elem_fore_temp_hi = sel_fore_temp_hi(self.tree)
        self.fore_temp_hi_day = []

        sel_fore_temp_lo = CSS("ul.forecast li.condition span.temperature span.lo-c")
        elem_fore_temp_lo = sel_fore_temp_lo(self.tree)
        self.fore_temp_lo_day = []

        for n in range(self.FOREDAY):
            # 赋值日期
            self.fore_day.append(elem_fore_day[n].text)
            # 赋值天气情况
            e = elem_fore_cond[n].get('class')
            if e.startswith("condition wc-"):
                if (e.endswith("-d ") or e.endswith("-n ")): #注意空格啊!
                    self.fore_cond_day.append(e[13:-3])
                else:
                    self.fore_cond_day.append(e[13:])
            else:
                pass
            # 赋值最高气温
            self.fore_temp_hi_day.append(elem_fore_temp_hi[n].text + "C")
            # 赋值最低气温
            self.fore_temp_lo_day.append(elem_fore_temp_lo[n].text + "C")
        return

    def PRINT_INFO(self):
        self.NOW_INFO()
        self.FORE_INFO()

        print("{0:10}{1:25}".format("Today:", self.now_cond))
        print("{0}  <<<{1}>>>  {2}".format(self.now_temp_lo.rjust(8), self.now_temp_cur.center(8), self.now_temp_hi.ljust(8)))
        for m in range(1,self.FOREDAY):
            print("{0:10}{1:25}".format(self.fore_day[m], self.fore_cond_day[m]))
            print("{0}{1}".format(self.fore_temp_hi_day[m].rjust(28), self.fore_temp_lo_day[m].rjust(5)))
        return

C1 = City(City1)
C1.PRINT_INFO()

# End of the Program
上次由 highwind 在 2014-04-23 4:09,总共编辑 2 次。
头像
highwind
帖子: 1362
注册时间: 2008-09-05 23:31
系统: LinuxMint17
送出感谢: 35 次
接收感谢: 10 次

Re: [highwind] --- conky

#6

帖子 highwind » 2014-04-23 2:05

代码: 全选

TEXT
# Time + Weather 1#
${color4}中国-深圳${color}
${color2}${hr 2}${color}
# Time section #
${font Droid Sans Mono :size=10}${color1}${exec TZ='Asia/Shanghai' date +'PRC(%:::z) %A'}${color}${font}
${font Droid Sans Mono :size=12}${color1}${goto 40}${exec TZ='Asia/Shanghai' date +'%F %H:%M'}${color}${font}
# Weather section #
${font Droid Sans Mono :size=9}${color1}${execpi 3600 python3 ~/.conky/Weather.py}${color}${font}
最近琢磨了下所谓面向对象的编程方法,楼上的那些代码就是Weather.py(简单的小爬虫,复习加练习),也不知道是不是这样(大大有路过的给指点指点)。
这样就总算阶段性搞出个同时显示时间和天气的东西来了。本来想做成applet,可是不懂JS呀,没办法,python+conky吧。 :em06
头像
highwind
帖子: 1362
注册时间: 2008-09-05 23:31
系统: LinuxMint17
送出感谢: 35 次
接收感谢: 10 次

Re: [highwind] --- conky

#7

帖子 highwind » 2014-04-28 10:44

代码: 全选

${if_match ${desktop}==2}${font WenQuanYi Zen Hei:size=10}${color4}${execp cat ~/.conky/ToDoList2.txt | sed 's#^#${goto 0}#'}${color}${font}
${else}${font WenQuanYi Zen Hei:size=10}${color4}${execp cat ~/.conky/ToDoList1.txt | sed 's#^#${goto 0}#'}${color}${font}
${endif}
这一段搭配if_match和desktop(不知道为何desktop_name/_number不是很好用)[老样子使用wmctrl -d查看,不过好像得加1]在不同工作区选择性执行不同的条目。

另,更多详情见
conky.sourceforge.net/variables.html
头像
highwind
帖子: 1362
注册时间: 2008-09-05 23:31
系统: LinuxMint17
送出感谢: 35 次
接收感谢: 10 次

Re: [highwind] --- conky

#8

帖子 highwind » 2014-07-31 11:58

利用conky内置的函数,大部分可实现世界时钟和天气预报(简单需求不再需要脚本了):

代码: 全选

${font DejaVu San Mono: size=22: style=bold}${tztime US/Eastern %T}${font}
${goto 2}Atlanta${goto 80}${tztime US/Eastern %F}
${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ KPDK temperature 30}°C${goto 80}${execi 3600 curl -s http://weather.noaa.gov/pub/data/observations/metar/decoded/KPDK.TXT | sed -n 5p | sed -e 's/Sky conditions: //'}
Updated at:${goto 80}${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ KPDK last_update 30}

${font DejaVu San Mono: size=22: style=bold}${tztime Asia/Shanghai %T}${font}
${goto 2}Shenzhen${goto 80}${tztime Asia/Shanghai %F}
${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ ZGSZ temperature 30}°C${goto 80}${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ ZGSZ cloud_cover 30}
Updated at:${goto 80}${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ ZGSZ last_update 30}
回复

回到 “个人配置文件存放点”