diff --git a/ReadMe.md b/ReadMe.md index 232fdcd..1c6a3d2 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -4,11 +4,16 @@ Conky Widget for Godville About ----- -This widget provides a Godville game client (read only) for Linux Conky. It is based on the [script](http://godville.net/forums/show_topic/257) by [lol2Fast4U](http://godville.net/gods/lol2Fast4U). +This widget provides a Godville game client (read only) for Linux Conky. It is based on the [script](http://godville.net/forums/show_topic/257) by [lol2Fast4U](http://godville.net/gods/lol2Fast4U) but with switching to python parser 100% of the code has been rewritten. Changes: +- updated to use json (as recommended by Godville Admins) - updated to be compartible with new Conky versions - added Conky Manager support - added long strings split (by words) +- written in python +- inventory count bug corrected +- some logic improvements made +- etc Installing ---------- @@ -17,18 +22,20 @@ First you need to allow API requests on your [godville settings page](http://god ####If you are using git and Conky Manager (recommended): -just place all the files to the folder under your conky manager folder, make shure you've allowed executing of `godville.sh` - and here you go! You can activate it in Conky Manager. You can do it with simple cloning the repo: +just place all the files to the folder under your conky manager folder, make sure you've allowed executing of `godville.py` - and here you go! + +You can do it with simple cloning the repo: cd ~/.conky && git clone git@github.com:zesaver/conky_godville.git +Now you can activate it in Conky Manager. + ####If you are not using Conky Manager (not tested yet): -just place all the files to any folder you like, make shure you've allowed executing of `godville.sh` and add to your `conkyrc` following: +just place all the files to any folder you like, make sure you've allowed executing of `godville.py` and add to your `~/.conkyrc` following: - ${execi 15 /path/to/godville.sh | fold -s -w 50} + ${execi 15 /path/to/godville.py | fold -s -w 50} -####P.S. -You may need to install `xsltproc` (`sudo apt-get install xsltproc`) to be able to parse xml answer from the server. Switching to json and some "unix-native" parser is planned in future but not realized yet. Miscellaneous ------------- diff --git a/godville b/godville index 1ea06d5..c19c92f 100644 --- a/godville +++ b/godville @@ -40,7 +40,7 @@ color1 77B753 minimum_size 300 300 TEXT -${color1}${execi 15 ~/.conky/Godville/godville.sh | fold -s -w 50} +${color1}${execi 15 ./godville.py | fold -s -w 50} diff --git a/godville.py b/godville.py index 2e89cc0..6b1a832 100755 --- a/godville.py +++ b/godville.py @@ -1,9 +1,27 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- import requests -import json -username='YOURNAME' +username = 'ZESAVER' -json_data=requests.get("http://godville.net/gods/api/"+username+".json") +resp = requests.get("http://godville.net/gods/api/"+username+".json") +data = resp.json() -print(data) +print "Героиня: " if data["gender"] == "female" else "Герой: ",(data["name"].encode('utf-8')) +print 'Клан:',data["clan"] +print 'Характер:',data["alignment"].encode('utf-8') +print 'Девиз:',data["motto"].encode('utf-8') +print "Уровень: %.0f (%.0f/100)" % (data["level"],data["exp_progress"]) +print "Здоровье: %.0f/%.0f" % (data["health"],data["max_health"]) +print "Прана: %.0f/100" % (data["godpower"]) +print 'Золотых:',data["gold_approx"].encode('utf-8') +print "Кирпичей: %.0f/100" % (data["bricks_cnt"]) +print 'Задание:',data["quest"].encode('utf-8'),"(%.0f/100)" % (data["quest_progress"]) +print 'Последняя запись:',data["diary_last"].encode('utf-8') +print "Инвентарь: %.0f/%.0f" % (data["inventory_num"],data["inventory_max_num"]) + +inventory={} +for n, v in data["inventory"].iteritems(): + inventory[v["pos"]] = " %s %s" % (v['pos']+1, n.encode('utf-8')) + +print "\n".join([inventory[i] for i in sorted(inventory.keys())]) diff --git a/godville.sh b/godville.sh deleted file mode 100755 index b619027..0000000 --- a/godville.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# by lol2Fast4U -USERNAME="zesaver" -curl http://godville.net/gods/api/$USERNAME.xml 2>/dev/null | xsltproc /home/zesaver/.conky/Godville/godville.xslt - $FILTER | grep -v " - -Герой: -Пол: -Клан: -Девиз: -Характер: -Уровень: +/100 -Инвентарь: / - - {@cnt} * - -Здоровье: / -Прана: /100 -Золотых: -Последняя запись: -Задание: /100 - - -