Skip to content

Commit

Permalink
分组展示阳历、农历;农历只1901至2050年;结果可保存至剪切板
Browse files Browse the repository at this point in the history
  • Loading branch information
imwr committed Sep 7, 2016
1 parent 6692f98 commit 3e244b8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
Binary file removed Images/screenshot.png
Binary file not shown.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Wox.Plugin.Lunar
一个公历Wox插件,公历、农历、生肖年、节气、节日查询
一个公历Wox插件,农历1901年到2050年公历、生肖年、节气、节日查询

## Features
* 支持所有标准的日期、时间格式的字符串
Expand All @@ -19,12 +19,13 @@ Standard Date and Time Format Strings, eg:
- `nl 10:11:12`
- `nl 2016-09-15`
- `nl Sep of 16`
- `nl 201609151011`
- `nl 20160915101112`
- `nl 1473905472000`
- `nl 2016 09 15 101112`
- `nl 2016-09-15T10:11:12`
- `nl Thu Sep 15 10:11:12 2016`

## Screenshot
![image](Images/screenshot.png)
![image](screenshot.png)

[1]: http://www.getwox.com/
62 changes: 47 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@
from lunar import Lunar
from dateutil.parser import parse
import datetime
import os

week_day_dict = {
0: '星期一',
1: '星期二',
2: '星期三',
3: '星期四',
4: '星期五',
5: '星期六',
6: '星期天',
}


class ChineseCalendar(Wox):
def query(self, query):
result = []
try:
if not query:
if not query or query == "now":
ln = Lunar()
else:
# 兼容纯long时间,如 1473905472000
# 兼容时间戳,如 1473905472000
if len(query.split(" ")) == 1 and len(query) == 12 or len(query) == 13:
try:
timenumber = float(query) / 1e3
Expand All @@ -24,28 +35,49 @@ def query(self, query):
except ValueError:
result.append({
"Title": 'Can not parse input string',
"SubTitle": 'Please read the docs',
"SubTitle": 'Please input standard date and time format strings',
"IcoPath": "Images/app.png",
})
else:
jieqi = ln.ln_jieqi()
jieri_lu = ln.ln_jie(True)
jieri = ln.ln_jie()
date = ln.localtime.strftime('%Y-%m-%d %H:%M:%S')
jieri = ln.ln_jie() # 阳历节日
date = ln.localtime.strftime('%Y-%m-%d %H:%M:%S') # 当前时间
notime = False
if date[11:] == "00:00:00":
notime = True
time1 = date[0: 11] if notime else date
result.append({
"Title": '时间 {} {}'.format(date[0: 11] if notime else date,
'【' + jieri + '】' if jieri else ""),
"SubTitle": '【{}年】 {} 【{}年-{}日{}】{} {}'.format(ln.sx_year(), ln.ln_date_str(), ln.gz_year(),
ln.gz_day(),
("-" + ln.gz_hour() + "时") if not notime else "",
'【' + jieqi + '】' if jieqi else "",
'【' + jieri_lu + '】' if jieri_lu else ""),
"Title": time1 + (' 【' + jieri + '】' if jieri else ""),
"SubTitle": ln.localtime.strftime("%A") + " " + week_day_dict[ln.localtime.weekday()],
"IcoPath": "Images/app.png",
"JsonRPCAction": {
"method": "add_to_clipboard",
"parameters": [time1],
"dontHideAfterAction": False
}
})
return result
if datetime.datetime(1901, 1, 1) < ln.localtime:
jieqi = ln.ln_jieqi() # 节气
jieri_lu = ln.ln_jie(True) # 农历节日
lutime1 = '{} {}'.format(ln.ln_date_str(), '【' + jieri_lu + '】' if jieri_lu else "")
lutime2 = '【{}】 {}年-{}日{} {}'.format(ln.sx_year(), ln.gz_year(),
ln.gz_day(),
("-" + ln.gz_hour() + "时") if not notime else "",
' 节气: ' + jieqi if jieqi else "")
result.append({
"Title": lutime1,
"SubTitle": lutime2,
"IcoPath": "Images/app.png",
"JsonRPCAction": {
"method": "add_to_clipboard",
"parameters": [lutime1],
"dontHideAfterAction": False
}
})
return result

def add_to_clipboard(self, text):
command = 'echo ' + text.strip() + '| clip'
os.system(command)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ID":"c662afd496e248e1aba2d22ff5ttcccc",
"ActionKeyword":"nl",
"ActionKeyword":"dt",
"Name":"Lunar",
"Description":"Lunar 公历、农历、生肖年、节气、节日查询",
"Author":"imwr",
"Version":"1.0.3",
"Version":"1.0.4",
"Language":"python",
"Website":"http://github.com/imwr/Wox.Plugin.Lunar",
"ExecuteFileName":"main.py",
Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3e244b8

Please sign in to comment.