sysinfo.sh
#sysinfo.sh
######## This is a script made
######## by 'yettenet'.
########
######## SysInfo script for OpenBox
######## v0.1
########
######## The author does not take
######## any responsibility for
######## what it might do to your
######## computer, though it's
######## improbable to do any harm.
########
######## You may share the script with
######## everyone and modify it for your
######## liking, as long as you
######## GIVE CREDIT.
########
######## To add it to Openbox, copy it to
######## your Openbox/scripts folder, which usually is at
######## ~/.config/openbox/scripts
########
######## edit your menu.xml file, which usually is at
######## ~/.config/openbox/menu.xml
######## and add the following line (in case you have the usual paths - if not, edit the path as needed):
########
########<menu execute="~/.config/openbox/scripts/sysinfo_v01-by_yettenet.script" id="sysinfo-menu" label="SysInfo"/>
########
######## Below you will find the settings
######## (the script still needs to be tested)
######## settings
MountPoint1=$(echo /dev/sdc1)
#MountPoint2=$(echo /dev/sda4)
NetworkDevice1=$(echo wlan1)
NetworkDevice2=$(echo eth0) #Uncomment some lines to make it work!
######## /settings
User=$(whoami)
Host=$(uname -n)
System=$(uname -s)
Release=$(uname -r)
Arch=$(uname -m)
SizeMountPoint1=$(df -HlT | grep "$MountPoint1")
#SizeMountPoint2=$(df -HlT | grep "$MountPoint2")
NetDev1ip=$(/sbin/ifconfig "$NetworkDevice1" | grep "inet addr:" | sed "s/.*inet addr://" | sed "s/Bcast.*//")
NetDev1down=$(/sbin/ifconfig "$NetworkDevice1" | grep bytes | sed 's/.*RX bytes:[0-9]* (//' | sed 's/iB).*TX.*//' | sed 's/b).*TX.*//' | sed 's/).*TX.*//')
NetDev1up=$(/sbin/ifconfig "$NetworkDevice1" | grep bytes | sed 's/.*TX bytes:[0-9]* (//' | sed 's/iB)//' |sed 's/b).*//' | sed 's/).*//')
NetDev2ip=$(/sbin/ifconfig "$NetworkDevice1" | grep "inet addr:" | sed "s/.*inet addr://" | sed "s/Bcast.*//")
NetDev2down=$(/sbin/ifconfig "$NetworkDevice1" | grep bytes | sed 's/.*RX bytes:[0-9]* (//' | sed 's/iB).*TX.*//' | sed 's/b).*TX.*//' | sed 's/).*TX.*//')
NetDev2up=$(/sbin/ifconfig "$NetworkDevice1" | grep bytes | sed 's/.*TX bytes:[0-9]* (//' | sed 's/iB)//' |sed 's/b).*//' | sed 's/).*//')
DateDate=$(date '+Date ~ %Y.%m.%d. (%a)')
DateWeek=$(date '+Week ~ %W')
DateDay=$(date '+ Day ~ %j')
DateTime=$(date '+Time ~ %H:%M [%Z]')
UpTime=$(uptime | sed 's/.* up //' | sed 's/[0-9]* us.*//' | sed 's/ day, /d/' | sed 's/ days, /d /' | sed 's/:/h /' | sed 's/ min//'| sed 's/,/m/' | sed 's/ / /')
MemTotal=$(echo "scale = 2; ("$(cat /proc/meminfo | grep MemTotal: | awk '{print $2}' | sed 's/k//')" /1024)" | bc)
MemFree=$(echo "scale = 2; ("$(cat /proc/meminfo | grep MemFree: | awk '{print $2}' | sed 's/k//')" /1024) + ("$(cat /proc/meminfo | grep grep -m 1 Cached: | awk '{print $2}' | sed 's/k//')" /1024)" | bc)
MemUsed=$(echo "scale = 2; ("$(cat /proc/meminfo | grep MemTotal: | awk '{print $2}' | sed 's/k//')" /1024) - (("$(cat /proc/meminfo | grep MemFree: | awk '{print $2}' | sed 's/k//')" /1024) + ("$(cat /proc/meminfo | grep -m 1 Cached: | awk '{print $2}' | sed 's/k//')" /1024))" | bc)
SwpTotal=$(echo "scale = 2; ("$(cat /proc/meminfo | grep SwapTotal: | awk '{print $2}' | sed 's/k//')" /1024)" | bc)
SwpFree=$(echo "scale = 2; ("$(cat /proc/meminfo | grep SwapFree: | awk '{print $2}' | sed 's/k//')" /1024)" | bc)
SwpUsed=$(echo "scale = 2; ("$(cat /proc/meminfo | grep SwapTotal: | awk '{print $2}' | sed 's/k//')" /1024) - ("$(cat /proc/meminfo | grep SwapFree: | awk '{print $2}' | sed 's/k//')" /1024)" | bc)
MemUsedPercent=$(echo "scale = 2; (("$(cat /proc/meminfo | grep MemTotal: | awk '{print $2}' | sed 's/k//')" /1024) - (("$(cat /proc/meminfo | grep MemFree: | awk '{print $2}' | sed 's/k//')" /1024) + ("$(cat /proc/meminfo | grep -m 1 Cached: | awk '{print $2}' | sed 's/k//')" /1024))) / ("$(cat /proc/meminfo | grep MemTotal: | awk '{print $2}' | sed 's/k//')" /1024) *100" | bc)
SwpUsedPercent=$(echo "scale = 2; (("$(cat /proc/meminfo | grep SwapTotal: | awk '{print $2}' | sed 's/k//')" /1024) - ("$(cat /proc/meminfo | grep SwapFree: | awk '{print $2}' | sed 's/k//')" /1024)) / ("$(cat /proc/meminfo | grep SwapTotal: | awk '{print $2}' | sed 's/k//')" /1024) *100" | bc)
CPUmodel=$(cat /proc/cpuinfo | grep "model name" | sed 's/.*: //')
CPUfreq=$(cat /proc/cpuinfo | grep -m 1 "cpu MHz" | sed 's/.*: //')
CPUcache=$(cat /proc/cpuinfo | grep -m 1 "cache size" | sed 's/.*: //')
echo "<openbox_pipe_menu>"
echo "<separator label=\"$User @ $Host \"/>"
echo "<item label=\"$System $Release $Arch\"/>"
echo "<separator label = \"Filesystem ~~ Type ~~ Total ~ Used ~ Free ~ % ~ Mount \"/>"
echo "<item label=\"$SizeMountPoint1\"/>"
#echo "<item label=\"$SizeMountPoint2\"/>"
echo "<separator label=\"CPU ~ RAM ~ Swap | Used/Total \"/>"
echo "<item label=\"RAM used: $MemUsed MiB/$MemTotal MiB ~ $MemUsedPercent%\"/>"
echo "<item label=\"Swp used: $SwpUsed MiB/$SwpTotal MiB ~ $SwpUsedPercent%\"/>"
echo "<item label=\"CPU ~ $CPUmodel\"/>"
echo "<item label=\"CPU @ $CPUfreq MHz ~ CPU Cache: $CPUcache\"/>"
echo "<separator label = \"Network ~ "$NetworkDevice1" \"/>"
echo "<item label=\""$NetworkDevice1" ~ ip: $NetDev1ip\"/>"
echo "<item label=\""$NetworkDevice1" ~ downloaded: "$NetDev1down"iB\"/>"
echo "<item label=\""$NetworkDevice1" ~ uploaded: "$NetDev1up"iB\"/>"
#echo "<separator label = \"Network ~ "$NetworkDevice2" \"/>"
#echo "<item label=\""$NetworkDevice1" ~ ip: $NetDev2ip\"/>"
#echo "<item label=\""$NetworkDevice1" ~ downloaded: "$NetDev2down"iB\"/>"
#echo "<item label=\""$NetworkDevice1" ~ uploaded: "$NetDev2up"iB\"/>"
echo "<separator label = \"Date ~ Time\"/>"
echo "<item label=\"$DateDate\"/>"
echo "<item label=\"$DateWeek\"/>"
echo "<item label=\"$DateDay\"/>"
echo "<item label=\"$DateTime\"/>"
echo "<item label=\" Up ~ $UpTime\"/>"
echo "</openbox_pipe_menu>"
gweather.py
#gweather.py
#!/usr/bin/python -o
# -*- coding: utf-8 -*-
from urllib import urlopen, quote
from xml.etree.cElementTree import parse
from datetime import datetime, timedelta
import os
from os.path import join
from sys import argv
try:
import cPickle as pickle
except ImportError:
import pickle
TRANSLATED_TEXT = {
'en': {
'current': 'Current conditions',
'weather': 'Weather',
'temp': 'Temperature',
'humidity': 'Humidity',
'wind': 'Wind',
'forecast': 'Forecast',
'mintemp': 'Minimun Temperature',
'maxtemp': 'Maximun Temperature'
},
'es': {
'current': u'Actualmente',
'weather': u'Tiempo',
'temp': u'Temperatura',
'humidity': u'Humedad',
'wind': u'Viento',
'forecast': u'Previsión',
'mintemp': u'Temperatura Mínima',
'maxtemp': u'Temperatura Máxima'
},
'fr': {
'current': u'Actuel',
'weather': u'Météo',
'temp': u'Température',
'humidity': u'Humidité',
'wind': u'Vent',
'forecast': u'Prévision',
'mintemp': u'Température minimale',
'maxtemp': u'Température maximale'
},
'de': {
'current': u'Aktuell',
'weather': u'Wetter',
'temp': u'Temperatur',
'humidity': u'Luftfeuchtigkeit',
'wind': u'Wind',
'forecast': u'Prognostizieren',
'mintemp': u'Minimale Temperatur',
'maxtemp': u'Höchste Temperatur'
}
}
if len(argv) != 3:
raise Exception('Usage: gweather.py city language.')
else:
city = argv[1]
lang = argv[2]
CACHE_HOURS = 1
WEATHER_URL = 'http://www.google.com/ig/api?weather=%s&hl=%s&oe=UTF-8'
def get_weather(city, lang):
url = WEATHER_URL % (quote(city), quote(lang))
data = parse(urlopen(url))
forecasts = []
for forecast in data.findall('weather/forecast_conditions'):
forecasts.append(
dict([(element.tag, element.get("data")) for element in forecast.getchildren()]))
return {
'forecast_information': dict([(element.tag, element.get("data")) for element in data.find('weather/forecast_information').getchildren()]),
'current_conditions': dict([(element.tag, element.get("data")) for element in data.find('weather/current_conditions').getchildren()]),
'forecasts': forecasts
}
def get_openbox_pipe_menu(lang, forecast_information, current_conditions, forecasts):
if lang == 'en-US':
lang = 'en'
tt = TRANSLATED_TEXT[lang]
temp_var, temp_unit = ("temp_c", u"\u00b0C") if forecast_information['unit_system'] == "SI" else ("temp_f", "F")
output = '<openbox_pipe_menu>'
output += '\n<separator label="%s (%s)" />' % (weather['forecast_information']['city'],forecast_information['forecast_date'])
output += '\n<separator label="%s" />' % tt['current']
output += '<item label="%s: %s" />' % (tt['weather'], current_conditions['condition'])
output += '<item label="%s: %s %s" />' % (tt['temp'], current_conditions[temp_var], temp_unit)
output += '<item label="%s: %s" />' % (tt['humidity'], current_conditions['humidity'])
output += '<item label="%s: %s" />' % (tt['wind'], current_conditions['wind_condition'])
for forecast in forecasts:
output += '\n<separator label="%s: %s" />' % (tt['forecast'], forecast['day_of_week'])
output += '<item label="%s: %s" />' % (tt['weather'], forecast['condition'])
output += '<item label="%s: %s %s" />' % ( tt['mintemp'], forecast['low'], temp_unit )
output += '<item label="%s: %s %s" />' % ( tt['maxtemp'], forecast['high'], temp_unit )
output += '\n</openbox_pipe_menu>'
return output.encode('utf-8')
cache_file = join(os.getenv("HOME"), '.gweather.cache')
try:
f = open(cache_file,'rb')
cache = pickle.load(f)
f.close()
except IOError:
cache = None
if cache == None or (city, lang) not in cache or (
cache[(city, lang)]['date'] + timedelta(hours=CACHE_HOURS) < datetime.utcnow()):
# The cache is outdated
weather = get_weather(city, lang)
ob_pipe_menu = get_openbox_pipe_menu(lang, **weather)
print ob_pipe_menu
if cache == None:
cache = dict()
cache[(city, lang)] = {'date': datetime.utcnow(), 'ob_pipe_menu': ob_pipe_menu}
#Save the data in the cache
try:
f = open(cache_file, 'wb')
cache = pickle.dump(cache, f, -1)
f.close()
except IOError:
raise
else:
print cache[(city, lang)]['ob_pipe_menu']
both scripts.