Projects and resources (En) > Contributing to FOSS
OpenBox scripts
melodie:
--- Citation de: patrick013 le 03 mars 2013 à 23:59:51 ---OK, but any reason ?
--- Fin de citation ---
Yes, our general laziness : I could point to your thread for people on some of the chans where I go more or less each evening, and show the scripts. It's easier to look at if there is no need to download and unpack.
Even a copy paste to pastebin - http://pastebin.com - and bring the links back here would be better than a tarball to download and unpack.
patrick013:
sysinfo.sh
--- Code: ---#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>"
--- Fin du code ---
gweather.py
--- Code: ---
#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']
--- Fin du code ---
both scripts.
melodie:
Hi again,
--- Citer ---#sysinfo.sh
######## This is a script made
######## by 'yettenet'.
--- Fin de citation ---
who is "yettenet"? Does he have a mail address ? ^^
patrick013:
--- Citation de: mélodie le 04 mars 2013 à 01:37:59 ---Hi again,
who is "yettenet"? Does he have a mail address ? ^^
--- Fin de citation ---
Hi Mel,
I don't know. I got these from an OB scripts website.
Had them for awhile, can't remember the exact website,
nothing in history, I've changed browsers lately.
Need to designate it a pipemenu, sysinfo-menu, then
configure a few lines within the script.
Voila,
Some system info, not the best but something, you know.
Need to see my menu.xml let me know.
regards,
patrickl
patrick013:
This weather script is better, just follow the script command with
your zip code and fahrenheit or celsius, the pipemenu works then.
pipe-weather is the pipemenu
yweather.py
--- Code: ---
#yweather.py
#!/usr/bin/python
import urllib
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
#Usage: yweather.py AYXX0001 Celsius
if len(argv) != 3:
raise Exception('Usage: yweather.py zip_code units. zip_code is your city code in Yahoo Weather, units can be Celsius or Fahrenheit.')
else:
zip_code = argv[1]
if argv[2] == 'Fahrenheit' or argv[2] == 'fahrenheit':
units = 'f'
else:
units = 'c'
CACHE_HOURS = 6
#http://weather.yahooapis.com/forecastrss
WEATHER_URL = 'http://xml.weather.yahoo.com/forecastrss?p=%s&u=%s'
WEATHER_NS = 'http://xml.weather.yahoo.com/ns/rss/1.0'
def weather_for_zip(zip_code, units):
url = WEATHER_URL % (zip_code, units)
rss = parse(urllib.urlopen(url)).getroot()
forecasts = []
for element in rss.findall('channel/item/{%s}forecast' % WEATHER_NS):
forecasts.append(dict(element.items()))
ycondition = rss.find('channel/item/{%s}condition' % WEATHER_NS)
return {
'current_condition': dict(ycondition.items()),
'forecasts': forecasts,
'title': rss.findtext('channel/title'),
'pubDate': rss.findtext('channel/item/pubDate'), #rss.findtext('channel/lastBuildDate'),
'location': dict(rss.find('channel/{%s}location' % WEATHER_NS).items()),
'wind': dict(rss.find('channel/{%s}wind' % WEATHER_NS).items()),
'atmosphere': dict(rss.find('channel/{%s}atmosphere' % WEATHER_NS).items()),
'astronomy': dict(rss.find('channel/{%s}astronomy' % WEATHER_NS).items()),
'units': dict(rss.find('channel/{%s}units' % WEATHER_NS).items())
}
def print_openbox_pipe_menu(weather):
print '<openbox_pipe_menu>'
print '<separator label="%s %s" />' % (weather['location']['city'],weather['pubDate'])
print '<separator label="Current conditions" />'
print '<item label="Weather: %s" />' % weather['current_condition']['text']
print '<item label="Temperature: %s %s" />' % ( weather['current_condition']['temp'],
weather['units']['temperature'] )
print '<item label="Humidity: %s%%" />' % weather['atmosphere']['humidity']
print '<item label="Visibility: %s %s" />' % ( weather['atmosphere']['visibility'],
weather['units']['distance'] )
#pressure: steady (0), rising (1), or falling (2)
if weather['atmosphere']['rising'] == 0:
pressure_state = 'steady'
elif weather['atmosphere']['rising'] == 1:
pressure_state = 'rising'
else:
pressure_state = 'falling'
print '<item label="Pressure: %s %s (%s)" />' % ( weather['atmosphere']['pressure'],
weather['units']['pressure'], pressure_state )
print '<item label="Wind chill: %s %s" />' % ( weather['wind']['chill'],
weather['units']['temperature'] )
print '<item label="Wind direction: %s degrees" />' % weather['wind']['direction']
print '<item label="Wind speed: %s %s" />' % ( weather['wind']['speed'],
weather['units']['speed'] )
print '<item label="Sunrise: %s" />' % weather['astronomy']['sunrise']
print '<item label="Sunset: %s" />' % weather['astronomy']['sunset']
for forecast in weather['forecasts']:
print '<separator label="Forecast: %s" />' % forecast['day']
print '<item label="Weather: %s" />' % forecast['text']
print '<item label="Min temperature: %s %s" />' % ( forecast['low'],
weather['units']['temperature'] )
print '<item label="Max temperature: %s %s" />' % ( forecast['high'],
weather['units']['temperature'] )
print '</openbox_pipe_menu>'
cache_file = join(os.getenv("HOME"), '.yweather.cache')
try:
f = open(cache_file,'rb')
cache = pickle.load(f)
f.close()
except IOError:
cache = None
if cache == None or (zip_code, units) not in cache or (
cache[(zip_code, units)]['date'] + timedelta(hours=CACHE_HOURS) < datetime.utcnow()):
# The cache is outdated
weather = weather_for_zip(zip_code, units)
if cache == None:
cache = dict()
cache[(zip_code, units)] = {'date': datetime.utcnow(), 'weather': weather}
#Save the data in the cache
try:
f = open(cache_file, 'wb')
cache = pickle.dump(cache, f, -1)
f.close()
except IOError:
raise
else:
weather = cache[(zip_code, units)]['weather']
print_openbox_pipe_menu(weather)
--- Fin du code ---
I've got the sysinfo.sh and yweather.py both working in Scorpio,
just finished that.
Questions or a copy of my menu.xml just ask.
Aren't computers fun ?
regards,
patrick
Navigation
[#] Page suivante
[*] Page précédente
Utiliser la version classique