Sergey Kiselev
2 years ago
2 changed files with 265 additions and 0 deletions
@ -0,0 +1,119 @@ |
|||
#!/usr/local/bin/lua53 |
|||
|
|||
-- Месяцы |
|||
m = { "января", "февраля", "марта", "апреля", "мая", "июня", |
|||
"июля", "августа", "сентября", "октября", "ноября", "декабря" } |
|||
|
|||
-- Единицы |
|||
l1 = { |
|||
{ "первое", "одна", "первого" }, |
|||
{ "второе", "две", "второго" }, |
|||
{ "третье", "три", "третьего" }, |
|||
{ "четвертое", "четыре", "четвертого" }, |
|||
{ "пятое", "пять", "пятого" }, |
|||
{ "шестое", "шесть", "шестого" }, |
|||
{ "седьмое", "семь", "седьмого" }, |
|||
{ "восьмое", "восемь", "восьмого" }, |
|||
{ "девятое", "девять", "девятого" }, |
|||
{ "десятое", "десять", "десятого" }, |
|||
{ "одиннадцатое", "одиннадцать", "одиннадцатого" }, |
|||
{ "двенадцатое", "двенадцать", "двенадцатого" }, |
|||
{ "тринадцатое", "тринадцать", "тринадцатого" }, |
|||
{ "четырнадцатое", "четырнадцать", "четырнадцатого" }, |
|||
{ "пятнадцатое", "пятнадцать", "пятнадцатого" }, |
|||
{ "шестнадцатое", "шестнадцать", "шестнадцатого" }, |
|||
{ "семнадцатое", "семнадцать", "семнадцатого" }, |
|||
{ "восемнадцатое", "восемнадцать", "восемнадцатого" }, |
|||
{ "девятнадцатое", "девятнадцать", "девятнадцатого" }, |
|||
{ "двадцатое", "двадцать", "двадцатого" } |
|||
} |
|||
|
|||
-- Десятки |
|||
l10 = { |
|||
{ "десятое", "десять", "десятого" }, |
|||
{ "двадцатое", "двадцать", "двадцатого" }, |
|||
{ "тридцатое", "тридцать", "тридцатого" }, |
|||
{ "", "сорок", "сорокового" }, |
|||
{ "", "пятьдесят", "пятидесятого" }, |
|||
{ "", "шестьдесят", "шестидесятого" }, |
|||
{ "", "семьдесят", "семидесятого" }, |
|||
{ "", "восемьдесят", "восьмидесятого" }, |
|||
{ "", "девяносто", "девяностого" } |
|||
} |
|||
|
|||
-- Сотни |
|||
l100 = { |
|||
{ "сто", "сотого" }, |
|||
{ "двести", "двухсотого" }, { "триста", "трехсотого" }, |
|||
{ "четыреста", "четырехсотого" }, { "пятьсот", "пятисотого" }, |
|||
{ "шестьсот", "шестисотого" }, { "семьсот", "семисотого" }, |
|||
{ "восемьсот", "восьмисотого" }, { "девятьсот", "девятисотого" } |
|||
} |
|||
|
|||
-- Тысячи |
|||
l1000 = { |
|||
"тысячного", "двухтысячного", "трехтысячного", "четырехтысячного", |
|||
"пятитысячного", "шеститысячного", "семитысячного", "восьмитысячного", |
|||
"девятитысячного" |
|||
} |
|||
|
|||
sym = { "тысяча", "тысячи", "тысяч" } |
|||
|
|||
d = tonumber(os.date('%d')) |
|||
|
|||
lettday = "" |
|||
|
|||
if ( math.fmod(d, 10) == 0 ) then |
|||
lettday = l10[d / 10][1] |
|||
else |
|||
if ( d <= 20 ) then |
|||
lettday = l1[d][1] |
|||
else |
|||
n10 = d // 10 |
|||
n1 = math.fmod(d, 10) |
|||
lettday = l10[n10][2] .. " " .. l1[n1][1] |
|||
end |
|||
end |
|||
|
|||
lettmonth = m[tonumber(os.date('%m'))] |
|||
|
|||
y = tonumber(os.date('%Y')) |
|||
n1000 = y // 1000 |
|||
n100 = math.fmod(y,1000) // 100 |
|||
n10 = math.fmod(y,100) |
|||
n1 = math.fmod(n10,10) |
|||
|
|||
lettyear = "" |
|||
|
|||
if ( n1000 > 0 and n100 == 0 and n10 == 0 and n1 == 0 ) then |
|||
lettyear = l1000[n1000] |
|||
elseif ( n1000 > 0 ) then |
|||
lettyear = l1[n1000][2] |
|||
|
|||
if ( n1000 == 1 ) then |
|||
lettyear = lettyear .. " " .. sym[1] |
|||
elseif ( n1000 < 5 ) then |
|||
lettyear = lettyear .. " " .. sym[2] |
|||
else |
|||
lettyear = lettyear .. " " .. sym[3] |
|||
end |
|||
end |
|||
|
|||
if ( n100 > 0 and n10 == 0 and n1 == 0 ) then |
|||
lettyear = lettyear .. " " .. l100[n100][2] |
|||
elseif ( n100 > 0 ) then |
|||
lettyear = lettyear .. " " .. l100[n100][1] |
|||
end |
|||
|
|||
if ( n10 > 0 and n1 == 0 ) then |
|||
lettyear = lettyear .. " " .. l10[n10 / 10][3] |
|||
elseif ( n10 < 20 ) then |
|||
lettyear = lettyear .. " " .. l1[n10][3] |
|||
else |
|||
lettyear = lettyear .. " " .. l10[n10 // 10][2] .. " " .. l1[n1][3] |
|||
end |
|||
|
|||
letters = lettday .. " " .. lettmonth .. " " .. lettyear .. " года" |
|||
|
|||
print(letters) |
|||
|
@ -0,0 +1,146 @@ |
|||
#!/bin/sh |
|||
# |
|||
|
|||
_usage() { |
|||
cat <<EOF |
|||
Usage: |
|||
say [-h] -d | -g | -m <message> | -t <dev> [-n] [-o <file>] |
|||
|
|||
-h show this help message |
|||
-d say date |
|||
-g godville.net |
|||
-m custom message |
|||
-t say device themperature (only cpu dev is supported) |
|||
-n show notification |
|||
-o save to file |
|||
|
|||
Example: |
|||
say -m "Hello, World!" -n -o hello.wav |
|||
|
|||
EOF |
|||
|
|||
exit ${1} |
|||
} |
|||
|
|||
_pluralform(){ |
|||
n=$(( ${1} % 100 )) |
|||
n1=$(( ${n} % 10 )) |
|||
|
|||
if [ ${n} -gt 10 -a ${n} -lt 20 ]; then |
|||
echo ${4} |
|||
elif [ ${n1} -gt 1 -a ${n1} -lt 5 ]; then |
|||
echo ${3} |
|||
elif [ ${n1} -eq 1 ]; then |
|||
echo ${2} |
|||
else |
|||
echo ${4} |
|||
fi |
|||
} |
|||
|
|||
_date() { |
|||
echo "Сегодня - $( date '+%A' ), $( date2word.lua )." |
|||
} |
|||
|
|||
_godville() { |
|||
base="https://godville.net/gods/api" |
|||
god="" |
|||
api_key="" |
|||
url="${base}/${god}/${api_key}" |
|||
quote="$( ${CURL} "${url}" | jq ".diary_last" )" |
|||
|
|||
echo "${quote}" |
|||
} |
|||
|
|||
_temperature() { |
|||
D=${1:-none} |
|||
M= |
|||
|
|||
case ${D} in |
|||
none) M="А куда градусник прикладывать?" ;; |
|||
cpu) |
|||
t=0 |
|||
ncpu=$( sysctl -n hw.ncpu ) |
|||
|
|||
for C in $( seq 0 $(( ${ncpu} - 1 )) ); do |
|||
t1=$( sysctl -n dev.cpu.${C}.temperature 2>/dev/null | \ |
|||
sed 's/,.*//' ) |
|||
t1=${t1:-0} |
|||
if [ ${t1} -gt ${t} ]; then t=${t1}; fi |
|||
done |
|||
|
|||
if [ ${t} -eq 0 ]; then |
|||
M="Градусник у процессора сломался или не поддерживается." |
|||
else |
|||
M="Температура центрального процессора: ${t}" |
|||
M="${M} $( _pluralform ${t} градус градуса градусов )" |
|||
M="${M} по Цельсию." |
|||
fi |
|||
;; |
|||
esac |
|||
|
|||
echo "${M}" |
|||
} |
|||
if [ $# -lt 1 ]; then _usage; fi |
|||
|
|||
SAY_CMD="$( which RHVoice-test )" |
|||
if [ -z "${SAY_CMD}" ]; then |
|||
echo "Speech synthesizer not found" |
|||
exit 1 |
|||
fi |
|||
SAY_PARAM="--rate 95 --pitch 120 --volume 30 --profile elena+slt" |
|||
|
|||
CURL="$( which curl )" |
|||
if [ -z "${CURL}" ]; then |
|||
echo "curl is required, but not found" |
|||
exit 1 |
|||
else |
|||
CURL="${CURL} -s" |
|||
fi |
|||
|
|||
NOTIFY="$( which notify-send )" |
|||
|
|||
ACTION= |
|||
#FILE= |
|||
DEV= |
|||
MSG= |
|||
SEND=0 |
|||
SUMMARY= |
|||
|
|||
while getopts dghm:no:t: OPT |
|||
do |
|||
case ${OPT} in |
|||
d|g|m|t) |
|||
if [ -z "${ACTION}" ]; then |
|||
case ${OPT} in |
|||
d) ACTION="date" ;; |
|||
g) |
|||
ACTION="godville" |
|||
SUMMARY="Годвиль - Вести с полей" ;; |
|||
m) |
|||
ACTION="message" |
|||
MSG="${OPTARG}" ;; |
|||
t) |
|||
ACTION="temperature" |
|||
DEV="${OPTARG}" ;; |
|||
esac |
|||
else |
|||
echo "Only one of the options -d, -f, -g, -m, -t is allowed." |
|||
exit 2 |
|||
fi ;; |
|||
n) SEND=1 ;; |
|||
o) SAY_PARAM="${SAY_PARAM} -o ${OPTARG}" ;; |
|||
h) _usage 0 ;; |
|||
*) _usage 2 ;; |
|||
esac |
|||
done |
|||
|
|||
if [ "${ACTION}" != "message" ]; then |
|||
MSG="$( _${ACTION} ${DEV} )" |
|||
fi |
|||
|
|||
if [ ${SEND} -eq 1 ] && [ -n "${NOTIFY}" ]; then |
|||
${NOTIFY} -u low -t 10000 -i dialog-information "${SUMMARY:- }" "${MSG}" |
|||
fi |
|||
|
|||
echo "${MSG}" | ${SAY_CMD} ${SAY_PARAM} |
|||
|
Loading…
Reference in new issue